Пример #1
0
        public async Task <IActionResult> DeleteAccommodationAsync([FromRoute] int id)
        {
            try
            {
                var accommodation = await _accommodationService.GetAccommodationAsync(id);

                if (!CorrectUserOrAdmin(accommodation.Owner.Id, GetIdOfLoggedInUser(HttpContext), GetUsertypeOfLoggedInUser(HttpContext)))
                {
                    return(BadRequest("Restricted acces, this action can only be done by administrator or owner of the accommodation!"));
                }

                await _deletionService.DeleteAccommodationAsync(id);

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