public ViewResult Details(int?id) { var employee = _employeerepository.GetEmployee(id ?? 1); EmployeeDataViewModel employeeDataViewModel = new EmployeeDataViewModel() { employee = employee, PageTitle = "New Page Title" }; return(View(employeeDataViewModel)); }
//To Update the records of a particluar employee public int UpdateEmployee(EmployeeDataViewModel model) { try { var employee = new Employee() { Id = model.Id, Name = model.Name, Department = model.Department, GenderId = model.GenderId, CityId = model.CityId }; db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(1); } catch { throw; } }
//To Add new employee record public int AddEmployee(EmployeeDataViewModel model) { try { var employee = new Employee() { Id = model.Id, Name = model.Name, Department = model.Department, GenderId = model.GenderId, CityId = model.CityId }; db.Employee.Add(employee); db.SaveChanges(); return(1); } catch { throw; } }
//Get the details of a particular employee public EmployeeDataViewModel GetEmployeeData(int id) { try { EmployeeDataViewModel employee = db.Employee.Where(x => x.Id == id).Select(x => new EmployeeDataViewModel() { Id = x.Id, Name = x.Name, Department = x.Department, CityId = x.CityId, GenderId = x.GenderId }).SingleOrDefault(); return(employee); } catch { throw; } }
public int Edit([FromBody] EmployeeDataViewModel employee) { return(objemployee.UpdateEmployee(employee)); }
public int Create([FromBody] EmployeeDataViewModel employee) { return(objemployee.AddEmployee(employee)); }