Esempio n. 1
0
 public void OTRequest_Service_GetByIdUT2()
 {
     //call action
     otRequest = objServices.GetById(20);
     //compare
     Assert.IsNull(otRequest);
 }
Esempio n. 2
0
        public bool CheckCreateDay(OTRequest oTRequest)
        {
            DateTime dateNow = DateTime.Now;

            if ((TimeSpan.ParseExact(oTRequest.StartTime, @"hh\:mm", CultureInfo.InvariantCulture)) < (TimeSpan.ParseExact(dateNow.ToString("HH:mm"), @"hh\:mm", CultureInfo.InvariantCulture)))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 3
0
        public void OTRequest_Service_AddUT2()
        {
            OTRequest OTRequest = new OTRequest();

            OTRequest.Title           = null;
            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.IsNull(otRequest);
        }
Esempio n. 4
0
 public static void UpdateOTRequest(this OTRequest otRequest, OTRequestViewModel otRequestVm)
 {
     otRequest.ID              = otRequestVm.ID;
     otRequest.Title           = otRequestVm.Title;
     otRequest.CreatedBy       = otRequestVm.CreatedBy;
     otRequest.OTDate          = otRequestVm.OTDate;
     otRequest.OTDateTypeID    = otRequestVm.OTDateTypeID;
     otRequest.OTTimeTypeID    = otRequestVm.OTTimeTypeID;
     otRequest.StatusRequestID = otRequestVm.StatusRequestID;
     otRequest.UserAssignedID  = otRequestVm.UserAssignedID;
     otRequest.CreatedDate     = otRequestVm.CreatedDate;
     otRequest.UpdatedDate     = otRequestVm.UpdatedDate;
     otRequest.UpdatedBy       = otRequestVm.UpdatedBy;
     otRequest.StartTime       = otRequestVm.StartTime;
     otRequest.EndTime         = otRequestVm.EndTime;
 }
Esempio n. 5
0
        public bool CheckOtRequestUser(OTRequest otRequest, List <string> otRequestUser)
        {
            var lstOTRequestUser = _oTRequestUserRepository.GetMulti(x => x.OTRequest.OTDate == otRequest.OTDate && x.OTRequest.StatusRequest.Name != CommonConstants.StatusCancelled).Select(x => x.UserID).ToList();
            var lstOTRequest     = _otrequestRepository.GetMulti(x => x.OTDate == otRequest.OTDate && x.StatusRequest.Name != CommonConstants.StatusCancelled);

            lstOTRequestUser.AddRange(lstOTRequest.Select(x => x.CreatedBy));
            lstOTRequestUser = lstOTRequestUser.Distinct().ToList();
            otRequestUser    = otRequestUser.Distinct().ToList();
            if (otRequestUser.Any(x => lstOTRequestUser.Contains(x)))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Add OT request into database
 /// </summary>
 /// <param name="otRequest"></param>
 /// <param name="userID"></param>
 /// <returns>OTReuqest</returns>
 public OTRequest Add(OTRequest otRequest, string userID)
 {
     try {
         otRequest.StatusRequestID = _statusRequestRepository.GetAll().FirstOrDefault(x => x.Name.Equals(CommonConstants.StatusPending)).ID;
         otRequest.CreatedDate     = DateTime.Now;
         otRequest.CreatedBy       = userID;
         var OTRequest = _otrequestRepository.Add(otRequest);
         Save();
         return(OTRequest);
     }
     catch (DbUpdateException e)
     {
         return(null);
     }
     catch (InvalidOperationException ex)
     {
         return(null);
     }
 }
        public OTRequest GetOTRequest(int ReqID, int?FY, string Username)
        {
            try
            {
                this.persister.CorrelationId = this.CorrelationId;
                DataSet   ds  = persister.GetOTRequest(ReqID, FY, Username);
                OTRequest obj = new OTRequest();
                obj.ReqID  = ReqID;
                obj.Header = (from DataRow row in ds.Tables[0].AsEnumerable()
                              select new Header()
                {
                    OTCode = row["OTCode"].ToString(),
                    Status = new IDDescription()
                    {
                        ID = Convert.ToInt32(row["StatusID"]),
                        Description = row["StatusName"].ToString(),
                    },
                    RequestType = new IDDescription()
                    {
                        ID = Convert.ToInt32(row["RequestTypeID"]),
                        Description = Enum.GetName(typeof(RequestType), Convert.ToInt32(row["RequestTypeID"])),
                    },
                    BriefDescription = row["BriefDescription"].ToString(),
                    DetailDescription = row["DetailDescription"].ToString(),
                    CashOrComp = row["CashOrComp"].ToString(),
                    BureauOwner = row["BureauOwner"].ToString(),
                    StartDate = Convert.ToDateTime(row["StartDate"]),
                    EndDate = Convert.ToDateTime(row["EndDate"]),
                    IFY = Convert.ToInt32(row["IFY"]),
                    AuthorizedOTAmount = Convert.ToDecimal(row["AuthorizedOTAmount"]),
                    EstimatedOTHours = Convert.ToDecimal(row["EstimatedOTHours"]),
                    AuthorizedOTHours = Convert.ToDecimal(row["AuthorizedOTHours"]),
                    ActiveOTCode = Convert.ToBoolean(row["ActiveOTCode"])
                                   // Neha TBD copy all the variables
                }).FirstOrDefault();

                return(obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public HttpResponseMessage GetOTRequest(int?reqid = null, int?fy = null)
        {
            HttpStatusCode       ReturnCode  = HttpStatusCode.OK;
            TranInfo <OTRequest> transaction = new TranInfo <OTRequest>();

            try
            {
                ExtractClaimDetails();

                OTRequest obj;
                if (reqid.HasValue)
                {
                    obj = service.GetOTRequest((int)reqid, fy, Username);
                }
                else
                {
                    obj = new OTRequest();
                }

                transaction.data   = obj;
                transaction.status = true;
            }
            catch (Exception ex)
            {
                transaction.AddException(ex.Message);
                ReturnCode = HttpStatusCode.InternalServerError;

                if (ex.InnerException != null)
                {
                    InnerExceptionMessage = ex.InnerException.Message;
                }
                LogHelper.Instance.Error(service.CorrelationId, Username, Request.GetRequestContext().VirtualPathRoot, ex.Message, InnerExceptionMessage, 0, ex);
            }

            return(Request.CreateResponse <TranInfo <OTRequest> >(ReturnCode, transaction));
        }
Esempio n. 9
0
 public void UpdateOTRequest(OTRequest oTRequest)
 {
     _otrequestRepository.Update(oTRequest);
     Save();
 }
Esempio n. 10
0
        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;
            }));
        }