Example #1
0
        public void CanInsertSales()
        {
            var repo = SalesFactory.GetSalesRepository();

            DateTime dateTime = DateTime.Now;

            var sale = new Sales()
            {
                Phone         = "8595478005",
                VehicleId     = 6,
                BuyerName     = "Randy Smith",
                Email         = "*****@*****.**",
                Street1       = "10854 War Drive",
                ZipCode       = 13456,
                City          = "Frankfort",
                StateName     = "KY",
                PurchasePrice = 12000,
                DatePurchased = dateTime,
                PurchaseType  = "Dealer Finance",
                UserId        = "000000-0000-0000-0000-000000"
            };

            repo.InsertSale(sale);

            var sales = SalesFactory.GetSalesRepository().GetAllSales();


            Assert.AreEqual(sales.Count(), 5);
        }
Example #2
0
        public void CanLoadSales()
        {
            var repo = SalesFactory.GetSalesRepository();

            var sales = repo.GetSales().ToList();

            Assert.AreEqual("Rad", sales[0].FirstName);
            Assert.AreEqual(4, sales[0].TotalVehicles);
            Assert.AreEqual(26500, sales[0].TotalSales);
        }
Example #3
0
        public void CanSearchSales()
        {
            var repo = SalesFactory.GetSalesRepository();

            var found = repo.GetSalesSearchResults(new SalesSearchParameters {
            }).ToList();

            Assert.AreEqual(1, found.Count());
            Assert.AreEqual("Rad", found[0].FirstName);
            Assert.AreEqual(26500, found[0].TotalSales);
            Assert.AreEqual(4, found[0].TotalVehicles);
        }
Example #4
0
        public void CanSearchSalesFromDate()
        {
            var repo = SalesFactory.GetSalesRepository();

            var parameters = new SalesSearchParameters {
                FromDate = DateTime.Parse("01/02/2015")
            };
            var found = repo.GetSalesSearchResults(parameters).ToList();

            Assert.AreEqual(1, found.Count());
            Assert.AreEqual("Rad", found[0].FirstName);
            Assert.AreEqual(20000, found[0].TotalSales);
            Assert.AreEqual(3, found[0].TotalVehicles);
        }
Example #5
0
        public void CanSearchSalesBetweenDates()
        {
            var repo = SalesFactory.GetSalesRepository();


            var parameters = new SalesSearchParameters {
                ToDate = DateTime.Parse("02/04/2016"), FromDate = DateTime.Parse("01/02/2009")
            };
            var found = repo.GetSalesSearchResults(parameters).ToList();

            Assert.AreEqual(1, found.Count());
            Assert.AreEqual("Joes", found[0].LastName);
            Assert.AreEqual(14500, found[0].TotalSales);
            Assert.AreEqual(2, found[0].TotalVehicles);
        }
        public IHttpActionResult GetSalesReport(string userName, string fromDate, string toDate)
        {
            var repo       = SalesFactory.GetSalesRepository();
            var parameters = new SalesSearchParameters();

            parameters.UserName = userName;

            var date = new DateTime();

            if (DateTime.TryParse(fromDate, out date))
            {
                parameters.FromDate = date;
            }
            else
            {
                parameters.FromDate = null;
            }

            date = new DateTime();

            if (DateTime.TryParse(toDate, out date))
            {
                parameters.ToDate = date;
            }
            else
            {
                parameters.ToDate = null;
            }

            try
            {
                var sales = repo.GetSalesSearchResults(parameters);

                if (sales.Count() != 0)
                {
                    return(Ok(sales));
                }
                else
                {
                    return(NotFound());
                }
            }

            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #7
0
        public ActionResult Purchase(PurchaseViewModel viewModel)
        {
            viewModel.Sale.MSRP       = viewModel.VehicleDetails.MSRP;
            viewModel.Sale.SalesPrice = viewModel.VehicleDetails.SalesPrice;

            if (ModelState.IsValid)
            {
                try
                {
                    var usrManger = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                    var user      = usrManger.FindByName(User.Identity.Name);

                    var salesRepo   = SalesFactory.GetSalesRepository();
                    var vehicleRepo = VehicleFactory.GetVehicleRepository();
                    var vehicle     = vehicleRepo.GetVehicle(viewModel.VehicleDetails.VehicleId);
                    vehicle.IsSold = true;

                    viewModel.Sale.VehicleId     = vehicle.VehicleId;
                    viewModel.Sale.DatePurchased = DateTime.Now;
                    viewModel.Sale.UserId        = user.Id;
                    salesRepo.InsertSale(viewModel.Sale);
                    vehicleRepo.UpdateVehicle(vehicle);


                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var viewModelReturn = new PurchaseViewModel();

                viewModelReturn.VehicleDetails = VehicleFactory.GetVehicleRepository().GetVehicleDetails(viewModel.VehicleDetails.VehicleId);
                TempData["MileageDisplay"]     = viewModel.VehicleDetails.Mileage.ToString("#,###");
                TempData["SalesPriceDisplay"]  = viewModel.VehicleDetails.SalesPrice.ToString("#,###");
                TempData["MSRPDisplay"]        = viewModel.VehicleDetails.MSRP.ToString("#,###");

                return(View(viewModelReturn));
            }
        }