public async Task <IActionResult> UpdateOwner(Guid id, [FromBody] OwnerForUpdateDto owner) { try { if (owner == 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 ownerEntity = await _repository.Owner.GetOwnerById(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(); return(NoContent()); } catch (Exception ex) { _logger.LogError($"Something went wrong inside 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 sent from ckient is null"); return(BadRequest("Owner object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid Object sent from client"); return(BadRequest("Invalid Model Object")); } var ownerEntity = _repository.Owner.GetOwnerById(id); if (ownerEntity == null) { _logger.LogError($"Owner id with : {id}, has not been found"); 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")); } }
public async Task <IActionResult> UpdateOwner(Guid id, [FromBody] OwnerForUpdateDto owner) { try { if (owner == 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")); } await _ownerService.UpdateOwnerAsync(id, owner); return(NoContent()); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdateOwner action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public async Task <IActionResult> UpdateOwner(Guid id, [FromBody] OwnerForUpdateDto owner) { if (owner == null) { _logger.LogInfo("Owner object sent from client is null."); return(BadRequest("Owner object is null")); } if (!ModelState.IsValid) { _logger.LogInfo("Invalid owner object sent from client."); return(BadRequest("Invalid model object")); } var ownerEntity = await _unitOfWork.Owner.GetOwnerByIdAsync(id); if (ownerEntity == null) { _logger.LogInfo($"Owner with id: {id}, hasn't been found in db."); return(NotFound()); } _mapper.Map(owner, ownerEntity); _unitOfWork.Owner.UpdateOwner(ownerEntity); await _unitOfWork.SaveAsync(); return(NoContent()); }
public IActionResult UpdateOwner(int ownerId, OwnerForUpdateDto owner) { var ownerFromRepo = _ownerRepository.GetOwner(ownerId); if (ownerFromRepo == null) { return(NotFound()); } _mapper.Map(owner, ownerFromRepo); _ownerRepository.UpdateOwner(ownerFromRepo); return(NoContent()); }
public async Task UpdateOwnerAsync(Guid id, OwnerForUpdateDto owner) { // Want to try to find the owner first before updating. Throw error if the owner does not exist. // What if the user attempts to modify the id field for the owner? Throw error. var ownerEntity = await GetOwnerByIdAsync(id); if (ownerEntity == null) { _logger.LogError($"Owner with id: {id}, hasn't been found in db."); return; // TODO: need to return notfound to the user } _mapper.Map(owner, ownerEntity); await _repositoryWrapper.Owner.UpdateOwnerAsync(ownerEntity); }
public async Task <IActionResult> UpdateOwner(Guid id, [FromBody] OwnerForUpdateDto owner) { if (owner == null) { return(BadRequest("Owner object is null")); } var ownerEntity = await _repositoryWrapper.Owner.GetOwnerByIdAsync(id); if (ownerEntity == null) { return(NotFound()); } _mapper.Map(owner, ownerEntity); _repositoryWrapper.Owner.UpdateOwner(ownerEntity); await _repositoryWrapper.SaveAsync(); return(NoContent()); }
public async Task <IActionResult> UpdateOwner(Guid id, [FromBody] OwnerForUpdateDto owner) { try { if (owner == null) { _logger.LogError("Tahsis boş gönderildi."); return(BadRequest("Owner object is null")); } if (!ModelState.IsValid) { _logger.LogError("Tahsis geçersiz gönderildi."); return(BadRequest("Geçersiz model")); } var ownerEntity = await _repository.Owner.GetOwnerByIdAsync(id); if (ownerEntity == null) { _logger.LogError($"Tahsis id'si bulunamadı: {id}."); return(NotFound()); } _mapper.Map(owner, ownerEntity); _repository.Owner.UpdateOwner(ownerEntity); await _repository.SaveAsync(); return(NoContent()); } catch (Exception ex) { _logger.LogError($"UpdateOwner action hata var: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public IActionResult UpdateOwner(long id, [FromBody] OwnerForUpdateDto ownerDto) { try { if (ownerDto == 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 ownerEntity = _repoWrapper.Owner.GetOwnerById(id); if (ownerEntity == null) { _logger.LogError($"Owner with id: {id}, hasn't been found in db."); return(NotFound()); } _mapper.Map(ownerDto, ownerEntity); _repoWrapper.Owner.UpdateOwner(ownerEntity); _repoWrapper.Save(); return(NoContent()); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdateOwner action: {ex.Message}"); return(StatusCode(500, ex.Message)); } }