public async Task <ActionResult> Create(CreditModelView creditCard, string userId)
        {
            Boolean found = await CheckIfExist(creditCard.card.creditCardID);

            if (ModelState.IsValid && found != true)
            {
                string card10Digits = creditCard.card.creditCardID.Substring(0, 12);
                string card4Digits  = creditCard.card.creditCardID.Substring(12, 4);
                string hashedStr    = Utility.Encryption.CreateHash(card10Digits);

                creditCard.card.creditCardID = hashedStr + ":" + card4Digits;
                creditCard.card.userId       = userId;
                db.CreditCards.Add(creditCard.card);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            var model = new CreditModelView
            {
                card        = creditCard.card,
                creditTypes = Utility.Util.getCreditTypex(),
                months      = Utility.Util.getMonthx(),
                years       = Utility.Util.getYearx()
            };

            ModelState.AddModelError("", "Credit card with the same number already exist!");
            ViewBag.userId = userId;

            return(View(model));
        }
Beispiel #2
0
        public async Task <ActionResult> Create([Bind(Include = "id,brandName,pic")] CigarBrand cigarBrand)
        {
            if (ModelState.IsValid)
            {
                db.CigarBrands.Add(cigarBrand);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(cigarBrand));
        }
        public async Task <ActionResult> Create([Bind(Include = "wrapperName,color")] CigaresWrapper cigaresWrapper)
        {
            if (ModelState.IsValid)
            {
                db.CigaresWrapper.Add(cigaresWrapper);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(cigaresWrapper));
        }
        public async Task <ActionResult> Create([Bind(Include = "id,categoryName,pic")] AlcoholCategory alcoholCategory)
        {
            if (ModelState.IsValid)
            {
                db.AlcoholCategory.Add(alcoholCategory);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(alcoholCategory));
        }
Beispiel #5
0
        public async Task <ActionResult> CheckOut([Bind(Exclude = "creditCard")] CheckOut newHistory)
        {
            Cart myCart = (Cart)Session["Cart"];

            if (myCart.myCart.Count == 0)
            {
                return(View("Index"));
            }

            if (ModelState.IsValid)
            {
                Session["Cart"] = null;
                DateTime   today = DateTime.Now;
                AspNetUser user  = await Utility.Util.getUser(HttpContext.User);

                newHistory.history.bh.userId     = user.Id;
                newHistory.history.bh.buyingDate = today.ToString();

                db.BuyingHistory.Add(newHistory.history.bh);
                await db.SaveChangesAsync();

                BuyingHistory ttt = await db.BuyingHistory.OrderByDescending(i => i.buyingId).FirstOrDefaultAsync <BuyingHistory>();

                BuyingHistoryItem historyItem;

                foreach (CartItem p in myCart.myCart)
                {
                    historyItem          = new BuyingHistoryItem();
                    historyItem.buyingId = ttt.buyingId;
                    if (p.isBundle)
                    {
                        historyItem.productID = 1012;
                        historyItem.bundleId  = p.id;
                    }
                    else
                    {
                        historyItem.bundleId  = 3;
                        historyItem.productID = p.id;
                    }
                    historyItem.quantity              = p.quantity;
                    newHistory.history.bh.totalPrice += p.price * p.quantity;
                    db.BuyingHistoryItems.Add(historyItem);
                }
                db.Entry(newHistory.history.bh).State = EntityState.Modified;
                await db.SaveChangesAsync();

                //creditCard.card.userId = userId;

                return(RedirectToAction("Invoice", "BuyingHistories", new { id = ttt.buyingId }));
            }

            return(View(newHistory));
        }
Beispiel #6
0
        public async Task <ActionResult> Create([Bind(Include = "customerId,customerName,customerLastName,customerphoneNumber,customerCountry,customerCity")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.customerId      = new SelectList(db.AspNetUsers, "Id", "Email", customer.customerId);
            ViewBag.customerCountry = new SelectList(db.Country, "countryName", "pic", customer.customerCountry);
            return(View(customer));
        }
        public async Task <ActionResult> Create(AlcoholProduct alcoholProduct)
        {
            if (ModelState.IsValid)
            {
                Product newProdct = new Product();
                //newProdct.productName
                db.AlcoholProduct.Add(alcoholProduct);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.categoryID = new SelectList(db.AlcoholCategory, "id", "categoryName", alcoholProduct.categoryID);
            ViewBag.origin     = new SelectList(db.Country, "countryName", "countryName", alcoholProduct.origin);
            ViewBag.productID  = new SelectList(db.Product, "productID", "productName", alcoholProduct.productID);
            return(View(alcoholProduct));
        }
Beispiel #8
0
        public async Task <ActionResult> Create(CigaresProduct cigaresProduct)
        {
            if (ModelState.IsValid)
            {
                db.CigaresProducts.Add(cigaresProduct);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.cigarBrand  = new SelectList(db.CigarBrands, "id", "brandName", cigaresProduct.cigarBrand);
            ViewBag.wrapperType = new SelectList(db.CigaresWrapper, "wrapperName", "wrapperName", cigaresProduct.wrapperType);
            ViewBag.strengthID  = new SelectList(db.CigarStrengths, "id", "strengthName", cigaresProduct.strengthID);
            ViewBag.origin      = new SelectList(db.Country, "countryName", "countryName", cigaresProduct.origin);
            ViewBag.productID   = new SelectList(db.Product, "productID", "productName", cigaresProduct.productID);
            return(View(cigaresProduct));
        }
        public async Task <ActionResult> Create(Bundle bundle)
        {
            List <BundleInfo> bundleItems = (List <BundleInfo>)Session["BundleList"];

            if (bundleItems == null || bundleItems.Count == 0)
            {
                ModelState.AddModelError("", "Add items to bundle");
                return(View(bundle));
            }
            if (ModelState.IsValid)
            {
                BundleInfo item;
                db.Bundles.Add(bundle);
                await db.SaveChangesAsync();

                Bundle justAddedBundle = await db.Bundles.OrderByDescending(i => i.bundleId).FirstOrDefaultAsync <Bundle>();

                foreach (BundleInfo p in bundleItems)
                {
                    item           = new BundleInfo();
                    item.bundleId  = justAddedBundle.bundleId;
                    item.productID = p.productID;
                    item.quantity  = p.quantity;
                    db.BundleInfos.Add(item);
                }
                await db.SaveChangesAsync();

                Session["BundleList"] = null;
                return(RedirectToAction("Index"));
            }

            return(View(bundle));
        }
        public async Task <ActionResult> AddToWatchList(int pId, string isBundle)
        {
            AspNetUser user = await Utility.Util.getUser(HttpContext.User);

            Product p = await db.Product.FindAsync(pId);

            Bundle b = await db.Bundles.FindAsync(pId);

            WatchList wl = new WatchList();
            Boolean   found;

            wl.customerId = user.Id;

            if (isBundle.Equals("yes"))
            {
                wl.bundleId  = b.bundleId;
                wl.productID = 1012;

                found = await(from x in db.WatchList
                              where x.customerId == wl.customerId && x.bundleId == wl.bundleId
                              select x).AnyAsync();
            }
            else
            {
                wl.productID = p.productID;
                wl.bundleId  = 3;

                found = await(from x in db.WatchList
                              where x.customerId == wl.customerId && x.productID == wl.productID
                              select x).AnyAsync();
            }

            if (!found)
            {
                db.WatchList.Add(wl);
                await db.SaveChangesAsync();
            }

            return(RedirectToAction("Index"));
        }