public void GL_CreateExplanationTest1() { var explanation = new ExplanationRequest(); explanation.Title = "Giải trình cho việc nghỉ sớm ngày 24//02/2018"; explanation.StatusRequestId = 1; explanation.ReasonDetail = "có việc bận ở nhà"; explanation.TimeSheetId = 7; explanation.CreatedBy = userId1; explanation.CreatedDate = DateTime.Now; explanation.ReceiverId = userId2; var isAdded = explanationService.Add(explanation, null, null); Assert.AreEqual(true, isAdded); }
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); })); }