예제 #1
0
        // GET: Inventory
        public ActionResult Details(int id)
        {
            var repo  = CarRepositoryFactory.GetRepository();
            var model = repo.GetById(id);

            return(View(model));
        }
예제 #2
0
        public ActionResult EditVehicle(int id)
        {
            var model = new EditVehicleViewModel();

            var carRepo       = CarRepositoryFactory.GetRepository();
            var makeModelRepo = MakeModelRepositoryFactory.GetRepository();

            model.Car           = carRepo.GetById(id);
            model.CarMakeName   = new SelectList(makeModelRepo.GetMakes(), "CarMakeId", "CarMakeName");
            model.CarModelName  = new SelectList(makeModelRepo.GetModelByMake(model.Car.CarMakeId), "CarModelId", "CarModelName");
            model.CategoryName  = new SelectList(carRepo.GetCarCategory(), "CategoryId", "CategoryName");
            model.BodyStyle     = new SelectList(carRepo.GetBodyStyle(), "BodyStyle", "BodyStyle");
            model.Transmission  = new SelectList(carRepo.GetTransmission(), "Transmission", "Transmission");
            model.CarColor      = new SelectList(carRepo.GetCarColor(), "CarColor", "CarColor");
            model.InteriorColor = new SelectList(carRepo.GetInteriorColor(), "InteriorColor", "InteriorColor");
            if (model.IsSold == null)
            {
                model.IsSold = false;
            }
            if (model.IsFeatured == null)
            {
                model.IsFeatured = false;
            }
            else
            {
                model.IsFeatured = true;
            }

            return(View(model));
        }
예제 #3
0
        public IHttpActionResult SearchAdminInventory(decimal?minPrice, decimal?maxPrice, int?carYear, int?minYear,
                                                      int?maxYear, string carMakeName, string carModelName)
        {
            var repo = CarRepositoryFactory.GetRepository();

            try
            {
                var parameters = new CarSearchParameters()
                {
                    MinPrice     = minPrice,
                    MaxPrice     = maxPrice,
                    CarYear      = carYear,
                    MinYear      = minYear,
                    MaxYear      = maxYear,
                    CarMakeName  = carMakeName,
                    CarModelName = carModelName
                };

                var result = repo.SearchAll(parameters);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #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();
 }
예제 #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();
 }
예제 #6
0
        public ActionResult Index()
        {
            HomePromoViewModel model = new HomePromoViewModel();

            model.CarDetails = CarRepositoryFactory.GetRepository().GetFeatured();
            model.Promo      = PromoRepositoryFactory.GetRepository().GetAll();

            if (model != null)
            {
                return(View(model));
            }

            return(View());
        }
예제 #7
0
        public ActionResult DeleteVehicle(int carId)
        {
            var repo    = CarRepositoryFactory.GetRepository();
            var vehicle = repo.GetById(carId);

            repo.Delete(carId);
            string path = Path.Combine(Server.MapPath("~/Images/"),
                                       Path.GetFileName(vehicle.ImageFileName));

            System.IO.File.Delete(path);

            TempData["Message"] = "Vehicle and associated image have been removed.";
            return(RedirectToAction("Vehicles"));
        }
        public ActionResult Purchase(int id)
        {
            if (Request.IsAuthenticated)
            {
                var userMgr = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

                var user = userMgr.FindByName(User.Identity.Name);

                ViewBag.UserName = user.UserName;
            }

            SalesPurchaseViewModel model = new SalesPurchaseViewModel();
            var carRepo       = CarRepositoryFactory.GetRepository();
            var inventoryRepo = InventoryRepositoryFactory.GetRepository();

            model.Car          = carRepo.GetById(id);
            model.SalesInvoice = new SalesInvoice();
            model.States       = new SelectList(inventoryRepo.GetStates(), "StateId", "State");
            model.PurchaseType = new SelectList(inventoryRepo.GetPurchaseTypes(), "PurchaseTypeId", "PurchaseTypeName");

            return(View(model));
        }
예제 #9
0
        private AddVehicleViewModel GetAddVehicleModel(AddVehicleViewModel model)
        {
            var carRepo       = CarRepositoryFactory.GetRepository();
            var makeModelRepo = MakeModelRepositoryFactory.GetRepository();

            model.Car           = new Car();
            model.CarMakeName   = new SelectList(makeModelRepo.GetMakes(), "CarMakeId", "CarMakeName");
            model.CarModelName  = new SelectList(makeModelRepo.GetModels(), "CarModelId", "CarModelName");
            model.CategoryName  = new SelectList(carRepo.GetCarCategory(), "CategoryId", "CategoryName");
            model.BodyStyle     = new SelectList(carRepo.GetBodyStyle(), "BodyStyle", "BodyStyle");
            model.Transmission  = new SelectList(carRepo.GetTransmission(), "Transmission", "Transmission");
            model.CarColor      = new SelectList(carRepo.GetCarColor(), "CarColor", "CarColor");
            model.InteriorColor = new SelectList(carRepo.GetInteriorColor(), "InteriorColor", "InteriorColor");
            if (model.IsSold == null)
            {
                model.IsSold = false;
            }
            if (model.IsFeatured == null)
            {
                model.IsFeatured = false;
            }

            return(model);
        }
예제 #10
0
        public ActionResult Used()
        {
            var repo = CarRepositoryFactory.GetRepository();

            return(View(repo.GetDetails()));
        }
예제 #11
0
 public InventoryController()
 {
     _carsRepo = CarRepositoryFactory.GetRepository();
 }
예제 #12
0
        public ActionResult EditVehicle(EditVehicleViewModel model)
        {
            var repo = CarRepositoryFactory.GetRepository();

            int     carMileage;
            decimal carSalePrice;
            int     carYear;
            decimal msrp;

            if (!Decimal.TryParse(model.Car.CarPrice.ToString(), out msrp))
            {
                ModelState.AddModelError("Car.CarPrice",
                                         "Please enter a valid number.");
            }
            if (!Int32.TryParse(model.Car.Mileage.ToString(), out carMileage))
            {
                ModelState.AddModelError("Car.Mileage",
                                         "Please enter a valid number.");
            }
            if (!Decimal.TryParse(model.Car.CarSalePrice.ToString(), out carSalePrice))
            {
                ModelState.AddModelError("Car.CarSalePrice",
                                         "Please enter a valid number.");
            }
            if (!Int32.TryParse(model.Car.CarYear.ToString(), out carYear))
            {
                ModelState.AddModelError("Car.CarYear",
                                         "Please enter a valid number.");
            }
            if (model.Car.CarYear.ToString().Length < 4)
            {
                ModelState.AddModelError("Car.CarYear",
                                         "Please enter a four digit year.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var oldCar = repo.GetById(model.Car.CarId);

                    if (model.IsSold == null)
                    {
                        model.Car.IsSold = false;
                    }

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

                        string fileName  = Path.GetFileNameWithoutExtension("inventory");
                        string extension = Path.GetExtension(model.ImageUpload.FileName);
                        if (extension != "png" || extension != "jpg" || extension != "jpeg")
                        {
                            ModelState.AddModelError("Car.ImageFileName",
                                                     "Please upload a png, jpg, or jpeg file.");
                        }

                        var filePath = Path.Combine(savepath, fileName + model.Car.CarId + extension);

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

                        // delete old file
                        var oldPath = Path.Combine(savepath, oldCar.ImageFileName);
                        if (System.IO.File.Exists(oldPath))
                        {
                            System.IO.File.Delete(oldPath);
                        }
                    }
                    else
                    {
                        // they did not replace the old file, so keep the old file name
                        model.Car.ImageFileName = oldCar.ImageFileName;
                    }

                    repo.Update(model.Car);

                    TempData["Message"] = "Vehicle has been saved.";
                    return(RedirectToAction("EditVehicle", new { id = model.Car.CarId }));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var carRepo       = CarRepositoryFactory.GetRepository();
                var makeModelRepo = MakeModelRepositoryFactory.GetRepository();

                model.Car           = carRepo.GetById(model.Car.CarId);
                model.CarMakeName   = new SelectList(makeModelRepo.GetMakes(), "CarMakeId", "CarMakeName");
                model.CarModelName  = new SelectList(makeModelRepo.GetModelByMake(model.Car.CarMakeId), "CarModelId", "CarModelName");
                model.CategoryName  = new SelectList(carRepo.GetCarCategory(), "CategoryId", "CategoryName");
                model.BodyStyle     = new SelectList(carRepo.GetBodyStyle(), "BodyStyle", "BodyStyle");
                model.Transmission  = new SelectList(carRepo.GetTransmission(), "Transmission", "Transmission");
                model.CarColor      = new SelectList(carRepo.GetCarColor(), "CarColor", "CarColor");
                model.InteriorColor = new SelectList(carRepo.GetInteriorColor(), "InteriorColor", "InteriorColor");
                if (model.IsSold == null)
                {
                    model.IsSold = false;
                }
                if (model.IsFeatured == null)
                {
                    model.IsFeatured = false;
                }
                else
                {
                    model.IsFeatured = true;
                }

                return(View(model));
            }
        }
