public async Task <BookingMonth> Find(BookingMonthId aggregateId) { var query = $@" SELECT id as Id, booking as Booking FROM laundry.bookings WHERE id = @id"; using (var connection = new NpgsqlConnection(_options.ConnectionString)) { var pgDocument = await connection.QuerySingleOrDefaultAsync <BookingMonthPostgresDocument>(query, new { id = aggregateId.Value }); if (pgDocument == null) { return(null); } var dataModel = JsonConvert.DeserializeObject <BookingMonthDataModel>(pgDocument.Booking); if (dataModel == null) { return(null); } var aggregate = BookingMonthMapper.From(dataModel); return(aggregate); } }
public async Task <IActionResult> PostBooking( [FromRoute] int year, [FromRoute] int month, [FromRoute] int day, [FromBody] BookingInputModel input) { var bookingMonthId = BookingMonthId.From(new DateTime(year, month, day)); var bookingMonth = await _repository.Find(bookingMonthId); if (bookingMonth == null) { bookingMonth = new BookingMonth(bookingMonthId, year, month, new Dictionary <int, BookingDay>()); } var userId = UserId.With(HttpContext.GetUserId().Value); var slot = (Slot)input.Slot; bookingMonth.AddBooking(userId, day, slot); await _repository.Upsert(bookingMonth); var responseModel = await _factory.From(bookingMonth.BookingDays[day].Bookings[slot], input.Slot); return(CreatedAtAction("GetBookingSlot", new { year = year, month = month, day = day, slot = input.Slot, }, responseModel)); }
public async Task <ActionResult <BookingMonthResponseModel> > GetBookings(int year, int month) { var bookingMonthId = BookingMonthId.From(new DateTime(year, month, 1)); var bookingMonth = await _repository.Find(bookingMonthId); if (bookingMonth == null) { return(NotFound()); } var responseModel = await _factory.From(bookingMonth); return(responseModel); }
public static BookingMonth From(BookingMonthDataModel dataModel) { if (dataModel == null) { return(null); } var aggregateId = BookingMonthId.With(dataModel.Id); return(new BookingMonth( aggregateId, dataModel.Year, dataModel.Month, From(dataModel.BookingDays))); }
public async Task <ActionResult <UserBookingResponseModel> > GetBookingSlot(int year, int month, int day, int slot) { var bookingMonthId = BookingMonthId.From(new DateTime(year, month, day)); var bookingMonth = await _repository.Find(bookingMonthId); if (bookingMonth == null) { return(NotFound()); } var slotEnum = (Slot)slot; if (bookingMonth.BookingDays.ContainsKey(day) && bookingMonth.BookingDays[day].Bookings.ContainsKey(slotEnum)) { return(await _factory.From(bookingMonth.BookingDays[day].Bookings[slotEnum], slot)); } return(NotFound()); }