示例#1
0
        public IActionResult Index()
        {
            Dictionary <int, int> lst = HttpContext.Session.Get <Dictionary <int, int> >("ls");

            if (lst != null && lst.TryGetValue(int.MinValue, out int v) && v == 1)
            {
                HttpContext.Session.Set("ls", new Dictionary <int, int>());
                lst = new Dictionary <int, int>();
            }
            if (lst != null)
            {
                if (orm == 1)
                {
                    List <Products> ls = new List <Products>();
                    foreach (int i in lst.Keys)
                    {
                        Products p = qdb.retProduct(i); ls.Add(p); qdb.include_pt_st(ls);
                        p.Price = lst[i] * p.Price;
                        ShoppingCardvm.Products.Add(p);
                        ls.Clear();
                    }
                }
                else
                {
                    foreach (int i in lst.Keys)
                    {
                        Products p = _db.Products.Include(e => e.ProductTypes).Include(e => e.SpecialTags)
                                     .FirstOrDefault(e => e.Id == i);
                        if (p != null)
                        {
                            p.Price = lst[i] * p.Price;
                        }
                        ShoppingCardvm.Products.Add(p);
                    }
                }

                //foreach (int i in lst.Keys)
                //{
                //    Products p = _db.Products.Include(e => e.ProductTypes).Include(e => e.SpecialTags)
                //        .FirstOrDefault(e => e.Id == i);
                //    p.Price = lst[i] * p.Price;
                //    ShoppingCardvm.Products.Add(p);
                //}
            }

            return(View(ShoppingCardvm));
        }
        public async Task <IActionResult> Index()
        {
            if (Convert.ToInt32(TempData["edit"]) == 1)
            {
                ViewBag.edit = true;
            }
            else if (Convert.ToInt32(TempData["delete"]) == 1)
            {
                ViewBag.delete = true;
            }
            else if (Convert.ToInt32(TempData["create"]) == 1)
            {
                ViewBag.create = true;
            }

            List <Products> product;

            if (orm == 1)
            {
                product = qdb.retProduct();
                qdb.include_pt_st(product);
            }
            else
            {
                product = await _db.Products.Include(m => m.SpecialTags).Include(m => m.ProductTypes).ToListAsync();
            }

            return(View(product));
        }
示例#3
0
        //[BindProperty]
        //public bool Error { get; set; }
        public IActionResult Index(ProductViewModelForList vm)
        {
            if (vm.tag == "All")
            {
                vm.tag          = null;
                TempData["tag"] = null;
            }
            if (vm.type == "All")
            {
                vm.type          = null;
                TempData["type"] = null;
            }
            if (TempData["tag"] != null)
            {
                vm.tag = TempData["tag"].ToString();
                TempData.Keep();
            }
            else
            {
                if (vm.tag != null)
                {
                    TempData["tag"] = vm.tag;
                    TempData.Keep();
                }
            }
            if (TempData["type"] != null)
            {
                vm.type = TempData["type"].ToString();
                TempData.Keep();
            }
            else
            {
                if (vm.type != null)
                {
                    TempData["type"] = vm.type;
                    TempData.Keep();
                }
            }

            //ProductViewModelForList vm = new ProductViewModelForList();
            //vm.tag = tag;
            //vm.type = type;
            if (TempData["congrats"] != null && Convert.ToInt32(TempData["congrats"]) == 1)
            {
                ViewBag.congrats     = true;
                TempData["congrats"] = null;
            }
            if (TempData["orm"] != null)
            {
                int o = Convert.ToInt32(TempData["orm"]);
                if (o == 1)
                {
                    ViewBag.orm = 0;
                }
                else
                {
                    ViewBag.orm = 0;
                }
            }
            bool tagg = true, typee = true;

            if (vm.tag == null)
            {
                tagg = false;
            }
            if (vm.type == null)
            {
                typee = false;
            }

            List <Products> temp = null;

            if (orm == 1)
            {
                temp = qdb.retProduct();
                qdb.include_pt_st(temp);
            }
            else
            {
                temp = _db.Products.Include(e => e.SpecialTags).Include(e => e.ProductTypes).ToList();
            }

            if (tagg)
            {
                temp = temp.Where(e => e.SpecialTags.Name == vm.tag).ToList();
            }

            if (typee)
            {
                temp = temp.Where(e => e.ProductTypes.Name == vm.type).ToList();
            }



            vm.Products     = temp;
            vm.SpecialTags  = _db.SpecialTags.ToList();
            vm.ProductTypes = _db.ProductTypes.ToList();

            return(View(vm));
        }
示例#4
0
        public async Task <IActionResult> Pay()
        {
            var idd = HttpContext.Session.Get <Dictionary <int, int> >("ls")[int.MaxValue];

            if (CreditCard.AppointmentId != idd)
            {
                return(NotFound());
            }
            if (!ModelState.IsValid)
            {
                return(View(CreditCard));
            }
            var id = CreditCard.AppointmentId;

            CreditCard.Appointments = null;

            List <ProductsSelectedForAppointment> psd = null;

            if (orm == 1)
            {
                qdb.incredit(CreditCard);
                psd = qdb.retpsa_with_ai(id);

                foreach (var item in psd)
                {
                    var product = qdb.retProduct(item.ProductId);
                    product.Count -= item.Count;
                    if (product.Count == 0)
                    {
                        product.Available = false;
                    }

                    qdb.upProduct(product);
                }

                var appointment = qdb.retAppointment(id);
                appointment.IsConfirmed = true;
                qdb.upAppointment(appointment);
            }
            else
            {
                _db.CreditCards.Add(CreditCard);
                await _db.SaveChangesAsync();

                psd = await _db.ProductsSelectedForAppointments.Where(e => e.AppointmentId == id)
                      .ToListAsync();

                foreach (var item in psd)
                {
                    var product = _db.Products.First(e => e.Id == item.ProductId);
                    product.Count -= item.Count;
                    if (product.Count == 0)
                    {
                        product.Available = false;
                    }
                }
                _db.Appointments.First(e => e.Id == id).IsConfirmed = true;
                await _db.SaveChangesAsync();
            }

            Dictionary <int, int> dic = new Dictionary <int, int>();

            HttpContext.Session.Set("ls", dic);
            TempData["congrats"] = 1;
            return(RedirectToAction("Index", "Home"));
        }