#controller
- public ActionResult Employee(int txtEmployeeId, string txtEmployeeName, string txtEmployeeDesignation, HttpPostedFileBase Empimage, double txtSalary, string txtEmployeeDpt, byte[] bytes)
- {
- EmployeeBusiness EmpBusiness = new EmployeeBusiness();
- EmployeeEntity emp = new EmployeeEntity();
- emp.Empid = Convert.ToInt32(txtEmployeeId);
- emp.Empname = txtEmployeeName;
- emp.Designation = txtEmployeeDesignation;
- emp.Salary = Convert.ToDouble(txtSalary);
- emp.Department = txtEmployeeDpt;
- emp.Empimage = savetophysicallocation(Empimage);
- EmpBusiness.saveEmployeeDetails(emp);
- return View();
- }
- private string savetophysicallocation(HttpPostedFileBase Empimage)
- {
- if(Empimage.ContentLength>0){
- var fileName=Path.GetFileName(Empimage.FileName);
- var upload="~/C:/Users/sangeetha.k/Desktop/images";
- var path = Path.Combine(Server.MapPath(upload), fileName);
- Empimage.SaveAs(path);
- return path;
- }
- return string.Empty;
- }
- }
- }
#Business Layer
- namespace EmployeeBusinessLayer
- {
- public class EmployeeBusiness
- {
- EmployeeDataAcess empdata = new EmployeeDataAcess();
- public void saveEmployeeDetails(EmployeeEntity emp)
- {
- empdata.saveEmployeeDetails(emp);
- }
- }
- }
#Data AccessLayer
- public class EmployeeDataAcess
- {
- string ConnectionString = ConfigurationManager.ConnectionStrings["Employee"].ConnectionString;
- AdventureWorksEntities EmpDbEntity = new AdventureWorksEntities();
- tblEmployee EmployeeDbContext = new tblEmployee();
- public void saveEmployeeDetails(EmployeeEntity emp)
- {
- using (AdventureWorksEntities EmpDbEntity = new AdventureWorksEntities())
- {
- tblEmployee EmployeeDbContext = null;
- if(EmpDbEntity.tblEmployees==null)
- {
- EmployeeDbContext.Empid = emp.Empid;
- EmployeeDbContext.Empname = emp.Empname;
- EmployeeDbContext.Designation = emp.Designation;
- EmployeeDbContext.Empimage = emp.Empimage;
- EmployeeDbContext.Empimage = emp.Empimage;
- EmployeeDbContext.Salary = emp.Salary;
- EmployeeDbContext.Email = emp.Email;
- EmployeeDbContext.Department = emp.Department;
- }
- if(EmpDbEntity.tblEmployees!=null)
- {
- EmployeeDbContext = EmpDbEntity.tblEmployees.Where(x => x.Empid == emp.Empid).FirstOrDefault();
- }
- }
- }
- }
- }
and #entity Layer
- public class EmployeeEntity
- {
- public int Empid { get; set; }
- public string Empname { get; set; }
- public string Designation { get; set; }
- public string Empimage { get; set; }
- public byte[] ImageData { get; set; }
- public Nullable<double> Salary { get; set; }
- public string Email { get; set; }
- public string Department { get; set; }
- //public EmployeeEntity()
- //{
- //}
- //public EmployeeEntity(int Empid, string Empname, string Designation, string Empimage, byte[] ImageData, double Salary, string Email, string Department)
- //{
- // this.Empid = Empid;
- // this.Empname = Empname;
- // this.Designation = Designation;
- // this.Empimage = Empimage;
- // this.ImageData = ImageData;
- // this.Salary = Salary;
- // this.Email = Email;
- // this.Department = Department;
- }
- }
#sql Table structure
Empid int
Empname nvarchar
Designation nvarchar
Empimage nvarchar
ImageData varbinary
Salary float
Email nvarchar
Department nvarchar
sangeetha kPosted Mar 28, 2018, 4:58 AM
sangeetha kPosted Mar 28, 2018, 4:56 AM
Ramesh PalanivelPosted Mar 23, 2018, 7:11 AM
sangeetha kPosted Mar 23, 2018, 7:05 AM
Ramesh PalanivelPosted Mar 23, 2018, 6:58 AM
Sagar Pandurang KapPosted Mar 23, 2018, 6:45 AM