예제 #1
0
 private void AddSlotSearchQueryParams(MySqlCommand command, SlotSearchQuery query)
 {
     command.Parameters.AddWithValue("vUserEmail", query.UserEmail);
     command.Parameters.AddWithValue("vSlotDate", query.SlotDate);
     command.Parameters.AddWithValue("vStartTime", query.StartTime == DateTime.MinValue ? null : (DateTime?)query.StartTime);
     command.Parameters.AddWithValue("vEndTime", query.EndTime == DateTime.MinValue ? null : (DateTime?)query.EndTime);
 }
예제 #2
0
        public async Task <IEnumerable <Duration> > GetAvailableSlotDurationsAsync(SlotSearchQuery query)
        {
            ValidateSlotSearchQuery(query);
            IEnumerable <Duration> occupiedSlotDurations = await _slotRepository.GetOccupiedSlotDurations(query);

            return(ExcludeOccupiedSlotDurations(query.StartTime, query.EndTime, query.SlotDate, query.IntervalType, query.Interval, occupiedSlotDurations));
        }
예제 #3
0
 private void ValidateSlotSearchQuery(SlotSearchQuery query)
 {
     if (query == null)
     {
         throw new InvalidArgumentException(nameof(SlotSearchQuery), null, "non null query");
     }
     if (string.IsNullOrWhiteSpace(query.UserEmail))
     {
         throw new InvalidArgumentException(nameof(query.UserEmail), null, "non null/empty user email");
     }
     if (query.SlotDate == DateTime.MinValue)
     {
         throw new InvalidArgumentException(nameof(query.SlotDate), DateTime.MinValue.ToString(), "non null slot date");
     }
 }
예제 #4
0
        public async Task <IEnumerable <Duration> > GetOccupiedSlotDurations(SlotSearchQuery query)
        {
            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
            using (MySqlConnection connection = new MySqlConnection(_appSettings.ConnectionString))
            {
                await connection.OpenAsync();

                using (MySqlCommand command = new MySqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = Routines.GetOccupiedSlotDurations;

                    AddSlotSearchQueryParams(command, query);

                    using (MySqlDataReader reader = command.ExecuteReader())
                    {
                        return(await ReadOccupiedDurationsAsync(reader));
                    }
                }
            }
        }
예제 #5
0
 public async Task <ActionResult <IEnumerable <Duration> > > GetAvailableSlotDurationsAsync([FromBody] SlotSearchQuery query)
 {
     try
     {
         return(Ok(await _slotService.GetAvailableSlotDurationsAsync(query)));
     }
     catch (InvalidArgumentException ex)
     {
         return(BadRequest(new { message = ex.Message }));
     }
 }