예제 #13
0
        public ActionResult AddVehicle(AddVehicleViewModel model)
        {
            var repo = CarRepositoryFactory.GetRepository();

            int     carMileage;
            decimal carSalePrice;
            int     carYear;
            decimal msrp;

            if (!Decimal.TryParse(model.Car.CarPrice.ToString(), out msrp))
            {
                ModelState.AddModelError("Car.CarPrice",
                                         "Please enter a valid number.");
            }
            if (!Int32.TryParse(model.Car.Mileage.ToString(), out carMileage))
            {
                ModelState.AddModelError("Car.Mileage",
                                         "Please enter a valid number.");
            }
            if (!Decimal.TryParse(model.Car.CarSalePrice.ToString(), out carSalePrice))
            {
                ModelState.AddModelError("Car.CarSalePrice",
                                         "Please enter a valid number.");
            }
            if (!Int32.TryParse(model.Car.CarYear.ToString(), out carYear))
            {
                ModelState.AddModelError("Car.CarYear",
                                         "Please enter a valid number.");
            }
            if (model.Car.CarYear.ToString().Length < 4)
            {
                ModelState.AddModelError("Car.CarYear",
                                         "Please enter a four digit year.");
            }
            if (model.Car.CarYear < 2000 || model.Car.CarYear > DateTime.Now.Year + 1)
            {
                ModelState.AddModelError("Car.CarYear",
                                         "Car year can not be less than year 2000 or greater than next year.");
            }
            if (model.ImageUpload == null)
            {
                ModelState.AddModelError("Car.ImageFileName",
                                         "Please upload an image of the vehicle.");
            }
            if ((model.Car.CategoryId == 2) && (model.Car.CarYear >= DateTime.Now.Year))
            {
                if (model.Car.Mileage > 1000)
                {
                    ModelState.AddModelError("Car.Mileage",
                                             "Mileage must be below 1000 miles for new vehicles.");
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.IsSold == null)
                    {
                        model.Car.IsSold = false;
                    }
                    if (model.IsFeatured == null)
                    {
                        model.IsFeatured = false;
                    }

                    repo.Insert(model.Car);

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

                        string fileName  = Path.GetFileNameWithoutExtension("inventory");
                        string extension = Path.GetExtension(model.ImageUpload.FileName);
                        if (extension != "png" || extension != "jpg" || extension != "jpeg")
                        {
                            ModelState.AddModelError("Car.ImageFileName",
                                                     "Please upload a png, jpg, or jpeg file.");
                        }
                        var filePath = Path.Combine(savepath, fileName + model.Car.CarId + extension);

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

                    repo.Update(model.Car);

                    TempData["Message"] = "New vehicle has been added.";
                    return(RedirectToAction("EditVehicle", new { id = model.Car.CarId }));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var carRepo       = CarRepositoryFactory.GetRepository();
                var makeModelRepo = MakeModelRepositoryFactory.GetRepository();

                model.Car           = new Car();
                model.CarMakeName   = new SelectList(makeModelRepo.GetMakes(), "CarMakeId", "CarMakeName");
                model.CarModelName  = new SelectList(makeModelRepo.GetModels(), "CarModelId", "CarModelName");
                model.CategoryName  = new SelectList(carRepo.GetCarCategory(), "CategoryId", "CategoryName");
                model.BodyStyle     = new SelectList(carRepo.GetBodyStyle(), "BodyStyle", "BodyStyle");
                model.Transmission  = new SelectList(carRepo.GetTransmission(), "Transmission", "Transmission");
                model.CarColor      = new SelectList(carRepo.GetCarColor(), "CarColor", "CarColor");
                model.InteriorColor = new SelectList(carRepo.GetInteriorColor(), "InteriorColor", "InteriorColor");
                if (model.IsSold == null)
                {
                    model.IsSold = false;
                }
                if (model.IsFeatured == null)
                {
                    model.IsFeatured = false;
                }

                return(View(model));
            }
        }
