public async Task <BookingResponse> CreateInView(BookingDTO newBooking, Guid viewId) { var isAdmin = _aadService.IsAdmin(); var booking = BookingMapper.Map(newBooking); if (!await _itemRepository.CheckIfAvailableToBook(booking)) { string errorMessage = "Too many concurrent bookings"; Log.Error(errorMessage); return(new BookingResponse(errorMessage)); } if (!isAdmin && !_viewRepository.CheckIfAllowedToBook(booking.ItemId, viewId)) { string errorMessage = $"Item {booking.Item.Name} can't be booked."; Log.Error(errorMessage); return(new BookingResponse(errorMessage)); } try { await _bookingRepository.Create(booking); await _context.SaveChangesAsync(); var showNames = _aadService.IsAdmin() || _viewRepository.GetShowNamesById(viewId); return(new BookingResponse(BookingMapper.Map(booking, showNames))); } catch (Exception ex) { string errorMessage = $"An error occured when creating the booking: {ex.Message}"; Log.Error <string>(ex, "An error occured when creating the booking: {booking}", JsonSerializer.Serialize(booking)); return(new BookingResponse(errorMessage)); } }
public async Task UpdateStatus(Guid id, BookingState newStatus, string declineReason) { var bookingRequest = await GetById(id); if (newStatus == BookingState.Approved) { var booking = BookingMapper.Map(bookingRequest); await _bookingRepository.Create(booking); } else { bookingRequest.DeclineReason = declineReason; } bookingRequest.Status = newStatus; _repository.Update(bookingRequest); await _context.SaveChangesAsync(); }
public async Task <IActionResult> Update([FromBody] BookingModel data) { var dataUpdate = await _bookingService.Update(BookingMapper.Map(data)); return(Ok()); }
public async Task <IActionResult> Add([FromBody] BookingModel data) { var dataEntity = await _bookingService.Add(BookingMapper.Map(data)); return(Ok(dataEntity)); }
public async Task <Booking> UpdateBooking(Booking booking) { var updated = await _bookinRepository.Update(BookingMapper.Map(booking)); return(BookingMapper.Map(updated)); }
public async Task <Booking> AddBooking(Booking booking) { var addedEntity = await _bookinRepository.Add(BookingMapper.Map(booking)); return(BookingMapper.Map(addedEntity)); }
public async Task <Booking> GetBooking(int id) { var entity = await _bookinRepository.Get(id); return(BookingMapper.Map(entity)); }
public async Task <IActionResult> UpdateBooking([FromBody] BookingModel booking) { var updatedBooking = await _bookingService.UpdateBooking(BookingMapper.Map(booking)); return(Ok(updatedBooking)); }
public async Task <IActionResult> AddBooking([FromBody] BookingModel booking) { var newBooking = await _bookingService.AddBooking(BookingMapper.Map(booking)); return(Ok(newBooking)); }
public async Task <IEnumerable <BookingDTO> > GetByView(Guid viewId) { var showNames = _aadService.IsAdmin() || _viewRepository.GetShowNamesById(viewId); return((await _bookingRepository.GetByView(viewId)).Select(booking => BookingMapper.Map(booking, showNames))); }
public async Task <IEnumerable <BookingDTO> > GetByCategory(Guid id) { return((await _bookingRepository.GetByCategory(id)).Select(booking => BookingMapper.Map(booking)).ToList()); }
public async Task <Booking> Update(Booking booking) { var data = await _bookingRepository.Update(BookingMapper.Map(booking)); return(booking); }
public async Task <Booking> Get(int id) { var data = await _bookingRepository.Get(id); return(BookingMapper.Map(data)); }