public async Task EditAsync(EditCarViewModel carModel) { var car = AutoMapperConfig.MapperInstance.Map <Car>(carModel); this.carsRepository.Update(car); await this.carsRepository.SaveChangesAsync(); }
public IActionResult Edit(EditCarViewModel model) { if (ModelState.IsValid) { Car car = _carRepository.GetCar(model.Id); car.Name = model.Name; car.MinLeeftijd = model.MinLeeftijd; car.Prijs = model.Prijs; car.Kw = model.Kw; car.UpdateDate = DateTime.Now; if (model.Photo != null) { if (model.ExistingPhotoCar != null) { string filePath = Path.Combine(_webHostEnvironment.WebRootPath, "images", model.ExistingPhotoCar); System.IO.File.Delete(filePath); } car.PhotoCar = ProcessUploadFile(model); } _carRepository.Update(car); return(RedirectToAction("ListCars", "Cars")); } return(View()); }
public IActionResult Edit(int id_car) { Car car = _context.FindCar(id_car); byte[] bytes = Convert.FromBase64String(car.Image); var stream = new MemoryStream(bytes); IFormFile file = new FormFile(stream, 0, bytes.Length, "name", "fileName"); EditCarViewModel model = new EditCarViewModel { Id = car.Id, Mark = car.Mark, Model = car.Model, Color = car.Color, Goverment_number = car.Goverment_number, Year = car.Year, id_supplier = car.id_supplier, Price = car.Price, status = car.status, country = car.country, city = car.city, Image = file, }; if (AllMarks[0] == "Все") { AllMarks.RemoveAt(0); } ViewBag.Marks = new SelectList(AllMarks); return(View(model)); }
// GET: Cars/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var car = await _context.Car.FindAsync(id); EditCarViewModel editCar = new EditCarViewModel { Id = car.Id, Descripcion = car.Descripcion, Modelo = car.Modelo, Precio = car.Precio, Estado = car.Estado, Kilometros = car.Kilometros, ExistPathImg = car.PathImg, Marca = car.MarcaId }; editCar.Marcas = _context.Marca.Select(marca => new SelectListItem() { Value = marca.Id.ToString(), Text = marca.Nombre.ToString() }) .ToList(); if (car == null) { return(NotFound()); } return(View(editCar)); }
public IActionResult CreateCar(EditCarViewModel model) { var extrasIds = model.Extras.Where(e => e.Selected == true).Select(e => e.Id).ToList(); var car = this.carService.AddCar( model.Car.BrandId, model.Car.CarModelId, model.Car.Mileage, model.Car.HorsePower, model.Car.EngineCapacity, model.Car.ProductionDate, model.Car.Price, model.Car.BodyTypeId, model.Car.Color, model.Car.ColorTypeId, model.Car.FuelTypeId, model.Car.GearBoxTypeId, model.Car.NumberOfGears, extrasIds); if (model.Images != null) { foreach (var image in model.Images) { if (!this.IsValidImage(image)) { this.StatusMessage = "Error: Please provide a.jpg or .png file smaller than 5MB"; return(this.RedirectToAction(nameof(CreateCar))); } } this.carService.SaveImages( this.GetUploadsRoot(), model.Images.Select(i => i.FileName).ToList(), model.Images.Select(i => i.OpenReadStream()).ToList(), car.Id ); } this.StatusMessage = "Car registration is successful!"; return(RedirectToAction("Details", "Car", new { area = "", id = car.Id })); }
// GET: Customer/{customerId}/Car/{carId}/Edit public ActionResult Edit(int customerId, int carId) { var currentUser = manager.FindById(User.Identity.GetUserId()); var customer = customersRepo.GetCustomerById(customerId); Car car = carsRepo.GetCarByCustomerId(customerId, carId); if (car == null || car.User != currentUser) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var viewModel = new EditCarViewModel() { Manufacturer = car.Manufacturer, Model = car.Model, VIN = car.VIN, PlateCode = car.PlateCode, Year = car.Year, EngineCode = car.EngineCode, FuelType = car.FuelType }; ViewBag.customerId = customerId; ViewBag.CustomerName = customer.FirstName + " " + customer.LastName; return(View(viewModel)); }
public void TestSaveCommand() { Car car = new Car() { CarId = 1, Color = "White", Description = "Kia Optima", Year = 2013, RentalPrice = 149.00M }; Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>(); EditCarViewModel viewModel = new EditCarViewModel(mockServiceFactory.Object, car); mockServiceFactory.Setup(mock => mock.CreateClient <IInventoryService>().UpdateCar(It.IsAny <Car>())).Returns(viewModel.Car); viewModel.Car.Color = "Black"; bool carUpdated = false; string color = string.Empty; viewModel.CarUpdated += (s, e) => { carUpdated = true; color = e.Car.Color; }; viewModel.SaveCommand.Execute(null); Assert.IsTrue(carUpdated); Assert.IsTrue(color == "Black"); }
public ActionResult Edit(EditCarViewModel viewModel, int customerId, int carId) { var customer = customersRepo.GetCustomerById(customerId); if (ModelState.IsValid) { var car = new Car() { CarId = carId, Manufacturer = viewModel.Manufacturer, Model = viewModel.Model, VIN = viewModel.VIN, EngineCode = viewModel.EngineCode, PlateCode = viewModel.PlateCode, Year = viewModel.Year, FuelType = viewModel.FuelType }; carsRepo.UpdateCar(car); carsRepo.Save(); return(RedirectToAction("CarsByCustomer", customerId)); } ViewBag.customerId = customerId; ViewBag.CustomerName = customer.FirstName + " " + customer.LastName; return(View(viewModel)); }
public IActionResult Edit(int id, string type) { var car = this.carService.EditDetails <EditCarViewModel>(id); if (car != null) { var model = new EditCarViewModel() { Id = car.Id, Model = car.Model, Made = car.Made, Transmission = car.Transmission, FuelConsumption = car.FuelConsumption, FuelType = car.FuelType, Category = car.Category, Places = car.Places, IsAvailable = car.IsAvailable, PriceForHour = car.PriceForHour, Description = car.Description, }; return(this.View(model)); } return(this.Redirect(string.Format(ALLPATH, type))); }
public async Task <IActionResult> EditAutoItem(EditCarViewModel model) { if (ModelState.IsValid) { var editedCarAd = await advertismentRepository.GetById(model.Id); editedCarAd.Title = model.Title; editedCarAd.Item.Brand = model.Brand; editedCarAd.Item.Description = model.Description; editedCarAd.Item.Mileage = Int32.Parse(model.Mileage); ((AutoItem)(editedCarAd.Item)).Seats = Int32.Parse(model.Seats); ((AutoItem)(editedCarAd.Item)).Doors = Int32.Parse(model.Doors); ((AutoItem)(editedCarAd.Item)).Price = Double.Parse(model.Price); editedCarAd.Item.ProductAge = model.ProductAge; if (model.Picture != null) { editedCarAd.Picture = ProcessUploadedPhoto(model.Picture); } try { await advertismentRepository.Update(editedCarAd); InitializeResultView(true, "You have successfuly updated this article", "Index", "Home", "Home"); } catch (Exception e) { InitializeResultView(false, "Failed to update this article", "MyAdvertisments", "Advertisment", ""); } return(View("ResultView")); } return(View()); }
public async Task <IActionResult> Edit(string id) { var allFuelTypes = default(IEnumerable <FuelTypeDetails>); var allTransmissionTypes = default(IEnumerable <TransmissionTypeDetails>); var allTasks = new List <Task>(); allTasks.Add(Task.Run(async() => { allFuelTypes = (await this.fuelTypeService.GetAllTypesAsync()) .Select(ft => new FuelTypeDetails { Id = ft.Id, Type = ft.Name }) .OrderBy(fuel => fuel.Type); })); allTasks.Add(Task.Run(async() => { allTransmissionTypes = (await this.transmissionTypeService.GetAllTypesAsync()) .Select(tt => new TransmissionTypeDetails { Id = tt.Id, Type = tt.Type }) .OrderBy(transmission => transmission.Type); })); await Task.WhenAll(allTasks); var carData = await this.carService.GetCarDetailsByIdAsync(id); if (carData == null) { this.ShowNotification(string.Format( NotificationMessages.InvalidOperation), NotificationType.Error); this.Redirect(WebConstants.AdminCustomersAllCustomers); } var model = new EditCarViewModel { Id = carData.Id, CustomerId = carData.CustomerId, Vin = carData.Vin, Make = carData.MakeName, Model = carData.ModelName, YearOfManufacturing = carData.YearOfManufacturing, RegistrationPlate = carData.RegistrationPlate, EngineModel = carData.EngineModel, EngineHorsePower = carData.EngineHorsePower, Кilometers = carData.Кilometers, FuelTypeId = allFuelTypes.FirstOrDefault(ft => ft.Type == carData.FuelTypeName).Id, FuelTypes = allFuelTypes.Select(ft => new SelectListItem(ft.Type, ft.Id)), TransmissionId = allTransmissionTypes.First(tr => tr.Type == carData.TransmissionName).Id, Transmissions = allTransmissionTypes.Select(tr => new SelectListItem(tr.Type, tr.Id)) }; return(this.View(model)); }
public async Task <IActionResult> Edit(EditCarViewModel model) { var car = Mapper.Map <EditCarServiceModel>(model); await this.carService.Edit(car); return(RedirectToAction("All", "Car")); }
public async Task <IActionResult> Edit(int id) { var car = await this.carService.GetCarAsync(id).ConfigureAwait(false); var allExtras = this.extraService.GetAllExtras(); var model = new EditCarViewModel { Brands = this.brandService.GetBrands() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(), CarModels = this.modelService.GetAllModelsByBrandId(car.BrandId) .Select(m => new SelectListItem { Value = m.Id.ToString(), Text = m.Name }).ToList(), NumberOfGears = this.gearTypeService.GetGearboxesDependingOnGearType(id) .Select(x => new SelectListItem { Value = x.NumberOfGears.ToString(), Text = x.NumberOfGears.ToString() }).ToList(), BodyTypes = this.bodyTypeService.GetBodyTypes() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(), GearTypes = this.gearTypeService.GetGearTypes() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(), ColorTypes = this.colorTypeService.GetColorTypes() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(), FuelTypes = this.fuelTypeService.GetFuelTypes() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(), Car = new CarViewModel(car) { StatusMessage = this.StatusMessage }, Extras = allExtras.Select(e => new ExtraCheckBox { Id = e.Id, Name = e.Name, Selected = car.CarsExtras.Any(ce => ce.Extra.Id == e.Id) ? true : false }).ToArray() }; return(View(model)); }
public IActionResult Edit(EditCarViewModel modelvm) { if (ModelState.IsValid) { Car car = new Car() { Id = modelvm.Id, Mark = modelvm.Mark, Model = modelvm.Model, Color = modelvm.Color, Goverment_number = modelvm.Goverment_number, Year = modelvm.Year, id_supplier = modelvm.id_supplier, Price = modelvm.Price, status = modelvm.status, country = modelvm.country, city = modelvm.city }; if (modelvm.Image != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(modelvm.Image.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)modelvm.Image.Length); } car.Image = Convert.ToBase64String(imageData);; car.ImageMimeType = modelvm.Image.ContentType; if (_context.UpdateCar(car)) { return(RedirectToAction("IndexBySupplier", "Car")); } else { ModelState.AddModelError("", "Ошибка"); } } else { if (_context.UpdateCarWithoutImage(car)) { return(RedirectToAction("IndexBySupplier", "Car")); } else { ModelState.AddModelError("", "Ошибка"); } } } if (AllMarks[0] == "Все") { AllMarks.RemoveAt(0); } ViewBag.Marks = new SelectList(AllMarks); return(View(modelvm)); }
// GET: Cars/Edit/5 public ActionResult Edit(int id) { EditCarViewModel carOfInterest = _carService.GetCarById(id); if (carOfInterest != null) { return(View(carOfInterest)); } return(NotFound()); }
// GET: Cars/Delete/5 public ActionResult Delete(int id) { EditCarViewModel car = _carService.GetCarById(id); if (car == null) { return(NotFound()); } return(View(car)); }
public IActionResult UpdateCar(EditCarViewModel viewModel) { var car = mapper.Map <Car>(viewModel.CarDto); car.Id = viewModel.CarId; carRepo.Update(car); return(RedirectToAction("Index")); }
public ActionResult _Create() { Car car = new Car(); var result = new EditCarViewModel(); result.CarBodies = unitOfWork.CarBodyRepository.GetAll().ToList(); result.CarClasses = unitOfWork.CarClassRepository.GetAll().ToList(); result.Transmissions = unitOfWork.TransmissionRepository.GetAll().ToList(); result.Car = car; return(PartialView("_Create", result)); }
public ActionResult Edit(int id) { Cars cars = carsRepository.GetCars(id).Cars; EditCarViewModel viewModel = new EditCarViewModel() { BodyStyles = carsRepository.GetAllBodyStyle().BodyStyles.Select(m => new SelectListItem { Text = m.BodyStyleName, Value = m.BodyStyleId.ToString() }), Colors = carsRepository.GetAllColor().Colors.Select(c => new SelectListItem { Text = c.ColorName, Value = c.ColorId.ToString() }), Interiors = carsRepository.GetAllInteriorColors().InteriorColorss.Select(m => new SelectListItem { Text = m.InteriorColorName, Value = m.InteriorColorId.ToString() }), CarId = id, Makes = carsRepository.GetAllMake().Makes.Select(m => new SelectListItem { Text = m.MakeName, Value = m.MakeId.ToString() }), Models = carsRepository.GetAllCarModel().CarModels.Select(m => new SelectListItem { Text = m.CarModelName, Value = m.CarModelId.ToString() }), Transmissions = carsRepository.GetAllTransmission().Transmissions.Select(m => new SelectListItem { Text = m.TransmissionName, Value = m.TransmissionId.ToString() }), Types = carsRepository.GetAllCarType().CarTypes.Select(m => new SelectListItem { Text = m.CarTypeName, Value = m.CarTypeId.ToString() }), Sold = false, Special = false, Price = cars.SalesPrice, Mileage = cars.Mileage, MSRP = cars.MSRP, Vin = cars.Vin, Year = cars.CarYear, Discription = cars.Discription }; return(View(viewModel)); }
public async Task <IActionResult> Edit(EditCarViewModel carInputModel) { if (!this.ModelState.IsValid) { return(this.View(carInputModel)); } carInputModel.ManufacturedOn = new DateTime(carInputModel.Year, carInputModel.Month, 1); await this.carsService.EditAsync(carInputModel); return(this.RedirectToAction("MyCars")); }
public IActionResult Edit(EditCarViewModel viewModel) { var p = _context.Cars.FirstOrDefault(x => x.Id == viewModel.Id); p.Manufacturer = viewModel.Manufacturer; p.Model = viewModel.Model; p.Price = viewModel.Price; p.Seats = viewModel.Seats; p.Year = viewModel.Year; _context.SaveChanges(); return(RedirectToAction("Index")); }
public void TestViewModelConstruction() { Car car = new Car() { CarId = 1, Color = "White" }; Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>(); EditCarViewModel viewModel = new EditCarViewModel(mockServiceFactory.Object, car); Assert.IsTrue(viewModel.Car != null && viewModel.Car != car); Assert.IsTrue(viewModel.Car.CarId == car.CarId && viewModel.Car.Color == car.Color); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Marca,Descripcion,Modelo,Precio,Estado,Foto")] EditCarViewModel car) { if (id != car.Id) { return(NotFound()); } if (ModelState.IsValid) { try { Car myCar = _context.Car.Find(id); myCar.Descripcion = car.Descripcion; myCar.Modelo = car.Modelo; myCar.Precio = car.Precio; myCar.Estado = car.Estado; myCar.Kilometros = car.Kilometros; myCar.MarcaId = car.Marca; if (car.Foto != null) { if (car.ExistPathImg != null) { string pathImg = Path.Combine(hosting.WebRootPath, "img", car.ExistPathImg); System.IO.File.Delete(pathImg); } myCar.PathImg = UploadImage(car); } _context.Update(myCar); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(car.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(car)); }
public IActionResult Edit(int id) { var model = _context.Cars.FirstOrDefault(x => x.Id == id); var viewModel = new EditCarViewModel { Id = model.Id, Manufacturer = model.Manufacturer, Model = model.Model, Seats = model.Seats, Price = model.Price, Year = model.Year }; return(View(viewModel)); }
public async Task <ActionResult> EditCar(EditCarViewModel editCarViewModel) { if (ModelState.IsValid) { bool changed = false; CarsRepository <Car, CarDTO> carsRepo = new CarsRepository <Car, CarDTO>(); Car car = await carsRepo.GetById(editCarViewModel.SelectedCarToEditId); // Add image if selected if (Request.Files.Count > 0) { var postedFile = Request.Files[0]; if (postedFile != null && postedFile.ContentLength > 0) { string carsImagesPath = HttpContext.Server.MapPath("~/Content/Images/Cars"); string extension = Path.GetExtension(postedFile.FileName); string carFileName = $"{editCarViewModel.SelectedCarToEditId}{extension}"; string saveToPath = Path.Combine(carsImagesPath, carFileName); try { postedFile.SaveAs(saveToPath); car.ImageName = carFileName; changed = true; } catch (Exception) { ModelState.AddModelError(string.Empty, "Failed to save new car image."); } } } if (editCarViewModel.Name != car.Name) { car.Name = editCarViewModel.Name; changed = true; } if (changed) { await carsRepo.Update(car.Id, car); TempData["CarId"] = car.Id; } } return(RedirectToAction("Index")); }
public async Task <ActionResult> UpdateAd(string adId, [FromBody] EditCarViewModel ad) { if (ad == null) { return(this.BadRequest()); } var isSuccessfully = await this._carService.UpdateAd(ad, adId); if (!isSuccessfully) { return(this.BadRequest()); } return(this.Ok()); }
public ViewResult Edit(int id) { Car car = _carRepository.GetCar(id); EditCarViewModel editCarViewModel = new EditCarViewModel { EditCarId = car.Id, Name = car.Name, MinLeeftijd = car.MinLeeftijd, Prijs = car.Prijs, Kw = car.Kw, ExistingPhotoCar = car.PhotoCar, UpdateDate = DateTime.Now }; return(View(editCarViewModel)); }
public IActionResult CreateCar() { var model = new EditCarViewModel { Brands = this.brandService.GetBrands() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(), CarModels = this.modelService.GetAllModelsByBrandId(this.brandService.GetBrands().FirstOrDefault().Id) .Select(m => new SelectListItem { Value = m.Id.ToString(), Text = m.Name }).ToList(), NumberOfGears = this.gearTypeService.GetGearboxesDependingOnGearType(this.gearTypeService.GetGearTypes().FirstOrDefault().Id) .Select(x => new SelectListItem { Value = x.NumberOfGears.ToString(), Text = x.NumberOfGears.ToString() }).ToList(), BodyTypes = this.bodyTypeService.GetBodyTypes() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(), GearTypes = this.gearTypeService.GetGearTypes() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(), ColorTypes = this.colorTypeService.GetColorTypes() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(), FuelTypes = this.fuelTypeService.GetFuelTypes() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(), Car = new CarViewModel() { StatusMessage = this.StatusMessage } }; return(this.View(model)); }
public ActionResult EditCar(int carID) { EditCarViewModel vm = new EditCarViewModel(); tblCarsService cservice = new tblCarsService(); tblColorsService colservice = new tblColorsService(); tblBrandsService bservice = new tblBrandsService(); vm.car = cservice.getCar(carID); vm.selectedBrandId = vm.car.BrandID; vm.selectedColorId = vm.car.ColorID; vm.brandChoice = bservice.getBrands(); vm.colorChoice = colservice.getColors(); vm.fuelChoice = (Fuel)Enum.Parse(typeof(Fuel), vm.car.CarFuel, true); vm.transmissionChoice = (Transmission)Enum.Parse(typeof(Transmission), vm.car.Transmission, true); return(View(vm)); }
public async Task <IActionResult> EditEntryCar(int carId) { var car = await _context.Cars.Where(s => s.Id == carId).FirstOrDefaultAsync(); EditCarViewModel model = new EditCarViewModel { Id = car.Id, FullName = car.FullName, Description = car.Description, Price = car.Price, ProdDate = car.ProdDate, Location = car.Location, UserId = car.SiteUserId }; return(View(model)); }
public ActionResult Edit(int id, EditCarViewModel model) { var car = this.Data.Cars .Find(id); if (car == null) { return this.HttpNotFound(); } if (!this.ModelState.IsValid) { return this.View(model); } car.Price = model.Price; car.Details = model.Details; this.Data.SaveChanges(); return this.RedirectToAction<CarsController>(x => x.Details(model.Id)); }