예제 #14
0
        public ActionResult Purchase(SalesPurchaseViewModel model)
        {
            var inventoryRepo = InventoryRepositoryFactory.GetRepository();
            var carRepo       = CarRepositoryFactory.GetRepository();

            decimal msrp;

            if (!Decimal.TryParse(model.SalesInvoice.Total.ToString(), out msrp))
            {
                ModelState.AddModelError("SalesInvoice.Total",
                                         "Please enter a valid number.");
            }
            if (model.SalesInvoice.Total < model.Car.CarSalePrice * (decimal)0.95)
            {
                ModelState.AddModelError("SalesInvoice.Total",
                                         "Purchase price cannot be less than 95% of sale price");
            }
            if (model.SalesInvoice.Total > model.Car.CarPrice)
            {
                ModelState.AddModelError("SalesInvoice.Total",
                                         "Purchase price cannot be greater than MSRP");
            }
            if ((string.IsNullOrEmpty(model.SalesInvoice.UserEmail)) && (string.IsNullOrEmpty(model.SalesInvoice.TelephoneNumber)))
            {
                ModelState.AddModelError("SalesInvoice.UserEmail",
                                         "Please enter an email address or phone number");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var preSale = carRepo.GetById(model.Car.CarId);

                    if (preSale.IsSold == false)
                    {
                        preSale.IsSold = true;
                    }

                    model.SalesInvoice.Car = preSale;
                    model.SalesInvoice.PurchaseTypeName = inventoryRepo.GetPurchaseTypeName(model.SalesInvoice.PurchaseTypeId);
                    model.SalesInvoice.State            = inventoryRepo.GetStateName(model.SalesInvoice.StateId);


                    var userMgr = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

                    var user = userMgr.FindByName(User.Identity.Name);

                    model.SalesInvoice.SalesPerson = user.FirstName + " " + user.LastName;
                    model.SalesInvoice.CarId       = model.SalesInvoice.Car.CarId;

                    carRepo.Update(model.SalesInvoice.Car);
                    inventoryRepo.Insert(model.SalesInvoice);


                    TempData["Message"] = "Thank you for your purchase.";
                    return(RedirectToAction("Purchase"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                if (Request.IsAuthenticated)
                {
                    var userMgr = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

                    var user = userMgr.FindByName(User.Identity.Name);

                    ViewBag.UserName = user.UserName;
                }

                model.Car          = carRepo.GetById(model.Car.CarId);
                model.SalesInvoice = new SalesInvoice();
                model.States       = new SelectList(inventoryRepo.GetStates(), "StateId", "State");
                model.PurchaseType = new SelectList(inventoryRepo.GetPurchaseTypes(), "PurchaseTypeId", "PurchaseTypeName");


                TempData["Message"] = "We were unable to complete your purchase.";
                return(View(model));
            }
        }