Exemplo n.º 1
0
        public async Task <IActionResult> UpdateAccommodationAsync([FromRoute] int id, Accommodation accommodation)
        {
            try
            {
                var acc = await _accommodationService.GetAccommodationAsync(id);

                var userType = GetUsertypeOfLoggedInUser(HttpContext);

                if (!CorrectUserOrAdmin(acc.Owner.Id, GetIdOfLoggedInUser(HttpContext), userType))
                {
                    return(BadRequest("Restricted access!"));
                }

                await _accommodationService.UpdateAccommodationAsync(id, accommodation);

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