Ejemplo n.º 1
0
        public async Task <IActionResult> CreateImageAsync([FromBody] Image img)
        {
            if (!CorrectUserOrAdmin(img.Accommodation.Owner.Id, GetIdOfLoggedInUser(HttpContext), GetUsertypeOfLoggedInUser(HttpContext)))
            {
                return(BadRequest("Only the accommodation's owner or admin can upload photos to an accommodation!"));
            }

            try
            {
                var newImg = await _imageService.AddPictureAsync(img.Accommodation.Id, img.Img);

                return(CreatedAtAction(nameof(GetImageAsync), new { id = newImg.Id }, newImg));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }