Beispiel #1
0
        public ActionResult Purchase(PurchaseAddViewModel vm)
        {
            var adminManager = AdminManagerFactory.GetManager();
            var vehicleRepo  = VehicleRepositoryFactory.GetRepository();

            vm.VehicleDetail = vehicleRepo.GetDetailById(vm.VehicleDetail.VehicleId);

            if (ModelState.IsValid)
            {
                vm.Sale.UserId = User.Identity.GetUserId();
                adminManager.Purchase(vm.VehicleDetail, vm.Sale, vm.Customer);

                return(RedirectToAction("Index"));
            }
            else
            {
                var stateRepo = StateRepositoryFactory.GetRepository();
                vehicleRepo = VehicleRepositoryFactory.GetRepository();

                vm.States        = new SelectList(stateRepo.GetAll(), "StateId", "Name");
                vm.VehicleDetail = vehicleRepo.GetDetailById(vm.VehicleDetail.VehicleId);

                return(View(vm));
            }
        }
Beispiel #2
0
        public ActionResult Purchase(int id)
        {
            PurchaseViewModel model = new PurchaseViewModel();
            var repo      = VehicleDetailRepositoryFactory.GetRepository();
            var stateRepo = StateRepositoryFactory.GetRepository();
            var typeRepo  = PurchaseTypeRepositoryFactory.GetRepository();

            model.Vehicle       = repo.GetDetail(id);
            model.States        = stateRepo.GetAll();
            model.PurchaseTypes = typeRepo.GetAll();
            return(View(model));
        }
Beispiel #3
0
        public ActionResult Purchase(int id)
        {
            var vehicleRepo = VehicleRepositoryFactory.GetRepository();
            var stateRepo   = StateRepositoryFactory.GetRepository();
            var vm          = new PurchaseAddViewModel();

            vm.States          = new SelectList(stateRepo.GetAll(), "StateId", "Name");
            vm.VehicleDetail   = vehicleRepo.GetDetailById(id);
            vm.Customer.UserId = User.Identity.GetUserId();

            return(View(vm));
        }
Beispiel #4
0
        public ActionResult PurchaseVehicle(int id)
        {
            var model = new PurchasedViewModel();

            var stateRepo   = StateRepositoryFactory.GetRepository();
            var vehicleRepo = VehicleRepositoryFactory.GetRepository();

            model.States   = new SelectList(stateRepo.GetAll(), "StateId", "StateName");
            model.vehicles = vehicleRepo.GetById(id);

            return(View(model));
        }
Beispiel #5
0
        public ActionResult Purchase(int id)
        {
            if (Request.IsAuthenticated)
            {
                ViewBag.UserID = AuthorizeUtilities.GetUserId(this);
            }

            var repo      = VehicleRepositoryFactory.GetRepository();
            var staterepo = StateRepositoryFactory.GetRepository();
            var model     = new PurchaseAddViewModel();

            model.VehicleDetails     = repo.GetDetails(id);
            model.Purchase.VehicleID = id;
            model.SetStateItems(staterepo.GetAll());
            return(View(model));
        }
Beispiel #6
0
        public ActionResult Purchase(PurchaseAddViewModel model)
        {
            if (Request.IsAuthenticated)
            {
                model.Purchase.UserID = AuthorizeUtilities.GetUserId(this);
            }

            if (ModelState.IsValid)
            {
                var customerRepo = CustomerRepositoryFactory.GetRepository();
                var purchaseRepo = PurchaseRepositoryFactory.GetRepository();
                try
                {
                    customerRepo.Insert(model.Customer);

                    model.Purchase.CustomerID = model.Customer.CustomerID;
                    model.Purchase.VehicleID  = model.VehicleDetails.VehicleID;

                    purchaseRepo.Insert(model.Purchase);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var repo      = VehicleRepositoryFactory.GetRepository();
                var staterepo = StateRepositoryFactory.GetRepository();

                model.VehicleDetails     = repo.GetDetails(model.VehicleDetails.VehicleID);
                model.Purchase.VehicleID = model.VehicleDetails.VehicleID;
                model.SetStateItems(staterepo.GetAll());

                return(View(model));
            }
        }