public HttpResponseMessage AddConfigDelegation(HttpRequestMessage request, string userId, string groupId, ConfigDelegationModel delegationVm)
        {
            if (!ModelState.IsValid)
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            else
            {
                //List<ExplanationRequest> lstExplanationRequest = new List<ExplanationRequest>();
                //var ChangeStatusById = AppUserManager.FindByNameAsync(User.Identity.Name).Result.Id;
                List <object> lstData        = new List <object>();
                var           delegationData = _configDelegationService.GetDataDelegationById(delegationVm.ID.ToString());
                delegationData.UpdateConfigDelegation(delegationVm);
                _configDelegationService.Update(delegationData);
                _configDelegationService.SaveChange();

                //Get request by user and group.Filter by StatusRequest is Pendding or Delegate in about time
                var model = _requestService.GetAllRequestByUser(userId, groupId);
                var data  = model.Where(x => (x.StatusRequest.Name.Equals(CommonConstants.StatusPending) ||
                                              x.StatusRequest.Name.Equals(CommonConstants.StatusDelegation)) &&
                                        x.CreatedDate.Value.Date >= delegationData.StartDate &&
                                        x.CreatedDate.Value.Date <= delegationData.EndDate);
                lstData.AddRange(data);
                _configDelegationService.ChangeStatusRequestConfigDelegate(delegationData.AssignTo, data.ToList());

                //Get explanation by userid and groupid.Filter by StatusRequest is Pending or Delegate
                var explanation     = _explanationRequestService.GetListExplanationByUser(userId, groupId);
                var dataExplanation = explanation.Where(a => (a.StatusRequest.Name.Equals(CommonConstants.StatusPending) ||
                                                              a.StatusRequest.Name.Equals(CommonConstants.StatusDelegation)) &&
                                                        a.CreatedDate.Value.Date >= delegationData.StartDate &&
                                                        a.CreatedDate.Value.Date <= delegationData.EndDate);
                lstData.AddRange(explanation);
                _configDelegationService.ChangeStatusExplanationRequestConfigDelegate(delegationData.AssignTo, dataExplanation.ToList());
                return(request.CreateResponse(HttpStatusCode.Created, lstData));
            }
        }
Beispiel #2
0
        public async Task <HttpResponseMessage> SetDelegateDefault(HttpRequestMessage request, string userId, string groupId, GroupCreateUpdateModel groupVm)
        {
            if (!ModelState.IsValid)
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            else
            {
                List <string>             lstRequestId            = new List <string>();
                List <string>             lstExplanationRequestId = new List <string>();
                List <object>             lstData               = new List <object>();
                List <Request>            lstRequest            = new List <Request>();
                List <ExplanationRequest> lstExplanationRequest = new List <ExplanationRequest>();
                var ChangeStatusById = AppUserManager.FindByNameAsync(User.Identity.Name).Result.Id;
                var newGroup         = _groupService.GetGroupById(groupVm.ID.ToString());
                newGroup.UpdateGroup(groupVm);
                _groupService.Update(newGroup);
                _groupService.SaveChange();

                //Get request by user and group.Filter by StatusRequest is Pendding
                var model = _requestService.GetAllRequestByUser(userId, groupId);
                var group = _groupService.GetGroupById(groupId);
                var data  = model.Where(x => x.StatusRequest.Name.Equals(CommonConstants.StatusPending));
                if (group.DelegateId != null)
                {
                    foreach (var item in data)
                    {
                        if (item.CreatedDate != null)
                        {
                            if (group.StartDate <= item.CreatedDate.Value.Date && group.EndDate >= item.CreatedDate.Value.Date)
                            {
                                lstRequestId.Add(item.ID.ToString());
                                lstRequest.Add(item);
                            }
                        }
                    }
                    lstData.AddRange(lstRequest);
                    //Change status request by delegate default
                    _requestService.ChangeStatusDelegateDefault(CommonConstants.StatusDelegation, newGroup.DelegateId, newGroup.StartDate.Value, newGroup.EndDate.Value, ChangeStatusById, lstRequestId.ToArray());
                }


                //Get explanation by userid and groupid.Filter by StatusRequest is Pending
                var explanation = _explanationRequestService.GetListExplanationByUser(userId, groupId).Where(a => a.StatusRequest.Name.Equals(CommonConstants.StatusPending));

                if (explanation.Count() > 0 && group.DelegateId != null)
                {
                    foreach (var explanationItem in explanation)
                    {
                        if (explanationItem.CreatedDate != null)
                        {
                            if (group.StartDate <= explanationItem.CreatedDate.Value.Date && group.EndDate >= explanationItem.CreatedDate.Value.Date)
                            {
                                lstExplanationRequest.Add(explanationItem);
                                lstExplanationRequestId.Add(explanationItem.ID.ToString());
                            }
                        }
                    }
                    lstData.AddRange(lstExplanationRequest);
                    //Change status explanation request by delegate default
                    _explanationRequestService.ChangeStatusExplanationDelegateDefault(lstExplanationRequestId.ToArray(), CommonConstants.StatusDelegation, newGroup.DelegateId, newGroup.StartDate.Value, newGroup.EndDate.Value);
                }

                return(request.CreateResponse(HttpStatusCode.Created, lstData));
            }
        }