コード例 #1
0
 public IActionResult UpdateOwner(Guid id, [FromBody] OwnerUpdateDto ownerUpdateDto)
 {
     try
     {
         if (ownerUpdateDto == null)
         {
             _logger.LogError("Owner object sent from client 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 owner = _repository.Owner.GetOwnerById(id);
         if (owner == null)
         {
             _logger.LogError($"Owner with id: {id}, hasn't been found in db.");
             return(NotFound());
         }
         _mapper.Map(ownerUpdateDto, owner);
         _repository.Owner.UpdateOwner(owner);
         _repository.Commit();
         return(NoContent()); // return 204
     }
     catch (Exception ex)
     {
         _logger.LogError($"Something went wrong inside UpdateOwner action: {ex.Message}");
         return(StatusCode(500, "Internal server error"));
     }
 }
コード例 #2
0
        public void UpdateOwner(int IdName, OwnerUpdateDto owner)
        {
            var updateOwner = _Context.Owners.Where(c => c.Id == IdName).FirstOrDefault();

            _Context.Entry(updateOwner).CurrentValues.SetValues(owner);
            Save();
        }
コード例 #3
0
        public async Task <IActionResult> UpdateOwner(Guid id, [FromBody] OwnerUpdateDto owner)
        {
            var ownerEntity = await _repository.Owner.GetOwnerByIdAsync(id);

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

                return(NotFound());
            }

            _mapper.Map(owner, ownerEntity);

            _repository.Owner.UpdateOwner(ownerEntity);

            await _repository.SaveAsync();

            var updatedOwner = _mapper.Map <OwnerDto>(ownerEntity);

            return(Ok(updatedOwner));
        }
コード例 #4
0
 public IActionResult OwnerUpdate(int Id, [FromBody] OwnerUpdateDto ownerUpdateDto)
 {
     _OwnerRepos.UpdateOwner(Id, ownerUpdateDto);
     return(Ok());
 }