public async Task <ActionResult <UULResponse> > GetTimeSlots(int year, int month, int day) { UULResponse response; try { var rulesDto = await RulesDao.GetCurrentRulesDTOOrDefault(_context); if (rulesDto == null) { return(Error.RulesNotFound.CreateErrorResponse(_logger, "GetTimeSlots")); } DateOperations.GetTimeSlotsBoundsUtc(rulesDto.TimeSlotSpan, year, month, day, out DateTime start, out DateTime end); var slots = await TimeSlotsDao.GetTimeSlotsByUtcBounds(_context, start, end); var data = new ScheduleDTO() { Date = year + "/" + month + "/" + day, GymId = null, TimeSlots = slots }; response = new UULResponse() { Success = true, Message = year + "/" + month + "/" + day, Data = data }; } catch (Exception e) { response = Error.TimeSlotsGetFailed.CreateErrorResponse(_logger, "GetTimeSlots", e); } return(response); }
public static async Task <List <TimeSlot> > CreateTimeSlotsForDateUTC(UULContext context, DateTime dateUtc, int hourToStart) { var rules = await RulesDao.GetCurrentRulesOrDefault(context); DateOperations.GetTimeSlotsBoundsUtc(rules.TimeSlotSpan, dateUtc.Year, dateUtc.Month, dateUtc.Day, out DateTime start, out DateTime end); var existent = await TimeSlotsDao.GetTimeSlotsByUtcBounds(context, start, end); if (existent.Count != 0) { return(new List <TimeSlot>()); } var limit = dateUtc.AddDays(1); var slotStart = dateUtc.AddHours(hourToStart); var slots = new List <TimeSlot>(); var slotSpan = TimeSpan.FromMinutes(rules.TimeSlotSpan); while (slotStart.CompareTo(limit) < 0) { foreach (Gym gym in rules.Gyms) { var slot = new TimeSlot { Start = slotStart.ToUniversalTime(), End = (slotStart + slotSpan).ToUniversalTime(), Gym = gym }; slots.Add(slot); } slotStart += slotSpan; } return(slots); }