Exemplo n.º 1
0
        public ActionResult PostPurchase(PurchaseAddViewModel pviewmodel)
        {
            var carId = pviewmodel.Car.CarId;

            //var carId = 4;

            var purchase = pviewmodel.Purchase;

            var contact = pviewmodel.Contact;

            var currentUser = User.Identity.GetUserName();

            if (!ModelState.IsValid)
            {
                //return BadRequest(ModelState);
            }

            List <Purchase> ids = new List <Purchase>();

            ids = GuildCarsRepositoryFactory.GetRepository().GetPurchaseIds();

            int purchaseId = ids.Max(x => x.PurchaseId) + 1;

            GuildCarsRepositoryFactory.GetRepository().AddPurchase(purchase, currentUser);
            GuildCarsRepositoryFactory.GetRepository().ContactInsert1(contact, purchaseId);
            GuildCarsRepositoryFactory.GetRepository().UpdatePurchaseStatus(carId, purchaseId);
            //db.SaveChanges();

            var model = GuildCarsRepositoryFactory.GetRepository().GetAll();

            return(View("Index", model));
            //return Created($"api/Dvds1/{dvd.DvdId})", dvd);
            //return null;
            //return CreatedAtRoute("DefaultApi", new { id = dvd.DvdId }, dvd);
        }
Exemplo n.º 2
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));
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        public ActionResult Purchase(int id)
        {
            var cardetails = GuildCarsRepositoryFactory.GetRepository().GetById(id);

            ViewBag.carid = cardetails.CarId;

            var model = new PurchaseAddViewModel();

            var Repo = GuildCarsRepositoryFactory.GetRepository();

            model.States        = new SelectList(Repo.GetStates(), "StateId", "StateName");
            model.PurchaseTypes = new SelectList(Repo.GetPurchaseTypes(), "PurchaseTypeId", "PurchaseTypeName");
            model.Car           = cardetails;
            model.Purchase      = new Purchase();
            model.Contact       = new Contact();

            return(View(model));
        }
Exemplo n.º 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));
            }
        }