public IActionResult Edit(EmployeeView model) { if (model.Age < 18 || model.Age > 100) { ModelState.AddModelError(key: "Age", errorMessage: "Age is incorrect"); } if (!ModelState.IsValid) { return(View(model)); } if (model.Id > 0) { var dbItem = _employeeService.GetById(model.Id); if (ReferenceEquals(dbItem, null)) { return(NotFound()); } dbItem.FirstName = model.FirstName; dbItem.LastName = model.LastName; dbItem.Age = model.Age; dbItem.Patronymic = model.Patronymic; } else { _employeeService.AddNew(model); } _employeeService.Commit(); return(RedirectToAction(nameof(Index))); }
public IActionResult Edit(EmployeeView model) { if (ModelState.IsValid) { if (model.Id > 0) { var dbItem = _employeeData.GetById(model.Id); if (ReferenceEquals(dbItem, null)) { return(NotFound()); // возвращаем результат 404 Not Found } dbItem.Name = model.Name; dbItem.Age = model.Age; dbItem.Department = model.Department; dbItem.LastName = model.LastName; dbItem.Salary = model.Salary; dbItem.SecondName = model.SecondName; dbItem.Email = model.Email; } else { _employeeData.AddNew(model); } _employeeData.Comit(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public void AddNew([FromBody] EmployeeView model) { _employeeData.AddNew(model); }