public void SaveEmployee(CustomEmployee model) { Employee emp = new Employee(); using (EmployeeTestEntities db = new EmployeeTestEntities()) { emp.FirstName = model.FirstName; emp.LastName = model.LastName; emp.BirthDate = model.BirthDate; emp.Gender = model.Gender; emp.Salary = model.Salary; emp.FkCityId = model.FkCityId; emp.FkStateId = model.FkStateId; emp.FkDepartmentId = model.FkDepartmentId; emp.IsActive = model.IsActive; emp.Photo = "~/Images/" + model.user_image.FileName; db.Employees.Add(emp); db.SaveChanges(); } }
public void EditEmployee(CustomEmployee model) { Employee emp = new Employee(); using (EmployeeTestEntities db = new EmployeeTestEntities()) { emp = db.Employees.Where(x => x.EmployeeId == model.EmployeeId).FirstOrDefault(); emp.FirstName = model.FirstName; emp.LastName = model.LastName; emp.BirthDate = model.BirthDate; emp.Gender = model.Gender; emp.Salary = model.Salary; emp.FkCityId = model.FkCityId; emp.FkStateId = model.FkStateId; emp.FkDepartmentId = model.FkDepartmentId; emp.IsActive = model.IsActive; emp.Photo = "~/Images/" + model.user_image.FileName; db.Entry(emp).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }