public void OTRequest_Service_AddUT1() { OTRequest OTRequest = new OTRequest(); OTRequest.Title = "test1"; OTRequest.StatusRequestID = 1; OTRequest.OTTimeTypeID = 1; OTRequest.OTDateTypeID = 1; OTRequest.CreatedBy = UserID2; OTRequest.CreatedDate = DateTime.Now; OTRequest.OTDate = DateTime.Now.AddDays(1); //call action otRequest = objServices.Add(OTRequest, UserID2); //compare Assert.IsNotNull(otRequest); }
public async Task <HttpResponseMessage> Create(HttpRequestMessage request, string userID, string groupId, OTRequestViewModel otRequestVm) { return(await CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } var tmp = otRequestVm.OTRequestUserID.ToList(); tmp.Add(otRequestVm.UserID); otRequestVm.OTRequestUserID = tmp.Distinct().ToArray(); var newOTRequest = new OTRequest(); newOTRequest.UpdateOTRequest(otRequestVm); var dateNow = DateTime.Now.Date; if (otRequestVm.OTDate == dateNow && _otrequestService.CheckCreateDay(newOTRequest) == false) { return request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_CREATE_OTREQUEST_IN_PAST_NOT_MSG); } if (_otrequestService.CheckOtRequestUser(newOTRequest, otRequestVm.OTRequestUserID.ToList()) == false) { return request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_CANNOT_CREATE_OT_EXIST); } if (otRequestVm.OTDate < dateNow) { return request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_CREATE_OTREQUEST_IN_PAST_NOT_MSG); } // nomal if (otRequestVm.OTDate != null && _commonService.isWorkingDay(otRequestVm.OTDate.Value) && otRequestVm.OTDateTypeID != CommonConstants.OTDateTypeNormal) { return request.CreateResponse(HttpStatusCode.BadRequest, otRequestVm.OTDate.Value.Date.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + " is " + otRequestVm.OTDate.Value.DayOfWeek + ", " + MessageSystem.ERROR_MUST_SELECT_NOMAL); } // weekend if (otRequestVm.OTDate != null && _commonService.isWeekend(otRequestVm.OTDate.Value) && otRequestVm.OTDateTypeID != CommonConstants.OTDateTypeWeekend) { return request.CreateResponse(HttpStatusCode.BadRequest, otRequestVm.OTDate.Value.Date.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + " is " + otRequestVm.OTDate.Value.DayOfWeek + ", " + MessageSystem.ERROR_MUST_SELECT_WEEKEND); } //holiday if (otRequestVm.OTDate != null && _commonService.isHoliday(otRequestVm.OTDate.Value) && otRequestVm.OTDateTypeID != CommonConstants.OTDateTypeHoliDay) { return request.CreateResponse(HttpStatusCode.BadRequest, otRequestVm.OTDate.Value.Date.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + " is " + otRequestVm.OTDate.Value.DayOfWeek + ", " + MessageSystem.ERROR_MUST_SELECT_HOLIDAY); } else { if (TimeSpan.ParseExact(otRequestVm.StartTime, @"hh\:mm", CultureInfo.InvariantCulture) > TimeSpan.ParseExact(otRequestVm.EndTime, @"hh\:mm", CultureInfo.InvariantCulture)) { return request.CreateErrorResponse(HttpStatusCode.BadRequest, MessageSystem.StartTimeCompareEndTime); } var checkCondition = _otrequestService.CheckConditionCreate(otRequestVm.OTDateTypeID, otRequestVm.OTTimeTypeID, otRequestVm.StartTime, otRequestVm.EndTime); if (!string.IsNullOrEmpty(checkCondition)) { return request.CreateErrorResponse(HttpStatusCode.BadRequest, checkCondition); } if (_otrequestService.CheckOtRequestUser(newOTRequest, otRequestVm.OTRequestUserID.ToList()) == true) { _otrequestService.Add(newOTRequest, userID); var responseData = Mapper.Map <OTRequest, OTRequestViewModel>(newOTRequest); _otRequestUserService.Add(otRequestVm.OTRequestUserID, newOTRequest.ID); response = request.CreateResponse(HttpStatusCode.Created, responseData); } else { response = request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_CANNOT_CREATE_OT_EXIST); } } return response; })); }