Example #1
0
        public async Task SaveCarModelWithImagesTest()
        {
            var carModel = new CarModel
            {
                Description      = "Description",
                Kilometers       = 1000,
                PurchaseDate     = new DateTime(2019, 12, 10),
                PurchasePrice    = 2000,
                LotDate          = new DateTime(2019, 12, 12),
                Make             = "Make",
                Model            = "Model",
                Trim             = "Trim",
                SellingPrice     = 4000,
                Vin              = "11111111111111111",
                ShowCase         = false,
                Year             = 2005,
                TransmissionType = Core.Enums.TransmissionType.Automatic
            };

            await _carModelService.SaveCarModelAsync(carModel, new string[] { _jObject1.ToString() });

            var savedCar = (await _carRepository.GetAllAsync(includeProperties: "ThumbnailImage,Images")).Last();

            Assert.Equal(carModel.Description, savedCar.Description);
            Assert.Equal(carModel.Kilometers, savedCar.Kilometers);
            Assert.Equal(carModel.PurchaseDate, savedCar.PurchaseDate);
            Assert.Equal(carModel.PurchasePrice, savedCar.PurchasePrice);
            Assert.Equal(carModel.LotDate, savedCar.LotDate);
            Assert.Equal(carModel.Make, savedCar.Make);
            Assert.Equal(carModel.Model, savedCar.Model);
            Assert.Equal(carModel.Trim, savedCar.Trim);
            Assert.Equal(carModel.SellingPrice, savedCar.SellingPrice);
            Assert.Equal(carModel.Vin, savedCar.Vin);
            Assert.Equal(carModel.ShowCase, savedCar.ShowCase);
            Assert.Equal(carModel.Year, savedCar.Year);
            Assert.Equal(carModel.TransmissionType, savedCar.TransmissionType);
            Assert.NotNull(savedCar.ThumbnailImage);
            Assert.Single(savedCar.Images);
        }
Example #2
0
        private async Task <IActionResult> SaveCar(CarModel carModel, string redirectAction)
        {
            List <string> imageErrors = new List <string>();

            if (Request != null)
            {
                imageErrors.AddRange(_carModelService.ValidateCarImages(Request.Form["images"]));
            }

            foreach (string error in imageErrors)
            {
                ModelState.AddModelError("", error);
            }

            if (!ModelState.IsValid)
            {
                return(View(carModel));
            }

            await _carModelService.SaveCarModelAsync(carModel, Request == null?new List <string>() : Request.Form["images"].ToList());

            return(RedirectToAction(redirectAction).WithSuccess("Success", "Successfully saved Car."));
        }