public ActionResult Detail(int id) { EmployeeContext empContext = new EmployeeContext(); Employee employee = empContext.Employees.Single(emp => emp.EmployeeId == id); return View(employee); }
public ActionResult EditGet(int? id) { ActionResult action = RedirectToAction("Index"); if (id != null) { EmployeeContext dbContext = new EmployeeContext(); Employee employee = dbContext.Employees.SingleOrDefault(x => x.EmployeeId == id); if (employee != null) { action = View(employee); } } return action; }
public ActionResult Delete(int? id) { EmployeeContext dbContext = new EmployeeContext(); if (id != null) { Employee employee = dbContext.Employees.SingleOrDefault(e => e.EmployeeId == id); if (employee != null) { dbContext.Employees.Remove(employee); } dbContext.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult CreatePost() { ActionResult action = View(); Employee employee = new Employee(); TryUpdateModel<Employee>(employee); if (ModelState.IsValid) { EmployeeContext dbContext = new EmployeeContext(); dbContext.Employees.Add(employee); dbContext.SaveChanges(); action = RedirectToAction("Index"); } return action; }
// GET: Department public ActionResult Index() { EmployeeContext dbContext = new EmployeeContext(); List<Department> departments = dbContext.Departments.ToList(); return View(departments); }
public ActionResult EditPost() { ActionResult action = View(); Employee employee = new Employee(); TryUpdateModel<Employee>(employee); if (ModelState.IsValid) { EmployeeContext dbContext = new EmployeeContext(); Employee currentDetails = dbContext.Employees.SingleOrDefault(x => x.EmployeeId == employee.EmployeeId); // Name property is black listed if (currentDetails != null) { currentDetails.Gender = employee.Gender; currentDetails.DateOfBirth = employee.DateOfBirth; currentDetails.City = employee.City; dbContext.SaveChanges(); } action = RedirectToAction("Index"); } return action; }
public ActionResult Index() { EmployeeContext dbContext = new EmployeeContext(); List<Employee> employees = dbContext.Employees.ToList(); return View(employees); }