コード例 #1
0
        /// <summary>
        /// Bind data explanation list to view model
        /// </summary>
        /// <param name="userId">id of user logged</param>
        /// <param name="groupId">groupId of user logged</param>
        /// <param name="column">name of column to sort</param>
        /// <param name="isDesc">parameter to check to sort by asc or desc</param>
        /// <param name="page">current page(use in paging)</param>
        /// <param name="pageSize">number of page showing(use in paging)</param>
        /// <param name="filter">list conditions to filter</param>
        /// <returns> explanations list as view model type </returns>
        public List <ExplanationRequestViewModel> GetExplanationAssignedListViewModel(string userId,
                                                                                      string groupId, string column, bool isDesc, int page, int pageSize, FilterDelegationAssignedModel filter)
        {
            List <ExplanationRequestViewModel> listModel = new List <ExplanationRequestViewModel>();

            // get explanation list
            //var model = _explanationRequestService.GetExplanationsRequestAssignedList(userId, groupId, column, isDesc, page, pageSize, filter);
            var model = _explanationRequestService.GetListExplanationAssigned(userId, 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.ReceiverId).FirstOrDefault();
                    //_explanationRequestService.CheckDataDelegationExplanationRequest(item.AppUserCreatedBy.Group.ID, item.ID);
                    _explanationRequestService.CheckDataDelegationAllExplanationRequest(item.AppUserCreatedBy.Group.ID, item.ID, Convert.ToInt32(user.GroupId));
                }
            }
            _explanationRequestService.Save();
            var data = _explanationRequestService.GetExplanationsRequestAssignedList(userId, groupId, column, isDesc, page, pageSize, filter);

            // bind data to view model
            foreach (var item in data)
            {
                listModel.Add(new ExplanationRequestViewModel
                {
                    ID    = item.ID,
                    Title = item.Title,
                    User  = new AppUserViewModel
                    {
                        Id       = item.AppUserCreatedBy.Id,
                        FullName = item.AppUserCreatedBy.FullName,
                        Email    = item.AppUserCreatedBy.Email,
                        Group    = new GroupViewModel
                        {
                            Name = item.FingerTimeSheet.FingerMachineUsers.AppUser.Group.Name
                        }
                    },
                    Receiver = new AppUserViewModel
                    {
                        Id       = item.Receiver.Id,
                        FullName = item.Receiver.FullName
                    },
                    ReasonDetail    = item.ReasonDetail,
                    CreatedDate     = (DateTime)item.CreatedDate,
                    UpdatedDate     = item.UpdatedDate,
                    ExplanationDate = item.FingerTimeSheet.DayOfCheck,
                    StatusRequest   = new StatusRequestViewModel
                    {
                        ID   = item.StatusRequest.ID,
                        Name = item.StatusRequest.Name
                    },
                    Approver = item.UpdatedBy != null ? new AppUserViewModel
                    {
                        Id       = item.AppUserUpdatedBy.Id,
                        FullName = item.AppUserUpdatedBy.FullName
                    } : new AppUserViewModel {
                    },
                    Delegate = item.DelegateId != null ? new AppUserViewModel
                    {
                        Id       = item.Delegate.Id,
                        FullName = item.Delegate.FullName
                    } : new AppUserViewModel {
                    },
                    AbnormalReason = _explanationRequestService.GetAbnormalById(item.TimeSheetId).Select(m => new AbnormalCaseReasonViewModel
                    {
                        ReasonId   = m.AbnormalReason.ID,
                        ReasonName = m.AbnormalReason.Name
                    }).ToList()
                });
            }
            return(listModel);
        }