Пример #1
0
        public async Task <IActionResult> UpdateOwner(int id, [FromBody] OwnerForUpdateDTO owner)
        {
            try
            {
                if (owner == null)
                {
                    _logger.LogError("Owner object sent from client is null");
                    return(BadRequest("Owner object is empty"));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid owner object  sent from client");
                    return(BadRequest("Invalid owner object "));
                }
                var ownerEntity = await _repoWrapper.Owner.GetOwnerById(id);

                if (ownerEntity == null)
                {
                    _logger.LogError($"Owner with id: {id}, hasn't been found in db.");
                    return(NotFound());
                }
                _mapper.Map(owner, ownerEntity);

                _repoWrapper.Owner.UpdateOwner(ownerEntity);
                await _repoWrapper.SaveAsync();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something wnet wrong inisde UpdateOwner action : {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
 public IActionResult UpdateOwner(Guid id, [FromBody] OwnerForUpdateDTO owner)
 {
     try
     {
         if (owner == null)
         {
             _logger.LogError($"Owner object that u input is null");
             return(BadRequest("Owner object is null "));
         }
         if (!ModelState.IsValid)
         {
             _logger.LogError("Invalid owner object sent from client");
             return(BadRequest("Invalid model object"));
         }
         var ownerEntity = _repository.Owner.GetOwnerById(id);
         if (ownerEntity == null)
         {
             _logger.LogError($"Owner id: {id} is not found in db");
             return(NotFound());
         }
         _mapper.Map(owner, ownerEntity);
         _repository.Owner.UpdateOwner(ownerEntity);
         _repository.Save();
         return(NoContent());
     }
     catch (Exception ex)
     {
         _logger.LogError($"There is something wrong with UpdateOwner {ex.Message}");
         return(StatusCode(500, "Internal Server Error"));
     }
 }
        public IActionResult UpdateOwner(Guid id, [FromBody] OwnerForUpdateDTO owner)
        {
            try
            {
                if (owner == null)
                {
                    _logger.LogError("Owner object from client is null");
                    return(BadRequest("Owner object is null"));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid owner from client.");
                    return(BadRequest("Inavalid model object"));
                }

                var ownerEntity = _repository.Owner.GetOwnerById(id);
                if (ownerEntity == null)
                {
                    _logger.LogError($"Owner with id: {id}, hasn't been found in the DB.");
                    return(NotFound());
                }

                _mapper.Map(owner, ownerEntity);

                _repository.Owner.UpdateOwner(ownerEntity);
                _repository.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateOwner action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }