public IActionResult UpdateAddress(Guid organizationId, Guid addressId, [FromBody] AddressForUpdateDto addressForUpdate) { if (organizationId == new Guid()) { return(BadRequest()); } if (addressId == new Guid()) { return(BadRequest()); } if (!_unitOfWork.Addresses.IsOrganizationExists(organizationId)) { return(NotFound()); } if (!_unitOfWork.Addresses.IsAddressExists(organizationId, addressId)) { return(NotFound()); } var addressFromContext = _unitOfWork.Addresses.GetAddress(organizationId, addressId); _mapper.Map(addressForUpdate, addressFromContext); if (!_unitOfWork.Complete()) { return(StatusCode(500, "A problem happened while handling your request!")); } return(NoContent()); }
public async Task <IActionResult> PutAddress([FromRoute] int id, [FromBody] AddressForUpdateDto addressForUpdateDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //if (id != address.Id) //{ // return BadRequest(); //} var address = await _repository.GetAsync(id); if (address == null) { return(NotFound()); } _mapper.Map(addressForUpdateDto, address); if (await _unitOfWork.SaveAsync()) { return(NoContent()); } throw new Exception($"Updating address {id} failed on save"); }
public async Task <IActionResult> UpdateAddress(int id, [FromBody] AddressForUpdateDto address) { var addressEntity = HttpContext.Items["entity"] as Address; _mapper.Map(address, addressEntity); _repository.Address.UpdateAddress(addressEntity); await _repository.SaveAsync(); return(NoContent()); }
public IActionResult UpdateAddress(Guid id, [FromBody] AddressForUpdateDto address) { try { if (id == null || address == null) { _logger.LogError("Address object sent from client is null."); return(BadRequest("Address object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid address object sent from client."); return(BadRequest("Invalid model object")); } var addressEntity = _repository.Address.GetAddressById(id); if (addressEntity == null) { _logger.LogError($"Address with id: {id}, hasn't been found in db."); return(NotFound()); } if (IsAddressAdded(address.Id, address.Title, address.PersonId)) { _logger.LogError($"Address with title: {address.Title} added before to person Id: {address.PersonId}."); return(BadRequest($"Address added before to person Id: {address.PersonId}")); } _mapper.Map(address, addressEntity); _repository.Address.UpdateAddress(addressEntity); _repository.Save(); return(NoContent()); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdateAddress action: {ex.Message}"); if (ex.InnerException != null) { _logger.LogError($"Inner Exception: {ex.InnerException.Message}"); } return(StatusCode(500, "Internal server error")); } }
public async Task <IActionResult> UpdateAddress(int id, [FromBody] AddressForUpdateDto address) { try { //int? landlordId = await _repositoryWrapper.Landlord.FindLandlordIdByAddressId(id); //if(HttpContext.SelectLoggedUserId() != landlordId/* && landlordId != null*/) //{ // return Unauthorized(); //} if (address == null) { _logger.LogError("Address received is a Null Object."); return(BadRequest("Address object is null. Please send full request.")); } if (!ModelState.IsValid) { _logger.LogError("Invalid Address object sent from client."); return(BadRequest("Address object is not Valid")); } var addressEntity = await _repositoryWrapper.Address.GetAddressById(id); // Sprawdź czy taki Address istnieje zanim updejtujesz if (addressEntity == null) { _logger.LogError($"Address with id: {id}, hasn't been found in db."); return(NotFound()); } _mapper.Map(address, addressEntity); _repositoryWrapper.Address.UpdateAddress(addressEntity); await _repositoryWrapper.Save(); return(NoContent()); } catch (Exception e) { _logger.LogError($"Something went wrong inside UpdateAddress(id, address) action: {e.Message}"); return(StatusCode(500, e.Message)); } }
public ResponseObject <AddressForGetDto> Update(AddressForUpdateDto addressForUpdateDto) { throw new System.NotImplementedException(); }