public async Task <IActionResult> UpdateEmployeeDepartment(int Id, EmployeeDepartmentForUpdateDto employeeDepartment) { var EmployeeDepartmentFromRepo = await _EmployeeDepartmentRepository.GetEmployeeDepartmentAsync(Id); if (EmployeeDepartmentFromRepo == null) { return(NotFound()); } var validationResults = new EmployeeDepartmentForUpdateDtoValidator().Validate(employeeDepartment); validationResults.AddToModelState(ModelState, null); if (!ModelState.IsValid) { return(BadRequest(new ValidationProblemDetails(ModelState))); //return ValidationProblem(); } _mapper.Map(employeeDepartment, EmployeeDepartmentFromRepo); _EmployeeDepartmentRepository.UpdateEmployeeDepartment(EmployeeDepartmentFromRepo); await _EmployeeDepartmentRepository.SaveAsync(); return(NoContent()); }
public async Task <IActionResult> Edit([FromForm] EmployeeDepartmentViewModel employeeDepartmentVM) { if (ModelState.IsValid) { await _employeeDeparment.UpdateEmployeeDepartment(employeeDepartmentVM.EmployeeDepartment); TempData["message"] = "Your data has been updated successfully."; TempData["toasterType"] = ToasterType.success; return(RedirectToAction(nameof(Edit), new { id = employeeDepartmentVM.EmployeeDepartment.Id, returnUrl = employeeDepartmentVM.ReturnUrl })); } else { TempData["message"] = "A problem has been ocurred while updating your data."; TempData["toasterType"] = ToasterType.info; } return(View("Edit", EmployeeDepartmentViewModelFactory.Edit(employeeDepartmentVM.EmployeeDepartment, employeeDepartmentVM.ReturnUrl))); }