public ActionResult Add(FormCollection formValues, VehicleFormModel vehicleForm, HttpPostedFileBase photoFile) { if (IsSaveOperation(formValues)) { if (TrySaveVehicle(vehicleForm, photoFile)) { return(RedirectToRoute("Dashboard")); } } AddYearMakeModelSelectListsToViewBag(vehicleForm); var vehicles = Using <GetVehicleListForUser>().Execute(CurrentUserId); var vm = new VehicleAddViewModel { User = CurrentUser, VehiclesList = new VehicleListViewModel(vehicles), Vehicle = vehicleForm }; vm.VehiclesList.IsCollapsed = true; return(View(vm)); }
public async Task <ActionResult> Add(VehicleAddViewModel model) { bool haveErrors = false; if (model.Board.Length == 0) { ModelState.AddModelError("data", "Placa do carro não pode ter valor vazio"); haveErrors = true; } DateTime tmpDate = DateTime.ParseExact(model.InitialDate, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); if (!model.DateValid(tmpDate)) { ModelState.AddModelError("data", "Data inicial inválida"); haveErrors = true; } if (haveErrors) { return(View(model)); } try { Service.VehicleControl.Entry(model.Board, tmpDate); } catch (NotFoundDateControl e) { ModelState.AddModelError("data", "Não foi encontrado um período vigente para associar a data ao preço cobrado. Adicione um Valor Praticado."); return(View(model)); } return(RedirectToAction("Index")); }
public ActionResult Edit(int id) { var vehicles = Using <GetVehicleListForUser>() .Execute(CurrentUserId); var selected = vehicles .FirstOrDefault(x => x.VehicleId == id); // adding a flash notification here might provide a better user experience if (selected == null) { return(RedirectToRoute("Dashboard")); } var vehicleForm = ConstructForm(selected); AddYearMakeModelSelectListsToViewBag(vehicleForm); var vm = new VehicleAddViewModel { User = CurrentUser, Vehicle = vehicleForm, VehiclesList = new VehicleListViewModel(vehicles, id) }; vm.VehiclesList.IsCollapsed = true; return(View(vm)); }
public ActionResult PostVehicle(Car car) { if (!ModelState.IsValid) { //return BadRequest(ModelState); } GuildCarsRepositoryFactory.GetRepository().Insert(car); //db.SaveChanges(); var model = new VehicleAddViewModel(); var Repo = GuildCarsRepositoryFactory.GetRepository(); model.Make = new SelectList(Repo.GetMakes(), "MakeId", "MakeName"); model.Model = new SelectList(Repo.GetModels(), "ModelId", "ModelName"); model.Interior = new SelectList(Repo.GetInteriors(), "Id", "InteriorName"); model.Transmission = new SelectList(Repo.GetTransmissions(), "Id", "TransName"); model.Color = new SelectList(Repo.GetColors(), "Id", "ColorName"); model.BodyStyle = new SelectList(Repo.GetBodyStyles(), "Id", "BodyStyleName"); model.CarType = new SelectList(Repo.GetCarTypes(), "Id", "CarTypeName"); model.States = new SelectList(Repo.GetStates(), "StatesId", "StatesName"); model.Car = new Car(); List <Car> pass = new List <Car>(); pass = Repo.GetAll(); return(View("Vehicles", pass)); //return Created($"api/Dvds1/{dvd.DvdId})", dvd); //return null; //return CreatedAtRoute("DefaultApi", new { id = dvd.DvdId }, dvd); }
public ActionResult UpdateCar(Car car) { if (!ModelState.IsValid) { //return BadRequest(ModelState); } GuildCarsRepositoryFactory.GetRepository().Update(car); var model = new VehicleAddViewModel(); var Repo = GuildCarsRepositoryFactory.GetRepository(); List <Car> cars = new List <Car>(); cars = Repo.GetAll(); model.Make = new SelectList(Repo.GetMakes(), "MakeId", "MakeName"); model.Model = new SelectList(Repo.GetModels(), "ModelId", "ModelName"); model.Interior = new SelectList(Repo.GetInteriors(), "Id", "InteriorName"); model.Transmission = new SelectList(Repo.GetTransmissions(), "Id", "TransName"); model.Color = new SelectList(Repo.GetColors(), "Id", "ColorName"); model.BodyStyle = new SelectList(Repo.GetBodyStyles(), "Id", "BodyStyleName"); model.CarType = new SelectList(Repo.GetCarTypes(), "Id", "CarTypeName"); model.States = new SelectList(Repo.GetStates(), "StatesId", "StatesName"); return(View("Vehicles", cars)); }
public IActionResult ReflectedXSS(VehicleAddViewModel vehicleAddViewModel) { ViewBag.Year = vehicleAddViewModel.Year; ViewBag.Color = vehicleAddViewModel.Color; ViewBag.Plate = vehicleAddViewModel.Plate; return(View()); }
public ActionResult Add(VehicleAddViewModel model) { if (ModelState.IsValid) { var repo = VehicleRepositoryFactory.GetRepository(); try { if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { var savepath = Server.MapPath("~/Images"); string fileName = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName); string extension = Path.GetExtension(model.ImageUpload.FileName); var filePath = Path.Combine(savepath, fileName + extension); int counter = 1; while (System.IO.File.Exists(filePath)) { filePath = Path.Combine(savepath, fileName + counter.ToString() + extension); counter++; } model.ImageUpload.SaveAs(filePath); model.Vehicle.Picture = Path.GetFileName(filePath); } repo.Insert(model.Vehicle); return(RedirectToAction("Details", new { id = model.Vehicle.VehicleID })); } catch (Exception ex) { throw ex; } } else { var makesRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); var conditionRepo = ConditionRepositoryFactory.GetRepository(); var vehicleTypeRepo = VehicleTypeRepositoryFactory.GetRepository(); var transmissionTypeRepo = TransmissionTypeRepositoryFactory.GetRepository(); var colorRepo = ColorRepositoryFactory.GetRepository(); model.Makes = new SelectList(makesRepo.GetAll(), "MakeID", "MakeName"); model.Models = new SelectList(modelRepo.GetAll(), "ModelID", "ModelName"); model.ConditionName = new SelectList(conditionRepo.GetAll(), "ConditionID", "ConditionName"); model.VehicleType = new SelectList(vehicleTypeRepo.GetAll(), "VehicleTypeID", "VehicleTypeName"); model.TransmissionType = new SelectList(transmissionTypeRepo.GetAll(), "TransmissionTypeID", "TransmissionTypeName"); model.CarColorName = new SelectList(colorRepo.GetAll(), "ColorID", "ColorName"); model.InteriorColorName = new SelectList(colorRepo.GetAll(), "ColorID", "ColorName"); return(View(model)); } }
public ActionResult Add() { var model = new VehicleAddViewModel { Brand = new Brand(), Vehicles = _productService.GetAll() }; return(View(model)); }
public ActionResult AddVehicle() { var model = new VehicleAddViewModel(); var make = MakeRepositoryFactory.GetRepository(); var models = ModelRepositoryFactory.GetRepository(); model.Make = new SelectList(make.GetAll(), "MakeId", "MakeName"); model.Models = new SelectList(models.GetAll(), "ModelId", "ModelName"); model.vehicle1 = new Vehicle(); return(View(model)); }
public ActionResult AddVehicle(VehicleAddViewModel model) { var make = MakeRepositoryFactory.GetRepository(); var models = ModelRepositoryFactory.GetRepository(); model.Make = new SelectList(make.GetAll(), "MakeId", "MakeName"); model.Models = new SelectList(models.GetAll(), "ModelId", "ModelName"); if (ModelState.IsValid) { model.vehicle1.IsSold = false; var repo = VehicleRepositoryFactory.GetRepository(); try { if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { var savepath = Server.MapPath("~/Images"); string fileName = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName); string extension = Path.GetExtension(model.ImageUpload.FileName); var filePath = Path.Combine(savepath, fileName + extension); int counter = 1; while (System.IO.File.Exists(filePath)) { filePath = Path.Combine(savepath, fileName + counter.ToString() + extension); counter++; } model.ImageUpload.SaveAs(filePath); model.vehicle1.ImageFileName = Path.GetFileName(filePath); } repo.Insert(model.vehicle1); return(RedirectToAction("EditVehicle", new { id = model.vehicle1.VehicleId })); } catch (Exception ex) { throw ex; } } else { model.vehicle1 = new Vehicle(); return(View(model)); } }
public IActionResult NewVehicle(VehicleAddViewModel data) { var seatMap = new List <(int, string)>(); data.IsOnline = false; if (!String.IsNullOrEmpty(data.CheckIsOnline)) { data.IsOnline = true; foreach (var pair in data.NumberSeats) { var temp = pair.Split('-', StringSplitOptions.RemoveEmptyEntries); if (int.TryParse(temp[0], out var index)) { if (temp != null && temp.Length == 2) { seatMap.Add((index, temp[1]));
public async Task <IActionResult> Create(VehicleAddViewModel viewModel) { if (ModelState.IsValid) { var vehicle = mapper.Map <Vehicle>(viewModel); vehicle.ArrivalTime = DateTime.Now; _context.Add(vehicle); await _context.SaveChangesAsync(); // Try to park this vehicle var v = _context.Vehicles.Where(v => v.LicenceNr == viewModel.LicenceNr).Single(); var result1 = ParkVehicle(v); // We now have a success-flag and a message (in result1) return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public ActionResult AddVehicle() { var model = new VehicleAddViewModel(); var Repo = GuildCarsRepositoryFactory.GetRepository(); model.Make = new SelectList(Repo.GetMakes(), "MakeId", "MakeName"); model.Model = new SelectList(Repo.GetModels(), "ModelId", "ModelName"); model.Interior = new SelectList(Repo.GetInteriors(), "Id", "InteriorName"); model.Transmission = new SelectList(Repo.GetTransmissions(), "Id", "TransName"); model.Color = new SelectList(Repo.GetColors(), "Id", "ColorName"); model.BodyStyle = new SelectList(Repo.GetBodyStyles(), "Id", "BodyStyleName"); model.CarType = new SelectList(Repo.GetCarTypes(), "Id", "CarTypeName"); model.States = new SelectList(Repo.GetStates(), "StatesId", "StatesName"); model.Car = new Car(); return(View(model)); }
public ActionResult Add() { var vehicles = Using <GetVehicleListForUser>() .Execute(CurrentUserId); AddYearMakeModelSelectListsToViewBag(); var vm = new VehicleAddViewModel { User = CurrentUser, Vehicle = new VehicleFormModel(), VehiclesList = new VehicleListViewModel(vehicles) { IsCollapsed = true }, }; vm.VehiclesList.IsCollapsed = true; return(View(vm)); }
public ActionResult AddVehicle() { var model = new VehicleAddViewModel(); var makesRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); var conditionRepo = ConditionRepositoryFactory.GetRepository(); var vehicleTypeRepo = VehicleTypeRepositoryFactory.GetRepository(); var transmissionTypeRepo = TransmissionTypeRepositoryFactory.GetRepository(); var colorRepo = ColorRepositoryFactory.GetRepository(); model.Makes = new SelectList(makesRepo.GetAll(), "MakeID", "MakeName"); model.Models = new SelectList(modelRepo.GetAll(), "ModelID", "ModelName"); model.ConditionName = new SelectList(conditionRepo.GetAll(), "ConditionID", "ConditionName"); model.VehicleType = new SelectList(vehicleTypeRepo.GetAll(), "VehicleTypeID", "VehicleTypeName"); model.TransmissionType = new SelectList(transmissionTypeRepo.GetAll(), "TransmissionTypeID", "TransmissionTypeName"); model.CarColorName = new SelectList(colorRepo.GetAll(), "ColorID", "ColorName"); model.InteriorColorName = new SelectList(colorRepo.GetAll(), "ColorID", "ColorName"); model.Vehicle = new Vehicle(); return(View(model)); }
public ActionResult Add() { VehicleAddViewModel model = new VehicleAddViewModel(); return(View(model)); }