public Vehicle CreateNewVehicle(AddVehicleViewModel addVehicleViewModel, string VehicleImageSource) { Vehicle newVehicle = new Vehicle(); newVehicle.Manufacturer = addVehicleViewModel.Manufacturer; newVehicle.Model = addVehicleViewModel.Model; newVehicle.Doors = addVehicleViewModel.Doors; newVehicle.Seats = addVehicleViewModel.Seats; newVehicle.Colour = addVehicleViewModel.Colour; newVehicle.CostPerDay = addVehicleViewModel.CostPerDay; newVehicle.VehicleType = new VehicleType() { Id = addVehicleViewModel.VehicleTypeId }; newVehicle.Fuel = new Fuel() { Id = addVehicleViewModel.FuelId }; newVehicle.Transmission = new Transmission() { Id = addVehicleViewModel.TransmissionId }; newVehicle.VehicleImageSource = VehicleImageSource; return(newVehicle); }
public async Task <IActionResult> AddVehicle(AddVehicleViewModel model) { try { var make = await _makeRepo.GetMakeAsync(model.Make); if (make == null) { return(NotFound("Kunde inte hitta en tillverkare med namn: " + model.Make)); } var vehicle = new Vehicle { RegistrationNumber = model.RegistrationNumber, Make = make, Model = model.Model, ModelYear = model.ModelYear, Mileage = model.Mileage, FuelType = model.FuelType, GearType = model.GearType }; await _repo.AddAsync(vehicle); if (await _repo.SaveAllChangesAsync()) { return(StatusCode(201)); } return(StatusCode(500, "Det gick inget vidare!")); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public ActionResult AddedVehicles(AddVehicleViewModel model) { var repo = VehicleRepositoryFactory.GetRepository(); Vehicle vehicle = new Vehicle(); vehicle = model.Vehicle; vehicle.IsInstock = true; if (model.ImageUpload != null) { var savepath = Server.MapPath("~/Images"); string fileName = Path.GetFileName(model.ImageUpload.FileName); var filepath = Path.Combine(savepath, fileName); int counter = 1; while (System.IO.File.Exists(filepath)) { filepath = Path.Combine(savepath, filepath + counter.ToString()); counter++; } model.ImageUpload.SaveAs(filepath); vehicle.ImagePath = "/Images/" + fileName; } repo.AddVehicle(vehicle); return(RedirectToAction("AddVehicles")); }
public ActionResult AddNewVehicle(AddVehicleViewModel model) { ValidationViewModel validationModel; if (ModelState.IsValid) { var vehicle = Mapper.Map <Vehicle>(model); vehicle.VehicleType = (VehicleType)Enum.Parse(typeof(VehicleType), model.VehicleType); if (vehicle.Box_Id != null) { vehicle.VehicleStatus = VehicleStatus.Active; } _vehicleService.AddNewVehicle(vehicle); validationModel = new ValidationViewModel(new List <string>(), "Ok"); return(Json(validationModel, JsonRequestBehavior.AllowGet)); } var errors = (from modelStateValue in ModelState.Values from error in modelStateValue.Errors select error.ErrorMessage).ToList(); validationModel = new ValidationViewModel(errors, "Validation errors"); return(Json(validationModel, JsonRequestBehavior.AllowGet)); }
public ActionResult AddVehicle(AddVehicleViewModel model) { if (model.Vehicle.Year > 2020 || model.Vehicle.Year < 1769) { ModelState.AddModelError("error", "No vehicles currently exist out side of the years 1769-2020"); return(View(model)); } if (model.Vehicle.ModelId == 0 || model.Vehicle.MakeId == 0) { ModelState.AddModelError("error", "Please provide a make and model"); return(View(model)); } if (ModelState.IsValid) { IVehicleRepository repo = RepoFactory.CreateVehicleRepo(); var vehicle = repo.Create(model.Vehicle); byte[] imageByte = null; BinaryReader rdr = new BinaryReader(model.Image.InputStream); imageByte = rdr.ReadBytes((int)model.Image.ContentLength); if (System.IO.File.Exists(@"C:\Cohort\Repos\isaiah-dahlberg-individual-work\GuildCars\GuildCars\GuildCars.UI\Images\Inventory-" + model.Vehicle.VehicleId + ".jpg")) { System.IO.File.Delete(@"C:\Cohort\Repos\isaiah-dahlberg-individual-work\GuildCars\GuildCars\GuildCars.UI\Images\Inventory-" + model.Vehicle.VehicleId + ".jpg"); } using (FileStream fs = new FileStream(@"C:\Cohort\Repos\isaiah-dahlberg-individual-work\GuildCars\GuildCars\GuildCars.UI\Images\Inventory-" + vehicle.VehicleId + ".jpg", FileMode.Create)) { fs.Write(imageByte, 0, imageByte.Length); } return(RedirectToAction("EditVehicle/" + vehicle.VehicleId)); } return(View(model)); }
public ActionResult AddVehicle(long id, AddVehicleViewModel model) { ViewBag.ErrorFlag = false; ViewBag.DriverId = id; if (!ModelState.IsValid) { return(View()); } try { Driver driver = new Driver(id); driver.AddOrChangeVehicle(new Vehicle.RegisterationNumberFormat(model.Alphabets, model.Number, (short)model.Year.Year), model.CarModel, (int)model.EngineCC, model.IsAc, model.Color, new VehicleType(model.VehicleType)); return(RedirectToAction("ViewDetails", new { id = id })); } catch (UniqueKeyViolationException ex) { ViewBag.ErrorFlag = true; ModelState.AddModelError(String.Empty, ex.Message); return(View()); } catch (Exception ex) { return(RedirectToAction("ErrorPage", "Error", ex)); } }
public ActionResult AddVehicle() { var model = new AddVehicleViewModel(); model = GetAddVehicleModel(model); return(View(model)); }
public async Task <IActionResult> AddVehicle(AddVehicleViewModel addVehicleViewModel) { await AuthenticateUserLogin(true); bool imageUploadedSuccessfully = false; string vehicleImageSource = ""; if (ModelState.IsValid) { imageUploadedSuccessfully = UploadVehicleImage(addVehicleViewModel.vehicleImageFile).Result; if (imageUploadedSuccessfully) { vehicleImageSource = Path.GetFileName(addVehicleViewModel.vehicleImageFile.FileName); Vehicle newVehicle = CreateNewVehicle(addVehicleViewModel, vehicleImageSource); int vehicleAdded = (int)await CommandFactory.CreateCommand(CommandFactory.ADD_VEHICLE, newVehicle, DbContext).Execute(); if (vehicleAdded == 1) { TempData["successmessage"] = "Vehicle Added Successfully!"; return(RedirectToAction("Index", "Home")); } } else { List <VehicleType> VehicleTypeList = await GetVehicleTypes(); List <Transmission> TransmissionList = await GetTransmissionTypes(); List <Fuel> FuelList = await GetFuelTypes(); ViewData["VehicleTypeList"] = new SelectList(VehicleTypeList, "Id", "Size"); ViewData["TransmissionList"] = new SelectList(TransmissionList, "Id", "Type"); ViewData["FuelList"] = new SelectList(FuelList, "Id", "Type"); TempData["errormessage"] = "Failed to add vehicle. Please try again!"; return(View(addVehicleViewModel)); } return(View()); } else { List <VehicleType> VehicleTypeList = await GetVehicleTypes(); List <Transmission> TransmissionList = await GetTransmissionTypes(); List <Fuel> FuelList = await GetFuelTypes(); ViewData["VehicleTypeList"] = new SelectList(VehicleTypeList, "Id", "Size"); ViewData["TransmissionList"] = new SelectList(TransmissionList, "Id", "Type"); ViewData["FuelList"] = new SelectList(FuelList, "Id", "Type"); TempData["errormessage"] = "Vehicle data is invalid. Please try again!"; return(View(addVehicleViewModel)); } }
public ActionResult AddVehicle() { var model = new AddVehicleViewModel() { VehicleGroups = blVehicleGroup.Select().ToList(), Colors = blColor.Select().ToList() }; return(View(model)); }
public Vehicle AddVehicle() { addVehicleWindow = new AddVehicleWindow(); addVehicleViewModel = new AddVehicleViewModel() { AddCommand = new RelayCommand(ExecuteAddCommand), }; addVehicleWindow.DataContext = addVehicleViewModel; return(addVehicleWindow.ShowDialog() == true ? addVehicleViewModel.Vehicle : null); }
public IActionResult AddVehicle() { var model = new AddVehicleViewModel { Quantity = 1, Vehicles = _vehicleRepository.GetComboVehicles() }; return(View(model)); }
public IActionResult AddVehicle() { var facilities = this.facilityService.GetAll <FacilityDropDownViewModel>(); var viewModel = new AddVehicleViewModel { Facilities = facilities, }; return(this.View(viewModel)); }
public ActionResult AddVehicle(AddVehicleViewModel model) { if (ModelState.IsValid) { var repo = new VehicleRepositoryADO(); try { var savePath = Server.MapPath("~/Images"); string fileName = Path.GetFileNameWithoutExtension(model.PictureUpload.FileName); string extension = Path.GetExtension(model.PictureUpload.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.PictureUpload.SaveAs(filePath); model.Vehicle.Picture = Path.GetFileName(filePath); repo.Insert(model.Vehicle); return(RedirectToAction("EditVehicle", "Admin", new { id = model.Vehicle.VehicleID })); } catch (Exception ex) { throw ex; } } else { var vehicleModel = new AddVehicleViewModel(); var makeRepo = new MakeRepositoryADO(); var modelRepo = new ModelRepositoryADO(); var typeRepo = new TypeRepositoryADO(); var bodystyleRepo = new BodyStyleRepositoryADO(); var transmissionRepo = new TransmissionRepositoryADO(); var colorRepo = new ColorRepositoryADO(); var interiorRepo = new InteriorRepositoryADO(); vehicleModel.Makes = new SelectList(makeRepo.GetAll(), "MakeID", "MakeName"); vehicleModel.Models = new SelectList(modelRepo.GetAll(), "ModelID", "ModelName"); vehicleModel.Types = new SelectList(modelRepo.GetAll(), "TypeID", "TypeName"); vehicleModel.BodyStyles = new SelectList(modelRepo.GetAll(), "BodyID", "BodyStyleName"); vehicleModel.Transmissions = new SelectList(modelRepo.GetAll(), "TransmissionID", "TransmissionType"); vehicleModel.Colors = new SelectList(modelRepo.GetAll(), "ColorID", "ColorName"); vehicleModel.Interiors = new SelectList(modelRepo.GetAll(), "InteriorID", "InteriorColor"); return(View(vehicleModel)); } }
public async Task <IActionResult> AddVehicle(AddVehicleViewModel model) { if (this.ModelState.IsValid) { await _repairRepository.AddItemToRepairAsync(model, this.User.Identity.Name); return(this.RedirectToAction("Create")); } return(this.View(model)); }
private async Task <AddVehicleViewModel> GetAddVehicleViewModel() { var addVehicleViewModel = new AddVehicleViewModel(); addVehicleViewModel.Brands = await _brandServices.GetAllBrandsAsync(); addVehicleViewModel.Models = addVehicleViewModel.Brands[0].Models; addVehicleViewModel.ManufacturingDate = DateTime.Today; return(addVehicleViewModel); }
public ActionResult AddVehicle(AddVehicleViewModel viewModel) { if (ModelState.IsValid) { try { var newVehicle = new AddVehicleObject() { Make = viewModel.Make, Model = viewModel.Model, Type = viewModel.Type, BodyStyle = viewModel.BodyStyle, Year = viewModel.Year, Transmission = viewModel.Transmission, Color = viewModel.Color, Interior = viewModel.Interior, Mileage = viewModel.Mileage, VIN = viewModel.VIN, MSRP = viewModel.MSRP, SalePrice = viewModel.SalePrice, Description = viewModel.Description }; var repo = VehicleRepositoryFactory.GetVehicleRepository(); repo.AddVehicle(newVehicle); var savepath = Server.MapPath("~/Images/Vehicles"); string extension = Path.GetExtension(viewModel.ImageUpload.FileName); var filePath = Path.Combine(savepath, "inventory-" + newVehicle.VehicleId.ToString() + extension); viewModel.ImageUpload.SaveAs(filePath); var fileName = Path.GetFileName(filePath); repo.AddVehicleFileName(fileName, newVehicle.VehicleId); return(RedirectToAction("EditVehicle", new { id = newVehicle.VehicleId })); } catch (Exception ex) { throw ex; } } else { var vehicleViewObject = new AddVehicleViewModel(); return(View(vehicleViewObject)); } }
public IActionResult AddVehicleNoUser() { var model = new AddVehicleViewModel { Brands = _vehicleRepository.GetComboBrands(), Fuels = _vehicleRepository.GetComboFuels(), Colors = _vehicleRepository.GetComboColors(), }; return(View(model)); }
// GET: Variants/Create public async Task <ActionResult> Create() { AddVehicleViewModel addVehicleViewModel = new AddVehicleViewModel { ColorList = await db.Colors.ToListAsync(), ManufacturerList = await db.Manufacturers.ToListAsync(), VehicleTypeList = await db.VehicleTypes.ToListAsync(), VehicleModelList = await db.VehicleModel.ToListAsync() }; return(View("~/Views/Vehicle/Variants/Create.cshtml", addVehicleViewModel)); }
// GET: AddVehicleViewModels public async Task <ActionResult> Index() { AddVehicleViewModel addVehicleViewModel = new AddVehicleViewModel { ColorList = await db.Colors.ToListAsync(), ManufacturerList = await db.Manufacturers.ToListAsync(), VehicleTypeList = await db.VehicleTypes.ToListAsync(), VehicleModelList = await db.VehicleModel.ToListAsync() }; return(View(addVehicleViewModel)); }
//---------------------------------------------------------- public async Task <IActionResult> EditVehicle(int?id) { var vehicle = _context.Vehicle.FirstOrDefault(v => v.VehicleId == id); AddVehicleViewModel vm = Model(); vm.Vehicle = vehicle; return(View(vm)); }
// GET: Admin public ActionResult AddVehicles() { var repo = VehicleRepositoryFactory.GetRepository(); var model = new AddVehicleViewModel(); model.Makes = new SelectList(repo.GetAllMakes(), "MakeId", "MakeName"); model.InteriorColors = new SelectList(repo.GetAllColors(), "ColorId", "ColorName"); model.ExteriorColors = new SelectList(repo.GetAllColors(), "ColorId", "ColorName"); model.Transmissions = new SelectList(repo.GetAllTransmissionTypes(), "TransmissionId", "TransmissionName"); model.BodyStyles = new SelectList(repo.GetAllBodyStyles(), "BodyStyleId", "BodyStyleName"); return(View(model)); }
public async Task <SelectListItem> GetComboSoloBrand(AddVehicleViewModel model) { var brand = await _context.Brands.FirstOrDefaultAsync(b => b.Id == model.BrandId); var list = new SelectListItem { Text = brand.BrandName, Value = brand.Id.ToString(), }; return(list); }
public ActionResult AddVehicle() { var model = new AddVehicleViewModel(); model.SetMakeItems(CarFactory.Create().GetAllMakes()); model.SetModelItems(CarFactory.Create().GetAllModel()); model.SetBodyStyleItems(); model.SetTypeItems(); model.SetTransmissionItems(); model.SetColorItems(); model.SetInteriorItems(); return(View(model)); }
public ActionResult AddVehicle(AddVehicleViewModel model) { if (model.ImageFile == null || model.ImageFile.ContentLength <= 0) { ModelState.AddModelError(model.ImageFile.ToString(), "Image is required"); } if (model.ImageFile != null && model.ImageFile.ContentLength > 0) { var path = Server.MapPath("~/Images"); string file = Path.GetFileName(model.ImageFile.FileName); string filePath = Path.GetExtension(model.ImageFile.FileName); var wholefile = Path.Combine(path, file + filePath); int counter = 1; while (System.IO.File.Exists(filePath)) { wholefile = Path.Combine(path, file + counter.ToString() + filePath); counter++; } model.ImageFile.SaveAs(wholefile); } if (ModelState.IsValid) { Vehicle vehicleToAdd = new Vehicle(); vehicleToAdd.VehicleId = model.VehicleId; vehicleToAdd.Color = model.AddVehicles.Color; vehicleToAdd.Interior = model.AddVehicles.Interior; vehicleToAdd.IsNew = model.AddVehicles.IsNew; vehicleToAdd.Mileage = model.AddVehicles.Mileage; vehicleToAdd.MSRP = model.AddVehicles.MSRP; vehicleToAdd.Transmission = model.AddVehicles.Transmission; vehicleToAdd.Year = model.AddVehicles.Year; vehicleToAdd.VinNumber = model.AddVehicles.VinNumber; vehicleToAdd.SalesPrice = model.AddVehicles.SalesPrice; vehicleToAdd.Description = model.AddVehicles.Description; vehicleToAdd.MakeId = ctxs.GetMakeById(model.VehicleMakeId); vehicleToAdd.ModelId = ctxs.GetModelById(model.VehicleModelId); vehicleToAdd.VehicleType = model.AddVehicles.VehicleType; vehicleToAdd.ImageFileName = "Images/" + model.ImageFile.FileName; ctxs.AddVehicle(vehicleToAdd); } return(RedirectToAction("Vehicle")); }
//authorize section on milstone 4 lesson 11 //[Authorize(Roles = "admin")] public ActionResult AddVehicle() { var model = new AddVehicleViewModel(); model.SetMakeType(_carDealer.GetAllCarMakes()); model.SetModelType(_carDealer.GetAllCarModels()); model.SetBodyType(_carDealer.GetBodyStyles()); model.SetVehicleType(_carDealer.GetVehicleType()); model.SetTransmissionType(_carDealer.GetTransmissions()); model.SetColorOptions(); model.SetInteriorTypes(); //throw new Exception(); return(View(model)); }
public Vehicle ToNewVehicle(AddVehicleViewModel model, User user) { var vehicle = new Vehicle { LicencePlate = model.LicencePlate, BrandId = model.BrandId, ModelId = model.ModelId, EngineCapacity = model.EngineCapacity, FuelId = model.FuelId, ColorId = model.ColorId, CreationDate = DateTime.UtcNow, User = user, }; return(vehicle); }
public ActionResult AddVehicle(AddVehicleViewModel model) { if (ModelState.IsValid) { _raceTrackRepository = new RaceTrackRepository(dbContext); if (model.Vehicle.VehicleType == VehicleType.Truck) { Truck newTruck = new Truck { TowStrap = model.Vehicle.TowStrap, LiftHeight = model.TruckLiftHeight, VehicleType = model.Vehicle.VehicleType }; if (newTruck.AllowOnTrack(_raceTrackRepository.GetVehicleCount())) { _raceTrackRepository.Add(newTruck); } else { ModelState.AddModelError("", "Not allowed"); } } if (model.Vehicle.VehicleType == VehicleType.Car) { Car newCar = new Car { TowStrap = model.Vehicle.TowStrap, TireWear = model.CarTireWear, VehicleType = model.Vehicle.VehicleType }; if (newCar.AllowOnTrack(_raceTrackRepository.GetVehicleCount())) { _raceTrackRepository.Add(newCar); } else { ModelState.AddModelError("", "Not allowed"); } } } return(RedirectToAction("Index", "Home")); }
public ActionResult AddVehicle() { List <string> MakeNames = new List <string>(); AddVehicleViewModel vm = new AddVehicleViewModel(); var makeRepo = CarMakesRepositoryFactory.GetRepository(); List <CarMakes> carMakes = makeRepo.GetAll(); var carMakeNames = (from carmake in carMakes select carmake.MakeName).ToList(); vm.CarMakeNames = new SelectList(carMakes, "MakeName", "MakeName", 1); return(View(vm)); }
public async Task Add(AddVehicleViewModel viewModel, int creatorId) { var vehicle = await _dbContext.Vehicles.FirstOrDefaultAsync(x => x.Name == viewModel.Name); var user = await _dbContext.Users.FindAsync(creatorId); var vehicleType = (VehicleType)Enum.Parse(typeof(VehicleType), viewModel.VehicleType, true); var price = double.Parse(viewModel.Price); if (vehicle == null && user != null) { vehicle = new Vehicle(user.Id, viewModel.Name, vehicleType, price); await _dbContext.Vehicles.AddAsync(vehicle); await _dbContext.SaveChangesAsync(); } }
public void CreateVehicle(AddVehicleViewModel newVehicle) { VehicleDetails addVehicle = new VehicleDetails(); addVehicle = newVehicle.Vehicle; addVehicle.VehicleId = newVehicle.Vehicle.VehicleId; addVehicle.ModelName = dealerDb.CarModel.FirstOrDefault(m => m.ModelID == newVehicle.Vehicle.ModelName.ModelID); addVehicle.BodyName = dealerDb.BodyStyle.FirstOrDefault(b => b.BodyStyleId == newVehicle.Vehicle.BodyName.BodyStyleId); addVehicle.Color = newVehicle.Vehicle.Color; addVehicle.TransmissionType = dealerDb.Transmission.FirstOrDefault(t => t.TransmissionId == newVehicle.Vehicle.TransmissionType.TransmissionId); addVehicle.VehicleType = dealerDb.VehicleType.FirstOrDefault(y => y.VehicleTypeId == newVehicle.Vehicle.VehicleType.VehicleTypeId); addVehicle.ImageUrl = newVehicle.Vehicle.ImageUrl; addVehicle.IsSold = false; addVehicle.ImageUrl = newVehicle.Vehicle.ImageUrl; dealerDb.VehicleDetails.Add(addVehicle); dealerDb.SaveChanges(); }