public NewVehiclePage()
        {
            InitializeComponent();

            PlateEntry.Keyboard = Keyboard.Create(KeyboardFlags.CapitalizeCharacter);

            BindingContext = new NewVehicleViewModel();
        }
Beispiel #2
0
        public ActionResult Add()
        {
            var model = new NewVehicleViewModel();

            model.SetMakes(repo.GetAllMakes());
            model.SetModels(repo.GetAllModels());
            model.SetPurchaseTypes(repo.GetAllPurchaseTypes());
            return(View(model));
        }
Beispiel #3
0
        public ActionResult Add(NewVehicleViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Image != null)
                {
                    string picture = Path.GetFileName(model.Image.FileName);
                    string imgPath = Path.Combine(Server.MapPath("~/Images/"), picture);

                    model.Image.SaveAs(imgPath);
                }

                if (model.SalePrice > model.MSRP)
                {
                    ModelState.AddModelError("SalePrice", "Sale price cannot exceed MSRP");
                }

                Vehicle newVehicle = new Vehicle
                {
                    VehicleId = model.VehicleId,
                    Vin       = model.VIN,
                    Year      = model.Year,
                    BodyStyle = model.BodyStyle,
                    Model     = model.GetModel,
                    //Model=new VehicleModel
                    //{
                    //    VehicleModelId = model.GetModel.VehicleModelId,
                    //},
                    Image            = "http://localhost:53012/Images/" + model.Image.FileName,
                    Color            = model.Color,
                    InteriorColor    = model.InteriorColor,
                    Odometer         = model.Odometer,
                    MSRP             = model.MSRP,
                    SalePrice        = model.SalePrice,
                    TransmissionType = model.TransmissionType,
                    Description      = model.Description,
                    VehicleFeatured  = model.Featured,
                    VehicleIsNew     = model.IsNew,
                };
                repo.AddVehicle(newVehicle);
                return(RedirectToAction("Admin"));
            }
            else
            {
                return(View(model));
            }
        }
        public IActionResult Create([FromForm] NewVehicleViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_Create", new NewVehicleViewModel()));
            }

            try
            {
                vehicleService.Add(viewModel.Name,
                                   viewModel.Type,
                                   viewModel.RegistrationNumber,
                                   viewModel.MaximCarryWeight,
                                   viewModel.VIN);
                return(PartialView("_Create", new NewVehicleViewModel()));
            }
            catch (Exception e)
            {
                logger.LogError("Failed to create a new vehicle {@Exception}", e.Message);
                logger.LogDebug("Failed to create a new vehicle {@ExceptionMessage}", e);
                return(BadRequest(e.Message));
            }
        }
 public ActionResult Create(NewVehicleViewModel vm)
 {
     return(View());
 }