sangeetha k

sangeetha k

  • NA
  • 207
  • 51.6k

An exception of type 'System.NotSupportedException' occurred

Mar 23 2018 6:06 AM
#controller
  1. public ActionResult Employee(int txtEmployeeId, string txtEmployeeName, string txtEmployeeDesignation, HttpPostedFileBase Empimage, double txtSalary, string txtEmployeeDpt, byte[] bytes)  
  2. {  
  3. EmployeeBusiness EmpBusiness = new EmployeeBusiness();  
  4. EmployeeEntity emp = new EmployeeEntity();  
  5. emp.Empid = Convert.ToInt32(txtEmployeeId);  
  6. emp.Empname = txtEmployeeName;  
  7. emp.Designation = txtEmployeeDesignation;  
  8. emp.Salary = Convert.ToDouble(txtSalary);  
  9. emp.Department = txtEmployeeDpt;  
  10. emp.Empimage = savetophysicallocation(Empimage);  
  11. EmpBusiness.saveEmployeeDetails(emp);  
  12. return View();  
  13. }  
  14. private string savetophysicallocation(HttpPostedFileBase Empimage)  
  15. {  
  16. if(Empimage.ContentLength>0){  
  17. var fileName=Path.GetFileName(Empimage.FileName);  
  18. var upload="~/C:/Users/sangeetha.k/Desktop/images";  
  19. var path = Path.Combine(Server.MapPath(upload), fileName);  
  20. Empimage.SaveAs(path);  
  21. return path;  
  22. }  
  23. return string.Empty;  
  24. }  
  25. }  
  26. }  
#Business Layer
  1. namespace EmployeeBusinessLayer  
  2. {  
  3. public class EmployeeBusiness  
  4. {  
  5. EmployeeDataAcess empdata = new EmployeeDataAcess();  
  6. public void saveEmployeeDetails(EmployeeEntity emp)  
  7. {  
  8. empdata.saveEmployeeDetails(emp);  
  9. }  
  10. }  
  11. }  
#Data AccessLayer
  1. public class EmployeeDataAcess  
  2. {  
  3. string ConnectionString = ConfigurationManager.ConnectionStrings["Employee"].ConnectionString;  
  4. AdventureWorksEntities EmpDbEntity = new AdventureWorksEntities();  
  5. tblEmployee EmployeeDbContext = new tblEmployee();  
  6. public void saveEmployeeDetails(EmployeeEntity emp)  
  7. {  
  8. using (AdventureWorksEntities EmpDbEntity = new AdventureWorksEntities())  
  9. {  
  10. tblEmployee EmployeeDbContext = null;  
  11. if(EmpDbEntity.tblEmployees==null)  
  12. {  
  13. EmployeeDbContext.Empid = emp.Empid;  
  14. EmployeeDbContext.Empname = emp.Empname;  
  15. EmployeeDbContext.Designation = emp.Designation;  
  16. EmployeeDbContext.Empimage = emp.Empimage;  
  17. EmployeeDbContext.Empimage = emp.Empimage;  
  18. EmployeeDbContext.Salary = emp.Salary;  
  19. EmployeeDbContext.Email = emp.Email;  
  20. EmployeeDbContext.Department = emp.Department;  
  21. }  
  22. if(EmpDbEntity.tblEmployees!=null)  
  23. {  
  24. EmployeeDbContext = EmpDbEntity.tblEmployees.Where(x => x.Empid == emp.Empid).FirstOrDefault();  
  25. }  
  26. }  
  27. }  
  28. }  
  29. }  
and #entity Layer
  1. public class EmployeeEntity  
  2. {  
  3. public int Empid { getset; }  
  4. public string Empname { getset; }  
  5. public string Designation { getset; }  
  6. public string Empimage { getset; }  
  7. public byte[] ImageData { getset; }  
  8. public Nullable<double> Salary { getset; }  
  9. public string Email { getset; }  
  10. public string Department { getset; }  
  11. //public EmployeeEntity()  
  12. //{  
  13. //}  
  14. //public EmployeeEntity(int Empid, string Empname, string Designation, string Empimage, byte[] ImageData, double Salary, string Email, string Department)  
  15. //{  
  16. // this.Empid = Empid;  
  17. // this.Empname = Empname;  
  18. // this.Designation = Designation;  
  19. // this.Empimage = Empimage;  
  20. // this.ImageData = ImageData;  
  21. // this.Salary = Salary;  
  22. // this.Email = Email;  
  23. // this.Department = Department;  
  24. }  
  25. }  
#sql Table structure
 
Empid int
Empname nvarchar
Designation nvarchar
Empimage nvarchar
ImageData varbinary
Salary float
Email nvarchar
Department nvarchar

Answers (6)