Beispiel #1
0
        public ActionResult Details(int id)
        {
            var repo = InventoryRepositoryFactory.GetRepository();
            VehicleSearchResult model = repo.GetVehicleDetails(id);

            TempData["VIN"] = model.VehicleVIN;

            return(View(model));
        }
Beispiel #2
0
        public ActionResult Sales()
        {
            SalesReportViewModel model = new SalesReportViewModel();
            var repo = InventoryRepositoryFactory.GetRepository();

            model.SalesPerson = new SelectList(repo.SalesPersonSelectAll(), "SalesPerson", "SalesPerson");

            return(View(model));
        }
Beispiel #3
0
        private InventoryReportItem GetReportsInventoryModel(InventoryReportItem model)
        {
            var repo = InventoryRepositoryFactory.GetRepository();

            model.inventoryNew  = repo.GetNewVehicles();
            model.inventoryUsed = repo.GetUsedVehicles();

            return(model);
        }
Beispiel #4
0
        public ActionResult Inventory()
        {
            InventoryReportItem model = new InventoryReportItem();

            var repo = InventoryRepositoryFactory.GetRepository();

            model = GetReportsInventoryModel(model);

            return(View(model));
        }
Beispiel #5
0
        public ActionResult Inventory()
        {
            {
                var repo  = InventoryRepositoryFactory.GetRepository();
                var model = new InventoryReportViewModel();

                model.NewInventoryReport  = repo.CreateNewInventoryReport().ToList();
                model.UsedInventoryReport = repo.CreateUsedInventoryReport().ToList();

                return(View(model));
            }
        }
Beispiel #6
0
        public ActionResult Index()
        {
            var model = new HomeIndexViewModel();

            var repo1 = SpecialsRepositoryFactory.GetRepository();
            var repo2 = InventoryRepositoryFactory.GetRepository();

            model.SpecialsList     = repo1.GetAllSpecials().ToList();
            model.FeaturedVehicles = repo2.GetFeaturedVehicles().ToList();

            return(View(model));
        }
Beispiel #7
0
        public ActionResult Purchase(PurchaseVehicleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repo         = VehicleRepositoryFactory.GetRepository();
                var customerRepo = CustomersRepositoryFactory.GetRepository();
                var salesRepo    = SalesRepositoryFactory.GetRepository();
                var vehiclesRepo = VehicleRepositoryFactory.GetRepository();

                Vehicles vehicleToEdit = new Vehicles();

                try
                {
                    customerRepo.AddCustomer(model.Customer);

                    Sales addSale = new Sales();
                    addSale.CustomerId  = model.Customer.CustomerId;
                    addSale.VehicleId   = model.Vehicle.VehicleId;
                    addSale.FinancingId = model.Sale.FinancingId;
                    addSale.UserId      = AuthorizeUtilities.GetUserId(this);
                    addSale.SaleAmount  = model.Sale.SaleAmount;
                    addSale.SaleDate    = DateTime.Now;

                    salesRepo.AddSale(addSale);

                    vehicleToEdit = vehiclesRepo.SelectVehicle(model.Vehicle.VehicleId);
                    vehicleToEdit.VehicleIsFeatured = false;
                    vehiclesRepo.UpdateVehicle(vehicleToEdit);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var inventoryRepo = InventoryRepositoryFactory.GetRepository();
                var statesRepo    = StatesRepositoryFactory.GetRepository();
                var financingRepo = FinancingRepositoryFactory.GetRepository();

                model.Vehicle   = inventoryRepo.GetVehicleDetails(model.Vehicle.VehicleId);
                model.States    = new SelectList(statesRepo.GetAllStates(), "StateId", "StateId");
                model.Financing = new SelectList(financingRepo.GetAllFinancing(), "FinancingId", "FinancingDescription");

                return(View(model));
            }
        }
Beispiel #8
0
        public ActionResult Purchase(int id)
        {
            var model         = new PurchaseVehicleViewModel();
            var inventoryRepo = InventoryRepositoryFactory.GetRepository();
            var statesRepo    = StatesRepositoryFactory.GetRepository();
            var financingRepo = FinancingRepositoryFactory.GetRepository();

            model.Vehicle   = inventoryRepo.GetVehicleDetails(id);
            model.Customer  = new Customers();
            model.Sale      = new Sales();
            model.States    = new SelectList(statesRepo.GetAllStates(), "StateId", "StateId");
            model.Financing = new SelectList(financingRepo.GetAllFinancing(), "FinancingId", "FinancingDescription");

            return(View(model));
        }
Beispiel #9
0
        public IHttpActionResult SearchSalesReport(string salesPerson, DateTime?fromDate, DateTime?toDate)
        {
            var repo = InventoryRepositoryFactory.GetRepository();

            try
            {
                var parameters = new SalesReportSearchParameters()
                {
                    SalesPerson = salesPerson,
                    FromDate    = fromDate,
                    ToDate      = toDate
                };

                var result = repo.SearchSalesInvoices(parameters);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        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));
        }
Beispiel #11
0
        public IHttpActionResult SearchForInventory(string newUsed, string makeModelYear, decimal?minPrice, decimal?maxPrice, int?minYear, int?maxYear)
        {
            var repo = InventoryRepositoryFactory.GetRepository();

            try
            {
                var parameters = new VehicleSearchParameters()
                {
                    NewUsed       = newUsed,
                    MakeModelYear = makeModelYear,
                    MinPrice      = minPrice,
                    MaxPrice      = maxPrice,
                    MinYear       = minYear,
                    MaxYear       = maxYear
                };
                var result = repo.SearchInventory(parameters);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        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));
            }
        }