Beispiel #1
0
        public void GivenAValidTeacherAvailabilityIsReadyToBeSubmitted()
        {
            var availability        = new TimeSlotModel(IsoDayOfWeek.Monday, new LocalTimeModel(10, 0), new LocalTimeModel(22, 30));
            var teacherAvailability = new TeacherAvailabilityModel(availability.PutIntoList());

            ScenarioCache.Store(ModelKeys.TeacherAvailability, teacherAvailability);
        }
Beispiel #2
0
        public async Task <bool> AddTimeSlotAsync(TimeSlotModel timeSlotModel)
        {
            _context.TimeSlot.Add(timeSlotModel);
            var saveResult = await _context.SaveChangesAsync();

            return(saveResult == 1);
        }
        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());
        }
        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"));
        }
Beispiel #5
0
 public static TimeSlot Map(TimeSlotModel timeslotModel)
 {
     return(new TimeSlot
     {
         Id = timeslotModel.Id,
         Name = timeslotModel.Name
     });
 }
Beispiel #6
0
        public void GivenAInvalidOpeningHourIsReadyToBeSubmitted()
        {
            var openingTime = new LocalTimeModel(10, 0);
            var closingTime = openingTime.PlusHours(-1);
            var openingHour = new TimeSlotModel(IsoDayOfWeek.Monday, openingTime, closingTime);

            ScenarioCache.Store(ModelKeys.OpeningHours, openingHour);
        }
Beispiel #7
0
 public static TimeSlotDto Map(TimeSlotModel timeslot)
 {
     return(new TimeSlotDto
     {
         Id = timeslot.Id,
         Name = timeslot.Name
     });
 }
Beispiel #8
0
        public void GivenOpeningHoursNeedToBeChanged()
        {
            var response     = ApiCaller.Get <List <TimeSlotModel> >(Routes.OpeningHours);
            var openingHours = response.Data.Single();

            var newOpeningHours = new TimeSlotModel(openingHours.Day, openingHours.OpeningTime.PlusHours(1), openingHours.ClosingTime.PlusHours(1));

            ScenarioCache.Store(ModelKeys.OpeningHours, newOpeningHours);
        }
Beispiel #9
0
        public void ToEntity_Control_Success()
        {
            var unitUnderTest = new TimeSlotModel
            {
                TimeSlotType = TimeSlotType.Control
            };
            var convertedEntity = unitUnderTest.ToEntity();

            Assert.IsType <ControlTimeSlot>(convertedEntity);
        }
