public (int?, ApiError?) UpdateStock(ApiClient current_client, Guid car_id, int new_stock) { (var car, var maybe_error) = CheckAccess(current_client, car_id); if (maybe_error is ApiError error) { return(null, error); } // Always create a new object rather than updating the old // so there will be no partial updates in the car objects. var new_car = new Car { Make = car.Make, Model = car.Model, Year = car.Year, Stock = new_stock, Client = car.Client, Id = car.Id, UpdateCount = car.UpdateCount + 1 }; if (!_carsRepository.TryUpdate(car_id, new_car, car)) { return(null, ApiError.Conflict($"Car (ID {car_id}) has been updated by someone else")); } return(car.Stock, null); }