public IHttpActionResult Update([FromBody] UpdatePersonnelDto personnel) { if (personnel == null) { return(BadRequest()); } //custom validations var validator = new UpdatePersonnelDtoValidator(); var results = validator.Validate(personnel); if (!results.IsValid) { foreach (var failure in results.Errors) { ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage); } } if (!ModelState.IsValid) { string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState); return(BadRequest(errorMessage)); } try { var result = _personnelService.Update(personnel); if (!result.IsValid) { return(BadRequest(result.Message)); } } catch (LogicalException ex) { return(BadRequest(ex.Message)); } catch { return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE)); } return(Ok()); }
public CustomResult Update(UpdatePersonnelDto dto) { var personnel = _personnelRepository.GetById(dto.Id); if (personnel != null) { #region Update Personnel Info if (PersonnelCodeExistsInDB(dto.Code, personnel.Id)) { return(new CustomResult { IsValid = false, Message = "person code is not unique" }); } if (NationalCodeExistsInDB(dto.NationalCode, personnel.Id)) { return(new CustomResult { IsValid = false, Message = "national code is not unique" }); } personnel.Code = dto.Code; personnel.Name = dto.Name; personnel.LastName = dto.LastName; personnel.FathersName = dto.FathersName; personnel.NationalCode = dto.NationalCode; personnel.BirthCertificateCode = dto.BirthCertificateCode; personnel.PlaceOfBirth = dto.PlaceOfBirth; personnel.State = dto.State; personnel.City = dto.City; personnel.PostalCode = dto.PostalCode; personnel.BirthDate = dto.BirthDate; personnel.Email = dto.Email; personnel.Mobile = dto.Mobile; personnel.Phone = dto.Phone; personnel.Address = dto.Address; personnel.Education = dto.Education; personnel.MilitaryServiceStatus = dto.MilitaryServiceStatus; personnel.Gender = dto.Gender; personnel.MaritalStatus = dto.MaritalStatus; personnel.GroupCategoryId = dto.GroupCategoryId; personnel.EmployeementTypeId = dto.EmployeementTypeId; personnel.PositionId = dto.PositionId; personnel.InsuranceRecordDuration = dto.InsuranceRecordDuration; personnel.NoneInsuranceRecordDuration = dto.NoneInsuranceRecordDuration; personnel.BankAccountNumber = dto.BankAccountNumber; personnel.DateOfEmployeement = dto.DateOfEmployeement; personnel.FirstDateOfWork = dto.FirstDateOfWork; personnel.LastDateOfWork = dto.LastDateOfWork; personnel.LeavingWorkCause = dto.LeavingWorkCause; personnel.ActiveState = dto.ActiveState; _personnelRepository.Update(personnel); #endregion #region Update Approvals _personnelApprovalProcService.CreateOrUpdate(new PersonnelApprovalProcDto { Id = dto.Id, DismissalApprovalProcId = dto.DismissalApprovalProcId, DutyApprovalProcId = dto.DutyApprovalProcId, ShiftReplacementProcId = dto.ShiftReplacementProcId }); _dismissalApprovalService.Update(dto.DismissalApprovals, personnel.Id); _dutyApprovalService.Update(dto.DutyApprovals, personnel.Id); #endregion return(new CustomResult { IsValid = true }); } else { try { throw new LogicalException(); } catch (LogicalException ex) { _logger.LogLogicalError (ex, "Personnel entity with the id: '{0}', is not available." + " update operation failed.", dto.Id); throw; } } }