Beispiel #10
0
        public void ToEntity_Intervention_Success()
        {
            var unitUnderTest = new TimeSlotModel
            {
                TimeSlotType = TimeSlotType.Intervention
            };
            var convertedEntity = unitUnderTest.ToEntity();

            Assert.IsType <InterventionTimeSlot>(convertedEntity);
        }
        public async Task <IActionResult> AddTimeSlot(TimeSlotBindingModel timeSlotBindingModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var startTime = DateTime.Parse(timeSlotBindingModel.StartTime);
            var endTime   = DateTime.Parse(timeSlotBindingModel.EndTime);
            var isValid   = await _timeSlotService.AreStartTimeAndEndTimeLegal(startTime, endTime);

            if (!isValid)
            {
                return(BadRequest("The time slot is invalid"));
            }

            var timeSlot = await _timeSlotService.GetTimeSlotByTimeAsync(startTime, endTime);

            if (timeSlot != null)
            {
                return(BadRequest("The time slot is already taken"));
            }

            var roomModel = await _roomService.GetRoomByIdAsync(timeSlotBindingModel.RoomId);

            if (roomModel == null)
            {
                return(BadRequest("Could not find the room."));
            }

            var sessionModel = await _sessionService.GetSessionByIdAsync(timeSlotBindingModel.SessionId);

            if (sessionModel == null)
            {
                return(BadRequest("Could not find the session"));
            }

            var timeSlotModel = new TimeSlotModel
            {
                StartTime    = startTime,
                EndTime      = endTime,
                RoomModel    = roomModel,
                SessionModel = sessionModel
            };
            var successful = await _timeSlotService.AddTimeSlotAsync(timeSlotModel);

            if (!successful)
            {
                return(BadRequest("Could not add the time slot"));
            }

            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// Converts TimeSlotModel to TimeSlot
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns></returns>
        public static TimeSlot ToEntity(this TimeSlotModel instance)
        {
            if (instance.IsNull())
            {
                return(null);
            }

            return(new TimeSlot
            {
                Day = instance.Day,
                OpeningTime = instance.OpeningTime.ToEntity(),
                ClosingTime = instance.ClosingTime.ToEntity()
            });
        }
Beispiel #13
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TimeSlotModel = await _context.TimeSlotModel.FirstOrDefaultAsync(m => m.Id == id);

            if (TimeSlotModel == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Beispiel #14
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TimeSlotModel = await _context.TimeSlotModel.FindAsync(id);

            if (TimeSlotModel != null)
            {
                _context.TimeSlotModel.Remove(TimeSlotModel);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public static TimeSlotModel ToTimeSlotDetailsModel(this V_TIMESLOT_DETAILS model)
        {
            int slotAppCount = Convert.ToInt16(ConfigurationManager.AppSettings.Get("AppointSlotCount").ToString());

            if (model == null)
            {
                return(null);
            }
            var row = new TimeSlotModel();

            {
                //row.TimeSlotID = model.TIMESLOT_ID;
                row.TimeSlot_Category    = model.TIMESLOT_CATEGORY;
                row.TimeSlot_Description = model.TIMESLOT_DESC;
                row.TimeSlot_WeekDay     = model.TIMESLOT_WEEKDAY;
                row.IsTimeSlotAvailable  = model.App_cnt >= slotAppCount ? false : true;
                // row.Slot_Start_Time = model.SLOT_START_TIME.ToString();
                //row.Slot_End_Time = model.SLOT_END_TIME.ToString();
            }
            return(row);
        }
 public static string CheckTimeSlot(DateTime date, string times, int placeId)
 {
     using (UserContext dbUse = new UserContext())
     {
         try
         {
             TimeSlotModel model = dbUse.TimeSlotModels.FirstOrDefault(t => t.PlaceId == placeId && t.Date == date && t.Time == times);
             if (model == null)
             {
                 return("0");
             }
             else
             {
                 return("1");
             }
         }
         catch (Exception e)
         {
             return(e.ToString());
         }
     }
 }
        public static TimeSlotModel ToTimeSlotModel(this APS_TIMESLOT model)
        {
            if (model == null)
            {
                return(null);
            }
            var row = new TimeSlotModel();

            {
                // row.TimeSlotID = model.TIMESLOT_ID;
                row.TimeSlot_Category    = model.TIMESLOT_CATEGORY;
                row.TimeSlot_Description = model.TIMESLOT_DESC;
                row.TimeSlot_WeekDay     = model.TIMESLOT_WEEKDAY;
                //row.Slot_Start_Time = model.SLOT_START_TIME.ToString("hh:mm");
                //row.Slot_End_Time = model.SLOT_END_TIME.ToString("hh:mm");
                row.CreatedBy       = model.CREATED_BY;
                row.CreatedTime     = model.CREATED_TIME;
                row.LastUpdatedBy   = model.LAST_UPDATED_BY;
                row.LastUpdatedTime = model.LAST_UPDATED_TIME;
            }
            return(row);
        }
 public VerifyOpeningHoursProperties(TimeSlotModel expected, TimeSlotModel actual)
 {
     _expected = expected;
     _actual   = actual;
 }
 public IActionResult TryScheduleAsap(TimeSlotModel model)
 {
     return(ScheduleTimeSlot(model));
 }
Beispiel #20
0
        public void GivenAValidOpeningHourIsReadyToBeSubmitted()
        {
            var openingHour = new TimeSlotModel(IsoDayOfWeek.Monday, new LocalTimeModel(10, 0), new LocalTimeModel(22, 30));

            ScenarioCache.Store(ModelKeys.OpeningHours, openingHour);
        }