Exemplo n.º 1
0
        public ActionResult AddVehicle(VehicleViewModel model)
        {
            if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
            {
                model.Vehicle.Image = model.ImageUpload.FileName.ToString();
            }
            if (ModelState.IsValid)
            {
                model.Vehicle.UserName = User.Identity.GetUserName();

                var vehicleRepo = VehicleRepositoryFactory.GetRepository();

                vehicleRepo.Add(model.Vehicle);
                return(View("Vehicles"));
            }
            else
            {
                var makeRepo  = MakeRepositoryFactory.GetRepository();
                var modelRepo = ModelRepositoryFactory.GetRepository();
                var bodyRepo  = BodyStyleRepositoryFactory.GetRepository();
                var transRepo = TransmissionRepositoryFactory.GetRepository();
                var colorRepo = ColorRepositoryFactory.GetRepository();
                model.Makes      = makeRepo.GetLookup();
                model.Models     = modelRepo.GetLookup();
                model.DropDowns  = VehicleTypeLookupmodel.NewUsedDropDownList();
                model.BodyStyles = bodyRepo.GetAll();
                model.Trans      = transRepo.GetAll();
                model.Colors     = colorRepo.GetAll();
                return(View(model));
            }
        }
Exemplo n.º 2
0
        public ActionResult EditVehicle(int id)
        {
            var vehicleRepo        = VehicleRepositoryFactory.GetRepository();
            var makeRepo           = MakeRepositoryFactory.GetRepository();
            var modelRepo          = ModelRepositoryFactory.GetRepository();
            var bodyRepo           = BodyStyleRepositoryFactory.GetRepository();
            var transRepo          = TransmissionRepositoryFactory.GetRepository();
            var colorRepo          = ColorRepositoryFactory.GetRepository();
            VehicleViewModel model = new VehicleViewModel();

            model.Vehicle    = vehicleRepo.GetByID(id);
            model.Makes      = makeRepo.GetLookup();
            model.Models     = modelRepo.GetLookupByMake(model.Vehicle.MakeID);
            model.DropDowns  = VehicleTypeLookupmodel.NewUsedDropDownList();
            model.BodyStyles = bodyRepo.GetAll();
            model.Trans      = transRepo.GetAll();
            model.Colors     = colorRepo.GetAll();


            if (ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                return(View("Vehicles"));
            }
        }
Exemplo n.º 3
0
        public ActionResult EditVehicle(int id)
        {
            var model = new VehicleEditVM();

            var makeRepo          = MakeRepositoryFactory.GetRepository();
            var modelRepo         = ModelRepositoryFactory.GetRepository();
            var bodyStyleRepo     = BodyStyleRepositoryFactory.GetRepository();
            var transRepo         = TransmissionRepositoryFactory.GetRepository();
            var bodyColorRepo     = BodyColorRepositoryFactory.GetRepository();
            var interiorColorRepo = InteriorColorRepositoryFactory.GetRepository();
            var vehicleRepo       = VehicleRepositoryFactory.GetRepository();

            model.Vehicle = vehicleRepo.GetbyId(id);

            model.Make          = new SelectList(makeRepo.GetAll(), "MakeID", "MakeName");
            model.Model         = new SelectList(modelRepo.GetAll(), "ModelID", "ModelName");
            model.BodyStyle     = new SelectList(bodyStyleRepo.GetAll(), "BodyStyleID", "BodyDescription");
            model.Transmission  = new SelectList(transRepo.GetAll(), "TransmissionID", "Gears");
            model.BodyColor     = new SelectList(bodyColorRepo.GetAll(), "BodyColorID", "BodyColorName");
            model.InteriorColor = new SelectList(interiorColorRepo.GetAll(), "InteriorColorID", "InteriorColorName");

            var yearList = vehicleRepo.CreateSearchYears();

            model.Years = yearList.ConvertAll(a =>
            {
                return(new SelectListItem()
                {
                    Text = a.ToString(),
                    Value = a.ToString(),
                    Selected = false
                });
            });

            return(View(model));
        }
Exemplo n.º 4
0
 public HomeController()
 {
     _carsRepo                  = CarRepositoryFactory.GetRepository();
     _specialsRepo              = SpecialsRepositoryFactory.GetRepository();
     _makeRepo                  = MakeRepositoryFactory.GetRepository();
     _modelRepo                 = ModelRepositoryFactory.GetRepository();
     _colorRepo                 = ColorRepositoryFactory.GetRepository();
     _bodyStyleRepository       = BodyStyleRepositoryFactory.GetRepository();
     _transmissionRepository    = TransmissionRepositoryFactory.GetRepository();
     _customerContactRepository = CustomerContactRepositoryFactory.GetRepository();
 }
