Exemple #1
0
        public async Task <HttpResponseMessage> GetAllRequestIsAssignedForUser(HttpRequestMessage request, string userID, string groupID, string column, bool isDesc, int page, int pageSize, [FromBody] FilterDelegationAssignedModel filter)
        {
            Func <HttpResponseMessage> func = () =>
            {
                if (string.IsNullOrEmpty(userID) || string.IsNullOrEmpty(groupID))
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, nameof(userID) + MessageSystem.NoValues + nameof(groupID) + MessageSystem.NoValues));
                }
                //var model = _requestService.GetDelegationRequest(userID, groupID, filter);
                var model       = _requestService.GetAllAssignedRequestForUser(userID, groupID);
                var groupLeadId = __groupService.GetGroupLeadIdByGroup(Int32.Parse(groupID));
                //Check Data have status delegated have date now > end date
                foreach (var item in model)
                {
                    if (item.StatusRequest.Name == CommonConstants.StatusDelegation)
                    {
                        var user = AppUserManager.Users.Where(x => x.Id == item.DelegateId).FirstOrDefault();
                        //_requestService.CheckDataDelegationRequest(groupID, item.ID);
                        _requestService.CheckDataDelegationAllRequest(groupID, item, user.GroupId.ToString());
                    }
                }
                var requestData  = _requestService.GetDelegationRequest(userID, groupID, filter);
                var data         = requestData.OrderByField(column, isDesc).Skip((page - 1) * pageSize).Take(pageSize);
                var responseData = Mapper.Map <IEnumerable <Request>, IEnumerable <RequestViewModel> >(data);

                var paginationSet = new PaginationSet <RequestViewModel>()
                {
                    Items     = responseData,
                    PageIndex = page,
                    TotalRows = requestData.Count(),
                    PageSize  = pageSize
                };
                return(request.CreateResponse(HttpStatusCode.OK, paginationSet));
            };

            return(await CreateHttpResponse(request, func));
        }