public async Task <IActionResult> UpdateVehicle(int vehicleId, [FromBody] VehicleToUpdate vehicleToUpdate) { Vehicle existingVehicle = await _vegaRepository.GetVehicle(vehicleId).FirstOrDefaultAsync(); if (existingVehicle == null) { return(NotFound($"Could not find vehicle with id: {vehicleId}")); } if (vehicleToUpdate == null) { throw new ArgumentNullException(nameof(vehicleToUpdate)); } if (string.IsNullOrEmpty(vehicleToUpdate.Brand) || string.IsNullOrEmpty(vehicleToUpdate.Model) || string.IsNullOrEmpty(vehicleToUpdate.Contact.ContactName) ) { return(Conflict($"missing required field")); } await UpdateVehicle(existingVehicle, vehicleToUpdate); return(Ok()); }
private async Task UpdateVehicle(Vehicle existingVehicle, VehicleToUpdate vehicleToUpdate) { existingVehicle.Photo = vehicleToUpdate.Photo; existingVehicle.Brand = vehicleToUpdate.Brand; existingVehicle.Model = vehicleToUpdate.Model; existingVehicle.Year = vehicleToUpdate.Year; existingVehicle.Price = vehicleToUpdate.Price; existingVehicle.LastUpdate = DateTime.Now; existingVehicle.Contact.ContactName = vehicleToUpdate.Contact.ContactName; existingVehicle.Contact.ContactEmail = vehicleToUpdate.Contact.ContactEmail; existingVehicle.Contact.ContactPhone = vehicleToUpdate.Contact.ContactPhone; await _vegaRepository.UpdateVehicle(existingVehicle); }