public IActionResult Update(UpdateAddressDto updateAddressDto) { try { var addressDto = _addresService.Update(updateAddressDto); return(Ok(addressDto)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public GetAddressDto Update(UpdateAddressDto addressDto) { var addressInDb = _unitOfWork.AddressRepository.Get(addressDto.Id); if (addressInDb == null) { throw new Exception("Not Found"); } addressInDb.AddressDescription = addressDto.AddressDescription; _unitOfWork.AddressRepository.Update(addressInDb); _unitOfWork.SaveChanges(); return(_mapper.Map <GetAddressDto>(addressInDb)); }
[HttpPatch("update/employeePI/address/{addressId:int}", Name = "UpdateEmployeeAddress")] //Update employee address public IActionResult UpdateEmployeeAddress(int addressId, [FromBody] UpdateAddressDto updateAddressDto) { if (updateAddressDto == null || addressId != updateAddressDto.Id) { return(BadRequest(ModelState)); } var addressObj = _mapper.Map <Address>(updateAddressDto); if (!_npRepo.UpdateEmployeeAddress(addressObj)) { ModelState.AddModelError("", $"Something went wrong when updating the record {addressObj.Id}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public async Task <int> Update(int id, UpdateAddressDto dto, string userId) { var oldAddress = await _dbContext.Address.SingleOrDefaultAsync(x => x.Id == id); if (oldAddress == null) { throw _notFoundException; } if (id != dto.Id) { throw new UpdateEntityException(ExceptionMessage.UpdateEntityIdError); } var updatedAddress = _mapper.Map(dto, oldAddress); updatedAddress.UpdatedAt = DateTime.Now; updatedAddress.UpdatedBy = userId; _dbContext.Address.Update(updatedAddress); await _dbContext.SaveChangesAsync(); return(updatedAddress.Id); }
public async Task <IActionResult> Update(int id, [FromBody] UpdateAddressDto dto) => await GetResponse(async() => new ApiResponseViewModel(true, "Address Updated Successfully", await _addressService.Update(id, dto, UserId)));