Exemplo n.º 1
0
        public ActionResult EditVehicle(int id)
        {
            IVehicleRepository repo = RepoFactory.CreateVehicleRepo();
            var vehicle             = repo.GetById(id);

            AdminEditVehicleViewModel model = new AdminEditVehicleViewModel()
            {
                ModelName = vehicle.Model,
                MakeName  = vehicle.Make,
                Vehicle   = new Vehicle()
                {
                    Color        = vehicle.Color,
                    Description  = vehicle.Description,
                    Interior     = vehicle.Interior,
                    Mileage      = vehicle.Mileage,
                    MSRP         = vehicle.MSRP,
                    SalePrice    = vehicle.SalePrice,
                    Style        = vehicle.Style,
                    Transmission = vehicle.Transmission,
                    VehicleId    = vehicle.VehicleId,
                    Type         = vehicle.Type,
                    Vin          = vehicle.Vin,
                    Year         = vehicle.Year
                }
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult EditVehicle(int id)
        {
            AdminEditVehicleViewModel vm = new AdminEditVehicleViewModel();

            //Vehicle = storedproc to get specific vehicle from db using the vehicle id from the edit button on index page
            vm.Vehicle = new Vehicle
            {
                Id          = 1,
                Make        = "Ford",
                Model       = "F150",
                Year        = 2015,
                Image       = "/Content/Cars/2014FordTaurus.jpg",
                IsNew       = true,
                BodyStyle   = "Truck",
                Trans       = "Automatic",
                Color       = "Black",
                Interior    = "Leather",
                Mileage     = 0,
                VinNumber   = "1HGCM82633A004352",
                SalePrice   = 25000,
                MSRP        = 27500,
                Description = "Runs Great, Leather Interior, Vroom",
                IsFeatured  = false,
                InStock     = true
            };
            return(View(vm));
        }
Exemplo n.º 3
0
        public ActionResult EditVehicle(AdminEditVehicleViewModel model)
        {
            IVehicleRepository repo = RepoFactory.CreateVehicleRepo();

            if (model.Delete)
            {
                repo.RemoveFeatured(model.Vehicle.VehicleId);
                repo.Delete(model.Vehicle.VehicleId);
                return(RedirectToAction("Index"));
            }
            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)
            {
                repo.Update(model.Vehicle);
                if (model.Image != null)
                {
                    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-" + model.Vehicle.VehicleId + ".jpg", FileMode.Create))
                    {
                        fs.Write(imageByte, 0, imageByte.Length);
                    }
                }
                if (model.Feature)
                {
                    repo.RemoveFeatured(model.Vehicle.VehicleId);
                    repo.AddFeatured(model.Vehicle.VehicleId);
                }
                else
                {
                    repo.RemoveFeatured(model.Vehicle.VehicleId);
                }
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }