Exemplo n.º 1
0
        private IActionResult ScheduleTimeSlot(TimeSlotModel model)
        {
            if (model == null)
            {
                return(BadRequest("There is no enough information to schedule time slot"));
            }


            var timeSlot = model.ToEntity();

            try
            {
                //prevent overlapping of time slots which can due to overlapping of requests
                lock (Locker)
                {
                    var minimalStartDate = (timeSlot.ScheduledFor ?? DateTime.Now).AddHours(-8);
                    Expression <Func <SchedulingBoard, bool> > condition;
                    if (timeSlot.ScheduledFor.HasValue)
                    {
                        condition = m =>
                                    m.StartsAt.CompareTo(minimalStartDate) > 0 && m.StartsAt.CompareTo(timeSlot.ScheduledFor.Value) <= 0;
                    }
                    else
                    {
                        condition = m =>
                                    m.StartsAt.CompareTo(minimalStartDate) > 0;
                    }

                    var schedulingBoardCandidates = _schedulingRepository.FetchBoardsAsync(condition).Result;
                    foreach (var schedulingBoardCandidate in schedulingBoardCandidates)
                    {
                        if (!timeSlot.ScheduledFor.HasValue)
                        {
                            var scheduledFor = schedulingBoardCandidate.GetTimeForTimeSlot(timeSlot);
                            if (scheduledFor.HasValue)
                            {
                                timeSlot.SetTime(scheduledFor);
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else if (!schedulingBoardCandidate.IsTimeSlogValidForBoard(timeSlot))
                        {
                            continue;
                        }

                        timeSlot.SchedulingBoardId = schedulingBoardCandidate.Id;
                        _schedulingRepository.Schedule(timeSlot).Wait();
                        return(Ok(timeSlot));
                    }
                }
            }
            catch (ArgumentException ae)
            {
                return(BadRequest(ae.Message));
            }
            return(BadRequest("Business rules prevented scheduling"));
        }
Exemplo n.º 2
0
        public void ToEntity_Intervention_Success()
        {
            var unitUnderTest = new TimeSlotModel
            {
                TimeSlotType = TimeSlotType.Intervention
            };
            var convertedEntity = unitUnderTest.ToEntity();

            Assert.IsType <InterventionTimeSlot>(convertedEntity);
        }
Exemplo n.º 3
0
        public void ToEntity_Control_Success()
        {
            var unitUnderTest = new TimeSlotModel
            {
                TimeSlotType = TimeSlotType.Control
            };
            var convertedEntity = unitUnderTest.ToEntity();

            Assert.IsType <ControlTimeSlot>(convertedEntity);
        }
        public IHttpActionResult Post([FromBody] TimeSlotModel model)
        {
            var result = PerformAction <SetOpeningHours, TimeSlot>(new SetOpeningHours(model.ToEntity()));

            return(new ActionResultToCreatedHttpActionResult <TimeSlot, TimeSlotModel>(result, x => x.ToModel(), this)
                   .Do());
        }