Пример #1
0
        public async Task <IActionResult> UpdateBill(int id, int userId, PhotoForUpdateDto billForUpdate)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(id);

            _mapper.Map(billForUpdate, photoFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating bill {id} failed on save");
        }
Пример #2
0
        public async Task <IActionResult> UpdatePhoto(int id, [FromBody] PhotoForUpdateDto photo)
        {
            try
            {
                if (photo == null)
                {
                    _logger.LogError("Photo received is a Null Object.");
                    return(BadRequest("Photo object is null. Please send full request."));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid Photo object sent from client.");
                    return(BadRequest("Photo object is not Valid"));
                }

                var photoEntity = await _repositoryWrapper.Photo.GetPhotoById(id);

                if (photoEntity == null)
                {
                    _logger.LogError($"Photo with id: {id}, hasn't been found in db.");
                    return(NotFound());
                }

                _mapper.Map(photo, photoEntity);
                _repositoryWrapper.Photo.UpdatePhoto(photoEntity);

                await _repositoryWrapper.Save();

                return(NoContent());
            }
            catch (Exception e)
            {
                _logger.LogError($"Something went wrong inside UpdatePhoto(id, photoForUpdateDto) action: {e.Message}");
                return(StatusCode(500, e.Message));
            }
        }