Пример #1
0
 public HttpResponseMessage ChangeStatusMultiRequest(HttpRequestMessage request, string typeStatus, string userIdDelegate, string[] requestId)
 {
     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
         {
             var            dateNow     = DateTime.Now;
             List <Request> listRequest = new List <Request>();
             foreach (var item in requestId)
             {
                 Request requestEntity = _requestService.GetById(int.Parse(item));
                 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;
                 listRequest.Add(requestEntity);
             }
             return(request.CreateResponse(HttpStatusCode.OK, _requestService.ChangeStatusListRequest(listRequest, typeStatus, userIdDelegate).IsCompleted));
         }
         catch (Exception dex)
         {
             return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
         }
     }
     else
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }