public async Task <IHttpActionResult> Action(PersonnelDutyActionDto personnelDutyAction) { if (personnelDutyAction == null) { return(BadRequest()); } if (!ModelState.IsValid) { string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState); return(BadRequest(errorMessage)); } try { var result = await _personnelDutyService.Action(personnelDutyAction); 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(PersonnelDutyActionDto dto) { var personnelDuty = _personnelDutyRepository .Get(q => q.Id == dto.PersonnelDutyId, includeProperties: "Personnel,Duty") .SingleOrDefault(); if (personnelDuty != null) { if (personnelDuty.ActionDate.HasValue && personnelDuty.RequestAction != RequestAction.PartialAccept) { return(new CustomResult { Message = "your request is processed before" }); } if (LimitPassed(personnelDuty)) { personnelDuty.RequestAction = RequestAction.Reject; personnelDuty.ActionDescription = "action time period is finished"; } else { personnelDuty.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) { personnelDuty.RequestAction = RequestAction.PartialAccept; personnelDuty.ActionDescription = dto.ActionDescription; await _requestMessageHandlerService.SubmitMessage(dto.MessageId, receiverInfo , dto.RequestId, dto.RequestType, personnelDuty.RequestAction, personnelDuty.Personnel.Code); } else if (dto.RequestAction == RequestAction.Reject) { personnelDuty.RequestAction = RequestAction.Reject; personnelDuty.ActionDescription = dto.ActionDescription; } } else { //no superior personnelDuty.RequestAction = dto.RequestAction; personnelDuty.ActionDescription = dto.ActionDescription; } } _personnelDutyRepository.Update(personnelDuty); //update request message action _requestMessageHandlerService.UpdateRequestAction(dto.MessageId, personnelDuty.RequestAction); } else { try { throw new LogicalException(); } catch (LogicalException ex) { _logger.LogLogicalError (ex, "PersonnelDuty entity with the id: '{0}', is not available." + " action operation failed.", dto.PersonnelDutyId); throw; } } return(new CustomResult { IsValid = true }); }