Пример #1
0
        public async Task <IActionResult> DeleteBookingAsync([FromRoute] int id)
        {
            try
            {
                var booking = await _bookingService.GetBookingAsync(id);

                if (!CorrectUserOrOwnerOrAdmin(booking.Accommodation.Owner.Id, booking.BookedBy.Id, GetIdOfLoggedInUser(HttpContext), GetUsertypeOfLoggedInUser(HttpContext)))
                {
                    return(BadRequest("Restricted access, action can only be done by the booker, owner of the accommodation or admin!"));
                }

                await _deletionService.DeleteBookingAsync(id);

                return(NoContent());
            }
            catch (Exception ex)
            {
                if (ex.GetType().IsAssignableFrom(typeof(NotFoundException)))
                {
                    return(NotFound(ex.Message));
                }
                else
                {
                    return(BadRequest(ex.Message));
                }
            }
        }