Exemplo n.º 5
0
 public AdminController()
 {
     _carsRepo                  = CarRepositoryFactory.GetRepository();
     _specialsRepo              = SpecialsRepositoryFactory.GetRepository();
     _makeRepo                  = MakeRepositoryFactory.GetRepository();
     _modelRepo                 = ModelRepositoryFactory.GetRepository();
     _colorRepo                 = ColorRepositoryFactory.GetRepository();
     _bodyStyleRepository       = BodyStyleRepositoryFactory.GetRepository();
     _transmissionRepository    = TransmissionRepositoryFactory.GetRepository();
     _customerContactRepository = CustomerContactRepositoryFactory.GetRepository();
     _purchaseLogRepository     = PurchaseLogRepositoryFactory.GetRepository();
     _userRepository            = UserRepositoryFactory.GetRepository();
 }
Exemplo n.º 6
0
        public ActionResult AddVehicle()
        {
            VehicleViewModel model = new VehicleViewModel();
            var makeRepo           = MakeRepositoryFactory.GetRepository();
            var modelRepo          = ModelRepositoryFactory.GetRepository();
            var bodyRepo           = BodyStyleRepositoryFactory.GetRepository();
            var transRepo          = TransmissionRepositoryFactory.GetRepository();
            var colorRepo          = ColorRepositoryFactory.GetRepository();

            model.Makes      = makeRepo.GetLookup();
            model.Models     = modelRepo.GetLookup();
            model.DropDowns  = VehicleTypeLookupmodel.NewUsedDropDownList();
            model.BodyStyles = bodyRepo.GetAll();
            model.Trans      = transRepo.GetAll();
            model.Colors     = colorRepo.GetAll();
            return(View(model));
        }
Exemplo n.º 7
0
        public ActionResult EditVehicle(VehicleEditVM model)
        {
            if (ModelState.IsValid)
            {
                var repo = VehicleRepositoryFactory.GetRepository();

                try
                {
                    var oldVehicle = repo.GetbyId(model.Vehicle.VehicleID);

                    if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
                    {
                        var savepath = Server.MapPath("~/Images");

                        string extension = Path.GetExtension(model.ImageUpload.FileName);
                        string fileName  = "inventory-" + model.Vehicle.VehicleID.ToString();
                        var    filePath  = Path.Combine(savepath, fileName + extension);

                        model.ImageUpload.SaveAs(filePath);
                        model.Vehicle.ImageFileName = Path.GetFileName(filePath);

                        var oldPath = Path.Combine(savepath, oldVehicle.ImageFileName);
                        if (System.IO.File.Exists(oldPath))
                        {
                            System.IO.File.Delete(oldPath);
                        }
                    }
                    else
                    {
                        model.Vehicle.ImageFileName = oldVehicle.ImageFileName;
                    }

                    model.Vehicle.SaleStatus = oldVehicle.SaleStatus;
                    repo.Update(model.Vehicle);

                    return(RedirectToAction("EditVehicle", new { id = model.Vehicle.VehicleID }));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var makeRepo          = MakeRepositoryFactory.GetRepository();
                var modelRepo         = ModelRepositoryFactory.GetRepository();
                var bodyStyleRepo     = BodyStyleRepositoryFactory.GetRepository();
                var transRepo         = TransmissionRepositoryFactory.GetRepository();
                var bodyColorRepo     = BodyColorRepositoryFactory.GetRepository();
                var interiorColorRepo = InteriorColorRepositoryFactory.GetRepository();
                var vehicleRepo       = VehicleRepositoryFactory.GetRepository();

                model.Make          = new SelectList(makeRepo.GetAll(), "MakeID", "MakeName");
                model.Model         = new SelectList(modelRepo.GetAll(), "ModelID", "ModelName");
                model.BodyStyle     = new SelectList(bodyStyleRepo.GetAll(), "BodyStyleID", "BodyDescription");
                model.Transmission  = new SelectList(transRepo.GetAll(), "TransmissionID", "Gears");
                model.BodyColor     = new SelectList(bodyColorRepo.GetAll(), "BodyColorID", "BodyColorName");
                model.InteriorColor = new SelectList(interiorColorRepo.GetAll(), "InteriorColorID", "InteriorColorName");

                var yearList = vehicleRepo.CreateSearchYears();

                model.Years = yearList.ConvertAll(a =>
                {
                    return(new SelectListItem()
                    {
                        Text = a.ToString(),
                        Value = a.ToString(),
                        Selected = false
                    });
                });
                return(View(model));
            }
        }