/// <summary>
        /// Bind data from explanation detail to view model
        /// </summary>
        /// <param name="id">id of explanation</param>
        /// <returns> ExplanationRequestViewModel </returns>
        public ExplanationRequestViewModel GetExplanationDetailViewModel(int id)
        {
            List <ExplanationRequestViewModel> listModel = new List <ExplanationRequestViewModel>();

            // get explanation single
            var model = _explanationRequestService.GetExplanationDetail(id);

            // bind data to view model
            ExplanationRequestViewModel modelView = new ExplanationRequestViewModel
            {
                ID               = model.ID,
                Title            = model.Title,
                Actual           = model.Actual,
                GroupName        = model.AppUserCreatedBy.Group.Name,
                FullNameDelegate = AppUserManager.Users.Where(x => x.Id.Equals(model.DelegateId)).FirstOrDefault() != null?AppUserManager.Users.Where(x => x.Id.Equals(model.DelegateId)).FirstOrDefault().FullName : null,
                User             = new AppUserViewModel
                {
                    Id       = model.AppUserCreatedBy.Id,
                    FullName = model.AppUserCreatedBy.FullName,
                    Group    = model.FingerTimeSheet.FingerMachineUsers.AppUser.Group.Name != null ? new GroupViewModel
                    {
                        Name = model.FingerTimeSheet.FingerMachineUsers.AppUser.Group.Name
                    } : new GroupViewModel {
                    }
                },
                Receiver = new AppUserViewModel
                {
                    Id       = model.Receiver.Id,
                    FullName = model.Receiver.FullName
                },
                ReasonDetail    = model.ReasonDetail,
                CreatedDate     = (DateTime)model.CreatedDate,
                CreatedBy       = model.CreatedBy,
                FullName        = model.AppUserCreatedBy.FullName,
                ExplanationDate = model.FingerTimeSheet.DayOfCheck,
                StatusRequest   = new StatusRequestViewModel
                {
                    ID   = model.StatusRequest.ID,
                    Name = model.StatusRequest.Name
                },
                Approver = model.UpdatedBy != null ? new AppUserViewModel
                {
                    Id       = model.AppUserUpdatedBy.Id,
                    FullName = model.AppUserUpdatedBy.FullName
                } : new AppUserViewModel {
                },
                AbnormalReason = _explanationRequestService.GetAbnormalById(model.TimeSheetId).Select(m => new AbnormalCaseReasonViewModel
                {
                    ReasonId   = m.AbnormalReason.ID,
                    ReasonName = m.AbnormalReason.Name
                }).ToList()
            };

            // convert reason name in list to string
            ConvertSubstringToString(modelView);
            return(modelView);
        }
 /// <summary>
 /// Convert string in list into string
 /// </summary>
 /// <param name="model"><ExplanationRequestViewModel/param>
 /// <returns>ExplanationRequestViewModel</returns>
 public ExplanationRequestViewModel ConvertSubstringToString(ExplanationRequestViewModel model)
 {
     for (int i = 0; i < model.AbnormalReason.Count; i++)
     {
         if (i < model.AbnormalReason.Count - 1)
         {
             model.ReasonList += model.AbnormalReason[i].ReasonName + ", ";
         }
         else
         {
             model.ReasonList += model.AbnormalReason[i].ReasonName;
         }
     }
     return(model);
 }
 public async Task <HttpResponseMessage> Create(HttpRequestMessage request, string OTCheckIn, string OTCheckOut, ExplanationRequestViewModel explanationViewModel)
 {
     return(await CreateHttpResponse(request, () =>
     {
         var checkDelegate = new CheckDelegateModel();
         var dateNow = DateTime.Now.Date;
         var timesheet = _fingertimesheetService.GetById(explanationViewModel.TimeSheetId);
         var DateExRequestInPast = _commonService.GetDateExRequestInPast(timesheet.DayOfCheck);
         if (DateExRequestInPast.Date < dateNow)
         {
             return request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_CREATE_EXREQUEST_IN_PAST_NOT_MSG);
         }
         var explanation = new ExplanationRequest();
         explanation.UpdateExplanationRequest(explanationViewModel);
         if (explanation.Actual == "Leave")
         {
             var entitleDayAppUser = _explanationRequestService.GetEntitleDayByUserID(explanation.CreatedBy);
             var timeSheet = _fingertimesheetService.GetById(explanationViewModel.TimeSheetId);
             if ((timeSheet.Absent == CommonConstants.TimeSheetAbsent && entitleDayAppUser.MaxEntitleDayAppUser - entitleDayAppUser.NumberDayOff >= 1) ||
                 ((timeSheet.Absent == CommonConstants.TimeSheetAbsentAfternoon || timeSheet.Absent == CommonConstants.TimeSheetAbsentMorning) &&
                  entitleDayAppUser.MaxEntitleDayAppUser - entitleDayAppUser.NumberDayOff >= 0.5))
             {
                 if (_explanationRequestService.Add(explanation, OTCheckIn, OTCheckOut))
                 {
                     var group = __groupService.GetGroupById(explanationViewModel.GroupId.ToString());
                     var dataDelegation = _configDelegationService.GetDelegationByUserId(explanation.CreatedBy);
                     if (dataDelegation.StartDate <= explanation.CreatedDate.Value.Date && dataDelegation.EndDate >= explanation.CreatedDate.Value.Date)
                     {
                         checkDelegate.CheckConfigDelegateDefault = true;
                         checkDelegate.AssignConfigDelegate = dataDelegation.AssignTo;
                         _configDelegationService.ChangeStatusAfterAddExplanationRequest(dataDelegation.AssignTo, explanation);
                     }
                     else
                     {
                         if (explanation.CreatedDate != null)
                         {
                             if (group.DelegateId != null && group.StartDate <= explanation.CreatedDate.Value.Date && group.EndDate >= explanation.CreatedDate.Value.Date)
                             {
                                 checkDelegate.CheckGroupDelegateDefault = true;
                                 _explanationRequestService.AddDelegateDefault(explanationViewModel.GroupId, explanation.ID);
                             }
                         }
                     }
                     return request.CreateResponse(HttpStatusCode.Created, checkDelegate);
                 }
             }
             else
             {
                 return request.CreateErrorResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_CREATE_EXREQUEST_NOT_ENOUGH_ENTITLE_DAY);
             }
         }
         if (_explanationRequestService.Add(explanation, OTCheckIn, OTCheckOut))
         {
             var groupData = __groupService.GetGroupById(explanationViewModel.GroupId.ToString());
             var dataDelegationConfig = _configDelegationService.GetDelegationByUserId(explanation.CreatedBy);
             if (dataDelegationConfig.StartDate <= explanation.CreatedDate.Value.Date && dataDelegationConfig.EndDate >= explanation.CreatedDate.Value.Date)
             {
                 checkDelegate.CheckConfigDelegateDefault = true;
                 checkDelegate.AssignConfigDelegate = dataDelegationConfig.AssignTo;
                 _configDelegationService.ChangeStatusAfterAddExplanationRequest(dataDelegationConfig.AssignTo, explanation);
             }
             else
             {
                 if (explanation.CreatedDate != null)
                 {
                     if (groupData.DelegateId != null && groupData.StartDate <= explanation.CreatedDate.Value.Date && groupData.EndDate >= explanation.CreatedDate.Value.Date)
                     {
                         checkDelegate.CheckGroupDelegateDefault = true;
                         _explanationRequestService.AddDelegateDefault(explanationViewModel.GroupId, explanation.ID);
                     }
                 }
             }
             return request.CreateResponse(HttpStatusCode.Created, checkDelegate);
         }
         return request.CreateErrorResponse(HttpStatusCode.BadRequest, MessageSystem.Create_Explanation_Error);
     }));
 }
Example #4
0
 public static void UpdateExplanationRequest(this ExplanationRequest explanation, ExplanationRequestViewModel explanationViewModel)
 {
     explanation.Actual          = explanationViewModel.Actual;
     explanation.Title           = explanationViewModel.Title;
     explanation.CreatedBy       = explanationViewModel.CreatedBy;
     explanation.ReceiverId      = explanationViewModel.ReceiverId;
     explanation.ReasonDetail    = explanationViewModel.ReasonDetail;
     explanation.CreatedDate     = DateTime.Now;
     explanation.StatusRequestId = explanationViewModel.StatusRequestId;
     explanation.TimeSheetId     = explanationViewModel.TimeSheetId;
     explanation.Status          = true;
 }