public async Task <IResponse> UpdateAsync(UpdateShipperCommand request) { var shipperUpdate = await _dbContext.Shippers.FindAsync(request.Id); if (shipperUpdate == null) { //return new { error = "There is no shipper with that id" }; return(new NotFoundResponse()); } shipperUpdate.FirstName = request.FirstName; shipperUpdate.LastName = request.LastName; shipperUpdate.Address = request.Address; shipperUpdate.City = request.City; shipperUpdate.State = request.State; _dbContext.Shippers.Update(shipperUpdate); var result = await _dbContext.SaveChangesAsync() > 0; if (result) { await _cacheService .DeleteKeyAsync(RedisDefaultKeys.GetAllShippers); return(new OkResponse <string>()); } else { return(new BadResponse()); } }
public async Task <IActionResult> UpdateShipper(int id, [FromBody] UpdateShipperCommand command) { command.Id = id; var result = await _mediatr.Send(command); if (result is NotFoundResponse) { return(NotFound("There is no shipper with that id")); } else if (result is BadResponse) { return(BadRequest()); } else { return(Ok()); } }