public IActionResult Edit(int id) { SQLEmployeeData sqlData = new SQLEmployeeData(_context); var model = sqlData.Get(id); if (model == null) { return(RedirectToAction("Index")); } return(View(model)); }
public ViewResult Index() { var model = new HomePageViewModel(); if (_context != null) { SQLEmployeeData sqlData = new SQLEmployeeData(_context); model.Employees = sqlData.GetAll(); } return(View(model)); }
public IActionResult Edit(int id, EmployeeEditViewModel input) { SQLEmployeeData sqlData = new SQLEmployeeData(_context); var employee = sqlData.Get(id); if (employee != null && ModelState.IsValid) { employee.Name = input.Name; _context.SaveChanges(); return(RedirectToAction("Details", new { id = employee.Id })); } return(View(employee)); }
public IActionResult Create(EmployeeEditViewModel model) { if (ModelState.IsValid) { var employee = new Employee(); employee.Name = model.Name; var context = _context; SQLEmployeeData sqlData = new SQLEmployeeData(context); sqlData.Add(employee); return(RedirectToAction("Details", new { id = employee.Id })); } return(View()); }