Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult SearchForSalesReport(string userId, string fromDate, string toDate)
        {
            var repo = SalesRepositoryFactory.GetRepository();

            try
            {
                var parameters = new SalesReportSearchParameters()
                {
                    UserId   = userId,
                    FromDate = fromDate,
                    ToDate   = toDate
                };
                var result = repo.GetSalesForReport(parameters);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }