Exemplo n.º 1
0
        public async Task <HttpResponseMessage> ChangeStatus(HttpRequestMessage request, string action, string changeStatusBy, Request objectRequest)
        {
            Func <HttpResponseMessage> func = () =>
            {
                var rs = _requestService.ChangeStatusRequest(objectRequest, action, changeStatusBy);
                if (rs == null)
                {
                    return(request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.APPROVED_ERROR_HNN));
                }
                else if (rs.StatusRequest.Name == CommonConstants.StatusPending)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.OK, MessageSystem.Pending));
                }
                else if (rs.StatusRequest.Name == CommonConstants.StatusRejected)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.OK, MessageSystem.Rejected));
                }
                else if (rs.StatusRequest.Name == CommonConstants.StatusApproved)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.OK, MessageSystem.Approved));
                }
                return(request.CreateErrorResponse(HttpStatusCode.OK, MessageSystem.CancelFail));
            };

            return(await CreateHttpResponse(request, func));
        }
Exemplo n.º 2
0
 public HttpResponseMessage ChangeStatusRequest(HttpRequestMessage request, int requestId, string typeStatus, string userIdDelegate)
 {
     if (string.IsNullOrEmpty(requestId.ToString()) || string.IsNullOrEmpty(typeStatus))
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, nameof(requestId) + MessageSystem.NoValues + nameof(typeStatus) + MessageSystem.NoValues));
     }
     if (ModelState.IsValid)
     {
         try
         {
             Request requestEntity = _requestService.GetById(requestId);
             var     dateNow       = DateTime.Now;
             if (requestEntity.StartDate.AddHours(23) < dateNow)
             {
                 return(request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_CHANGESTATUS_REQUEST_IN_PAST_NOT_MSG));
             }
             var user = AppUserManager.Users.Where(x => x.Id.Equals(requestEntity.UserId)).FirstOrDefault();
             //Check if request in about set delegate default time that status is "Delegated",will not set delegate
             if (requestEntity != null && typeStatus.Equals(CommonConstants.StatusDelegation))
             {
                 var group = __groupService.GetGroupById(user.GroupId.ToString());
                 if (group.EndDate != null && requestEntity.CreatedDate != null)
                 {
                     if (group.EndDate.Value.Date < DateTime.Now.Date && group.StartDate.Value.Date <= requestEntity.CreatedDate.Value.Date && requestEntity.CreatedDate.Value.Date <= group.EndDate.Value.Date)
                     {
                         return(request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_CHANGESTATUS_REQUEST_NOT_IN_DELEGATEDEFAULT_TIME_MSG));
                     }
                 }
             }
             requestEntity.ChangeStatusById = AppUserManager.FindByNameAsync(User.Identity.Name).Result.Id;
             requestEntity.UpdatedDate      = DateTime.Now;
             if (_requestService.ChangeStatusRequest(requestEntity, typeStatus, userIdDelegate) == null)
             {
                 return(request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_HNN));
             }
             _requestService.Save();
             return(request.CreateResponse(HttpStatusCode.OK, Mapper.Map <TMS.Model.Models.Request, RequestViewModel>(requestEntity)));
         }
         catch (Exception dex)
         {
             return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
         }
     }
     else
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }