コード例 #1
0
        //method
        //TODO: Mileage doesn't change... Move this method to carService

        public async Task EditCar(CarViewModel model, IEnumerable <ExtraCheckBox> extrasCB)
        {
            var realCar = await carService.GetCarAsync(model.Id).ConfigureAwait(false);

            var newBody = bodyTypeService.GetBodyType(model.BodyTypeId);

            var newBrand = brandService.GetBrand(model.BrandId);
            var newModel = brandService.GetModeldOfBrand(model.BrandId, model.CarModelId);

            var newColor = this.colorService.GetColor(model.Color, model.ColorTypeId);

            if (newColor == null)
            {
                newColor = this.colorService.AddColor(model.Color, model.ColorTypeId);
            }
            var newEngineCapacity = model.EngineCapacity;
            var newFuelType       = fuelTypeService.GetFuelType(model.FuelTypeId);
            var newGearbox        = this.gearTypeService.GetGearBox(model.GearBoxTypeId, model.NumberOfGears);
            var newHorsePower     = model.HorsePower;
            var newPrice          = model.Price;
            var newProductionDate = model.ProductionDate;

            realCar.BodyType       = newBody;
            realCar.BodyTypeId     = newBody.Id;
            realCar.Brand          = newBrand;
            realCar.BrandId        = newBrand.Id;
            realCar.Color          = newColor;
            realCar.ColorId        = newColor.Id;
            realCar.EngineCapacity = newEngineCapacity;
            realCar.FuelType       = newFuelType;
            realCar.FuelTypeId     = newFuelType.Id;
            realCar.GearBox        = newGearbox;
            realCar.GearBoxId      = newGearbox.Id;
            realCar.HorsePower     = newHorsePower;
            realCar.CarModelId     = newModel.Id;
            realCar.CarModel       = newModel;
            realCar.Price          = newPrice;
            realCar.ProductionDate = newProductionDate;
            realCar.ModifiedOn     = DateTime.Now;

            var newExtrasIds     = extrasCB.Where(e => e.Selected == true).Select(e => e.Id).ToList();
            var currentExtrasIds = extraService.GetExtrasForCar(model.Id).Select(e => e.Id).ToList();

            var extraIdsToDelete = currentExtrasIds.Except(newExtrasIds).ToList();

            this.extraService.DeleteExtrasFromCar(realCar, extraIdsToDelete);

            var extrasIdsToAdd = newExtrasIds.Except(currentExtrasIds).ToList();

            this.extraService.AddExtrasToCar(realCar, extrasIdsToAdd);

            carService.Update(realCar);
        }
コード例 #2
0
        //method
        public void EditCar(CarViewModel model)
        {
            var realCar = carService.GetCar(model.Id);

            var newBody  = bodyTypeService.GetBodyType(model.BodyTypeId);
            var newBrand = brandService.GetBrand(model.BrandId);
            var newModel = brandService.GetModeldOfBrand(model.BrandId, model.CarModelId);

            var newColor = this.colorService.GetColor(model.Color, model.ColorTypeId);

            if (newColor == null)
            {
                newColor = this.colorService.AddColor(model.Color, model.ColorTypeId);
            }
            var newEngineCapacity = model.EngineCapacity;
            var newFuelType       = fuelTypeService.GetFuelType(model.FuelTypeId);
            var newGearbox        = this.gearTypeService.GetGearBox(model.GearBoxTypeId, model.NumberOfGears);
            var newHorsePower     = model.HorsePower;
            var newPrice          = model.Price;
            var newProductionDate = model.ProductionDate;

            //    var newImageName = model.ImageUrl;

            realCar.BodyType       = newBody;
            realCar.BodyTypeId     = newBody.Id;
            realCar.Brand          = newBrand;
            realCar.BrandId        = newBrand.Id;
            realCar.Color          = newColor;
            realCar.ColorId        = newColor.Id;
            realCar.EngineCapacity = newEngineCapacity;
            realCar.FuelType       = newFuelType;
            realCar.FuelTypeId     = newFuelType.Id;
            realCar.GearBox        = newGearbox;
            realCar.GearBoxId      = newGearbox.Id;
            realCar.HorsePower     = newHorsePower;
            realCar.CarModelId     = newModel.Id;
            realCar.CarModel       = newModel;
            realCar.Price          = newPrice;
            realCar.ProductionDate = newProductionDate;
            realCar.ModifiedOn     = DateTime.Now;

            carService.Update(realCar);
        }