public async Task <IHttpActionResult> Action(PersonnelShiftReplacementActionDto personnelShiftReplacementAction) { if (personnelShiftReplacementAction == null) { return(BadRequest()); } if (!ModelState.IsValid) { string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState); return(BadRequest(errorMessage)); } try { var result = await _personnelShiftReplacementService.Action(personnelShiftReplacementAction); 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 async Task <CustomResult> Action(PersonnelShiftReplacementActionDto dto) { var personnelShiftReplacement = _personnelShiftReplacementRepository .Get(q => q.Id == dto.PersonnelShiftReplacementId, includeProperties: "Personnel") .SingleOrDefault(); if (personnelShiftReplacement != null) { if (personnelShiftReplacement.ActionDate.HasValue && personnelShiftReplacement.RequestAction != RequestAction.PartialAccept) { return(new CustomResult { Message = "your request is processed before" }); } personnelShiftReplacement.ActionDate = DateTime.Now; //still needs to confirm with superior in the proc if (dto.ParentApprovalProcId.HasValue) { var receiverInfo = _approvalProcService .GetNextReceiverId(dto.ParentApprovalProcId.Value); if (dto.RequestAction == RequestAction.Accept) { await _requestMessageHandlerService.SubmitMessage(dto.MessageId, receiverInfo , dto.RequestId, dto.RequestType, personnelShiftReplacement.RequestAction, personnelShiftReplacement.Personnel.Code); personnelShiftReplacement.RequestAction = RequestAction.PartialAccept; personnelShiftReplacement.ActionDescription = dto.ActionDescription; } else if (dto.RequestAction == RequestAction.Reject) { personnelShiftReplacement.RequestAction = RequestAction.Reject; personnelShiftReplacement.ActionDescription = dto.ActionDescription; } } else { //no superior personnelShiftReplacement.RequestAction = dto.RequestAction; personnelShiftReplacement.ActionDescription = dto.ActionDescription; } _personnelShiftReplacementRepository.Update(personnelShiftReplacement); //update request message action _requestMessageHandlerService.UpdateRequestAction(dto.MessageId, personnelShiftReplacement.RequestAction); } else { try { throw new LogicalException(); } catch (LogicalException ex) { _logger.LogLogicalError (ex, "PersonnelShiftReplacement entity with the id: '{0}', is not available." + " action operation failed.", dto.PersonnelShiftReplacementId); throw; } } return(new CustomResult { IsValid = true }); }