Ejemplo n.º 1
0
        public async Task<HttpResponseMessage> CreateTimeDay(HttpRequestMessage request, TimeDayViewModel timedayVm)
        {
            return await CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    if (_timeDayService.CheckEqual(timedayVm.Workingday, timedayVm.ID))
                    {
                        return request.CreateResponse(HttpStatusCode.BadRequest, Common.Constants.MessageSystem.CheckExits);
                    }
                    var checkConditon = _timeDayService.CheckConditionTime(timedayVm.CheckIn, timedayVm.CheckOut);
                    if (!string.IsNullOrEmpty(checkConditon))
                    {
                        return request.CreateErrorResponse(HttpStatusCode.BadRequest, checkConditon);
                    }
                    TimeDay newTimeday = new TimeDay();
                    newTimeday.UpdateTimeday(timedayVm);
                    var timeDay = _timeDayService.Add(newTimeday);
                    var responseData = Mapper.Map<TimeDay, TimeDayViewModel>(timeDay);
                    _timeDayService.SaveChange();

                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }
                return response;
            });
        }
Ejemplo n.º 2
0
 public static void UpdateTimeday(this TimeDay timeday, TimeDayViewModel timedayViewModel)
 {
     timeday.ID         = timedayViewModel.ID;
     timeday.Workingday = timedayViewModel.Workingday;
     timeday.CheckIn    = timedayViewModel.CheckIn;
     timeday.CheckOut   = timedayViewModel.CheckOut;
 }
        public float?GetRateForRange(Guid groupId, TimeDay beginTime, TimeDay endTime)
        {
            if (beginTime.DayOfWeek != endTime.DayOfWeek || beginTime.TimeOfDay > endTime.TimeOfDay)
            {
                // Requirements can determine more specific behaviour of invalid time ranges
                throw new ArgumentException($"Days do not match for {beginTime} and {endTime}");
            }

            var rateGroup = RateGroupProvider.GetGroup(groupId);

            if (!rateGroup.DayRateRanges.TryGetValue(beginTime.DayOfWeek, out List <TimeRangeRate> dayRates))
            {
                return(null); // valid times but unavailable
            }

            // This runs in linear time. If we expect groups to have many rates for each day,
            // a better data structure could be used to get something like O(log n) time on this search.
            // e.g. A type of Trie in the form of [Day][Hour][Minute] => rate could be
            // pre-computed for a given group
            // Strictly greater and lesser than based on requirements of full encapsulation
            var result = dayRates.SingleOrDefault(dayRate =>
                                                  dayRate.BeginTime <beginTime.TimeOfDay && dayRate.EndTime> endTime.TimeOfDay);

            return(result?.Price);
        }
Ejemplo n.º 4
0
        public void UCT05()
        {
            TimeDay timedays = new TimeDay();

            timedays.ID = 1;
            var id = timedays.ID;

            timeday = timeDayService.Delete(id);
            Assert.IsNotNull(timeday);
        }
 public void OnTimeSet(TimePicker view, int hourOfDay, int minute)
 {
     //we display the LCOAL time for the user
     if (_isDateDay)
     {
         _dateDaySelected = new TimeDay(hourOfDay, minute);
         _dateDaySelectedHandler(_dateDaySelected);
     }
     else
     {
         _dateSelected = new Time(hourOfDay, minute);
         _dateSelectedHandler(_dateSelected);
     }
 }
Ejemplo n.º 6
0
        public TimeDay GetTimeDay(DateTime date)
        {
            if (_holidayRepository.IsHoliday(date))
            {
                return(null);
            }
            TimeDay timeDay = _timeDayRepository.GetSingleByCondition(x => x.Workingday == date.DayOfWeek.ToString());

            if (timeDay == null)
            {
                Holiday holiday = _holidayRepository.GetHolidayForDateOffset(date);
                return(holiday != null?GetTimeDayForDateOffset(holiday) : null);
            }
            return(timeDay);
        }
Ejemplo n.º 7
0
        public static TimeDay GetUtcTimeDayFromString(string dateTime)
        {
            var zonedDateTime = GetUtcDateTimeFromString(dateTime);

            if (zonedDateTime == null)
            {
                return(null);
            }

            var result = new TimeDay
            {
                DayOfWeek = zonedDateTime.Value.DayOfWeek,
                TimeOfDay = zonedDateTime.Value.Hour * 100 + zonedDateTime.Value.Minute
            };

            return(result);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// fuction update
 /// </summary>
 /// <param name="timeday"></param>
 public void Update(TimeDay timeday)
 {
     _timeDayRepository.Update(timeday);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// function add
 /// </summary>
 /// <param name="timeday"></param>
 /// <returns></returns>
 public TimeDay Add(TimeDay timeday)
 {
     return(_timeDayRepository.Add(timeday));
 }
Ejemplo n.º 10
0
 public void UCT03()
 {
     timeday = timeDayService.GetbyId(10);
     Assert.IsNull(timeday);
 }
Ejemplo n.º 11
0
 public void UCT02()
 {
     timeday = timeDayService.GetbyId(2);
     Assert.IsNotNull(timeday);
 }