Beispiel #1
0
        public async Task UpdateAsync(int id, EditCarInputModel model)
        {
            var car = this.carsRepository.All().FirstOrDefault(c => c.Id == id);

            car.Title           = model.Title;
            car.Price           = model.Price;
            car.Milage          = model.Milage;
            car.ManufactureDate = model.ManufactureDate;
            car.MakeId          = model.MakeId;
            car.ModelId         = model.ModelId;
            car.Description     = model.Description;
            car.ColorId         = model.ColorId;
            car.CoupeId         = model.CoupeId;
            car.TechDataUrl     = model.TechDataUrl;
            car.ConditionId     = model.ConditionId;
            car.GearBoxId       = model.GearBoxId;
            car.RegionId        = model.RegionId;
            car.TownId          = model.TownId;
            car.FuelId          = model.FuelId;
            car.HorsePower      = model.HorsePower;

            await this.carsRepository.SaveChangesAsync();

            //Color,coupe,techData,ConditionId,GearBoxId,RegionId,TownId,FuelId,HorsePower,
        }
Beispiel #2
0
        public async Task <IActionResult> EditCar(int id, EditCarInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.Categories = this.categoriesService.AllCategories();
                return(this.View(input));
            }

            await this.carsService.EditCarAsync(id, input);

            return(this.RedirectToAction(nameof(this.SingleCar), new { id }));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, EditCarInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                await this.carsService.AddAllSelectListValuesForCarEditInputModel(model);

                return(this.View(model));
            }

            await this.carsService.UpdateAsync(id, model);

            return(this.RedirectToAction(nameof(this.ById), new { id }));
        }
Beispiel #4
0
        public void Edit_WithValidCarObject_ReturnsCar()
        {
            var car = new Car()
            {
                Id           = 1,
                CarModel     = "testModel",
                ImageUrl     = "testUrl",
                Make         = "testMake",
                Owner        = new School(),
                OwnerId      = 1,
                Transmission = Transmission.Authomatic,
                VIN          = "77777",
                InUse        = true
            };
            var returnValue = new List <Car>()
            {
                car
            };

            this.repository.Setup(r => r.All()).Returns(returnValue.AsQueryable);

            this.repository.Setup(r => r.Update(car)).Callback(() => new Car()
            {
                Id           = 1,
                CarModel     = "testModel",
                ImageUrl     = "testUrl",
                Make         = "testMake",
                Owner        = new School(),
                OwnerId      = 1,
                Transmission = Transmission.Authomatic,
                VIN          = "AA1111AA",
                InUse        = true
            });

            var model = new EditCarInputModel()
            {
                Id       = 1,
                ImageUrl = "testUrlNew",
                VIN      = "AA1111AA",
                InUse    = false
            };
            var result = this.carService.Edit(model).GetAwaiter().GetResult();

            Assert.That(result.VIN, Is.EqualTo("AA1111AA"));
            Assert.That(result.ImageUrl, Is.EqualTo("testUrl"));
            Assert.That(result.InUse, Is.EqualTo(false));
            Assert.That(result.Id, Is.EqualTo(1));

            Assert.That(result.CarModel, Is.EqualTo("testModel"));
            Assert.That(result, Is.TypeOf <Car>());
        }
Beispiel #5
0
        public async Task EditCarAsync(int id, EditCarInputModel input)
        {
            var car = this.carRepository.All().FirstOrDefault(x => x.Id == id);

            car.Model                = input.Model;
            car.DateOfManufacture    = input.DateOfManufacture;
            car.Prize                = input.Prize;
            car.Power                = input.Power;
            car.Miles                = input.Miles;
            car.Collor               = input.Collor;
            car.EngineType           = input.EngineTypes;
            car.TransmissionType     = input.TransmissionTypes;
            car.AditionalInformation = input.AditionalInformation;
            car.CategoryId           = input.CategoryId;
            await this.carRepository.SaveChangesAsync();
        }
Beispiel #6
0
        public void Edit_WithEmptyImageFile_ThrowsException()
        {
            var car = new Car()
            {
                Id           = 1,
                CarModel     = "testModel",
                ImageUrl     = "testUrl",
                Make         = "testMake",
                Owner        = new School(),
                OwnerId      = 1,
                Transmission = Transmission.Authomatic,
                VIN          = "77777",
                InUse        = true
            };
            var returnValue = new List <Car>()
            {
                car
            };

            this.repository.Setup(r => r.All()).Returns(returnValue.AsQueryable);

            this.repository.Setup(r => r.Update(car)).Callback(() => new Car()
            {
                Id           = 1,
                CarModel     = "testModel",
                ImageUrl     = "testUrl",
                Make         = "testMake",
                Owner        = new School(),
                OwnerId      = 1,
                Transmission = Transmission.Authomatic,
                VIN          = "AA1111AA",
                InUse        = true
            });

            var fileformMock = new Mock <IFormFile>();
            var model        = new EditCarInputModel()
            {
                Id       = 1,
                ImageUrl = "testUrlNew",
                VIN      = "AA1111AA",
                InUse    = false,
                CarImage = fileformMock.Object
            };

            Assert.That(() => this.carService.Edit(model).GetAwaiter().GetResult(), Throws.Exception);
        }
Beispiel #7
0
        // TODO: REFACTOR

        public async Task AddAllSelectListValuesForCarEditInputModel(EditCarInputModel input)
        {
            input.MakesItems = await this.makeService.GetAllMakes();

            input.Colors = await this.colorService.GetAllColors();

            input.CoupeTypes = await this.coupesService.GetAllCoupes();

            input.Conditions = await this.conditionsService.GetAllConditionsAsync();

            input.GearBoxes = await this.gearBoxesService.GetAllGearBoxesAsync();

            input.Regions = await this.regionsServices.GetAllRegionsAsync();

            input.Fuels = await this.fuelsServices.GetAllFuelTypesAsync();

            // input.Additions = this.additionsService.GetAllAditions();
        }
Beispiel #8
0
        public void Edit_CarObjectDoNotExistInDb_ThrowsException()
        {
            var car = new Car()
            {
                Id           = 1,
                CarModel     = "testModel",
                ImageUrl     = "testUrl",
                Make         = "testMake",
                Owner        = new School(),
                OwnerId      = 1,
                Transmission = Transmission.Authomatic,
                VIN          = "77777",
                InUse        = true
            };
            var returnValue = new List <Car>()
            {
                car
            };

            this.repository.Setup(r => r.All()).Returns(returnValue.AsQueryable);

            this.repository.Setup(r => r.Update(car)).Callback(() => new Car()
            {
                Id           = 1,
                CarModel     = "testModel",
                ImageUrl     = "testUrl",
                Make         = "testMake",
                Owner        = new School(),
                OwnerId      = 1,
                Transmission = Transmission.Authomatic,
                VIN          = "AA1111AA",
                InUse        = true
            });

            var model = new EditCarInputModel()
            {
                Id       = 2,
                ImageUrl = "testUrl",
                VIN      = "AA1111AA",
                InUse    = true
            };

            Assert.That(() => this.carService.Edit(model).GetAwaiter().GetResult(), Throws.ArgumentException);
        }
Beispiel #9
0
        public ActionResult Edit(EditCarInputModel model)
        {
            try
            {
                if (!this.ModelState.IsValid)
                {
                    return(this.View(model));
                }

                if (!this.HasRights(model.Id))
                {
                    throw new OperationCanceledException(GlobalDataConstants.NoRights);
                }

                var car = this.carService.Edit(model).GetAwaiter().GetResult();

                return(this.RedirectToAction("Details", "Cars", new { id = car.Id }));
            }
            catch (Exception e)
            {
                return(this.View("_Error", e.Message));
            }
        }
Beispiel #10
0
        public async Task <Car> UpdateCarAsync(int id, EditCarInputModel input)
        {
            var carDb = this.carsRepository.All().First(x => x.Id == id);

            carDb.CategoryId      = input.CategoryId;
            carDb.ColorId         = input.ColorId;
            carDb.Doors           = input.Doors;
            carDb.EngineSize      = input.EngineSize;
            carDb.EuroStandartId  = input.EuroStandartId;
            carDb.FuelTypeId      = input.FuelTypeId;
            carDb.GearboxId       = input.GearboxId;
            carDb.HorsePower      = input.HorsePower;
            carDb.MakeId          = input.MakeId;
            carDb.ManufactureDate = input.ManufactureDate;
            carDb.Mileage         = input.Mileage;
            carDb.ModelId         = input.ModelId;
            carDb.ModifiedOn      = DateTime.UtcNow;
            carDb.Seats           = input.Seats;
            carDb.State           = input.State;

            await this.carsRepository.SaveChangesAsync();

            return(carDb);
        }
Beispiel #11
0
        public async Task <Car> Edit(EditCarInputModel model)
        {
            //todo check model validation in controller?!?
            //todo change inUse, Image, VIN
            var car = this.GetCarById(model.Id);

            car.InUse = model.InUse;
            car.VIN   = model.VIN;

            var name    = car.Owner.TradeMark + model.VIN;
            var account = Helpers.SetCloudinary();

            if (model.CarImage != null)
            {
                var imageUrl = await Helpers.UploadImage(account, model.CarImage, name);

                car.ImageUrl = imageUrl;
            }

            this.carRepository.Update(car);
            await this.carRepository.SaveChangesAsync();

            return(car);
        }
        public ActionResult EditCar(EditCarInputModel model)
        {
            if (this.User.Identity.GetUserName() != model.BaseModel.CurrentUsername)
            {
                throw new Exception("Not auhtorized.");
            }

            if (!this.ModelState.IsValid)
            {
                return this.View("~/Areas/UserProfile/Views/Profile/EditCar.cshtml", model);
            }

            this.carServices.Update(
                this.User.Identity.GetUserId(),
                model.Brand,
                model.CarModel,
                model.Color,
                model.Year,
                model.TotalSeats,
                model.SpaceForLugage,
                model.Description);

            return this.RedirectToAction("Car", new { username = model.BaseModel.CurrentUsername });
        }