Beispiel #1
0
        public async Task <IActionResult> PutVehicleAsync(VehicleUpdateRequest vehicle)
        {
            var result = await vehicleProvider.PutVehicleAsync(vehicle);

            if (result.IsSuccess)
            {
                return(Ok(result.Vehicle));
            }
            return(NotFound());
        }
Beispiel #2
0
        public ActionResult <VehicleResponse> UpdateVehicle(int id, VehicleUpdateRequest request)
        {
            var cityToUpdate = _vehicleRepository.FindVehicleById(id);

            if (cityToUpdate == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var result = _vehicleRepository.UpdateVehicle(id, request);

            return(Ok(result));
        }
Beispiel #3
0
 public VehicleUpdateResponse UpdateVehicle(VehicleUpdateRequest query)
 {
     return(this.SubmitRequest <VehicleUpdateResponse>(query));
 }
Beispiel #4
0
        public async Task <(bool IsSuccess, Models.ViewModels.Vehicle Vehicle, string ErrorMessage)> PutVehicleAsync(VehicleUpdateRequest vehicle)
        {
            try
            {
                var entity = await dBContext.Vehicles.FirstOrDefaultAsync(v => v.ID == vehicle.ID);

                if (entity != null)
                {
                    entity.CarModelID   = vehicle.CarModelID;
                    entity.LicensePlate = string.IsNullOrEmpty(vehicle.LicensePlate) ? entity.LicensePlate : vehicle.LicensePlate;
                    entity.ModelYear    = vehicle.ModelYear;

                    dBContext.Update(entity);

                    if (await dBContext.SaveChangesAsync() > 0)
                    {
                        entity = await dBContext.Vehicles.Include(m => m.CarModel).Include(m => m.CarModel.Make).Include(m => m.CarModel.VehicleCategory).Include(c => c.CarModel.FuelType).FirstOrDefaultAsync(v => v.ID == entity.ID);

                        var result = mapper.Map <DB.Vehicle, Models.ViewModels.Vehicle>(entity);
                        return(true, result, null);
                    }
                    return(false, null, "Failed to update record.");
                }
                return(false, null, "Montadora não encontrada.");
            }
            catch (Exception ex)
            {
                logger?.LogError(ex.ToString());
                return(false, null, ex.Message);
            }
        }