Esempio n. 1
0
 public IActionResult dAdd(int id, int quantity = 1)
 {
     if (SessionExtensions.Get <List <DailyDealOrder> >(HttpContext.Session, "dcart") == null)
     {
         List <DailyDealOrder> dcart = new List <DailyDealOrder>();
         dcart.Add(new DailyDealOrder {
             DailyDeal = id, Quantity = quantity
         });
         SessionExtensions.Set(HttpContext.Session, "dcart", dcart);
     }
     else
     {
         List <DailyDealOrder> dcart = SessionExtensions.Get <List <DailyDealOrder> >(HttpContext.Session, "dcart");
         int index = disExist(id);
         if (index != -1)
         {
             dcart[index].Quantity++;
         }
         else
         {
             dcart.Add(new DailyDealOrder {
                 DailyDeal = id, Quantity = 1
             });
         }
         SessionExtensions.Set(HttpContext.Session, "dcart", dcart);
     }
     return(RedirectToAction("Index", "DailyDeals"));
 }
Esempio n. 2
0
        public async Task <IActionResult> Index()
        {
            List <CategoryViewModel> categoryList = await _categoryApiClient.GetList();

            ViewBag.CategoryList = categoryList;
            ViewBag.Url          = _configuration["BaseAddress"];

            cart = SessionExtensions.Get <List <CartItems> >(HttpContext.Session, "cart");
            var list = new List <CartItems>();

            if (cart != null)
            {
                list = cart;
            }
            ViewBag.Cart = list;


            decimal total = 0;

            foreach (var item in list)
            {
                total += (item.Price * item.Quantity);
            }
            ViewBag.total = total;

            return(View(list));
        }
Esempio n. 3
0
        // Lekérem a sessionből a listát, belerakom az új productot és visszarakom a sessionbe.
        public void AddShoppingCartItem(int productModellNumber)
        {
            bool isIn = false;
            List <ShoppingCartItem> currentShoppingCartItems = SessionExtensions.Get <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart");

            if (currentShoppingCartItems == null)
            {
                SessionExtensions.Set <List <ShoppingCartItem> >(this.httpContext.Session, "shoppingCart", new List <ShoppingCartItem>());
                currentShoppingCartItems = SessionExtensions.Get <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart");
            }
            // megkell nézni, hogy volt e már a listában ilyen
            for (int i = 0; i < currentShoppingCartItems.Count; i++)
            {
                if (currentShoppingCartItems[i].ProductModellNumber == productModellNumber)
                {
                    currentShoppingCartItems[i].Quantity++;
                    isIn = true;
                }
            }
            if (isIn == false)
            {
                Product          item   = context.Products.FirstOrDefault(c => c.ModellNumber == productModellNumber);
                ShoppingCartItem scItem = new ShoppingCartItem(item.ModellNumber, 1, item.Description);
                currentShoppingCartItems.Add(scItem);
            }
            SessionExtensions.Set <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart", currentShoppingCartItems);
        }
Esempio n. 4
0
        public void ClearCart()
        {
            List <ShoppingCartItem> currentShoppingCartItems = SessionExtensions.Get <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart");

            currentShoppingCartItems.RemoveAll(c => c.Quantity != 0);
            SessionExtensions.Set <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart", currentShoppingCartItems);
        }
Esempio n. 5
0
 public IActionResult Order(int id, int quantity)
 {
     if (SessionExtensions.Get <List <DailyDeal> >(HttpContext.Session, "dcart") == null)
     {
         List <DailyDeal> cart = new List <DailyDeal>();
         cart.Add(new DailyDeal {
             DailyDealId = id, DailyDealQuantity = quantity
         });
         SessionExtensions.Set(HttpContext.Session, "dcart", cart);
     }
     else
     {
         List <DailyDeal> cart = SessionExtensions.Get <List <DailyDeal> >(HttpContext.Session, "dcart");
         int index             = isExist(id);
         if (index != -1)
         {
             cart[index].DailyDealQuantity++;
         }
         else
         {
             cart.Add(new DailyDeal {
                 DailyDealId = id, DailyDealQuantity = quantity
             });
         }
         SessionExtensions.Set(HttpContext.Session, "dcart", cart);
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 6
0
 public IActionResult Add(int id, int quantity = 1)
 {
     if (SessionExtensions.Get <List <ItemOrder> >(HttpContext.Session, "cart") == null)
     {
         List <ItemOrder> cart = new List <ItemOrder>();
         cart.Add(new ItemOrder {
             Item = id, Quantity = quantity
         });
         SessionExtensions.Set(HttpContext.Session, "cart", cart);
     }
     else
     {
         List <ItemOrder> cart = SessionExtensions.Get <List <ItemOrder> >(HttpContext.Session, "cart");
         int index             = isExist(id);
         if (index != -1)
         {
             cart[index].Quantity++;
         }
         else
         {
             cart.Add(new ItemOrder {
                 Item = id, Quantity = 1
             });
         }
         SessionExtensions.Set(HttpContext.Session, "cart", cart);
     }
     return(RedirectToAction("Index", "Items"));
 }
Esempio n. 7
0
        public async Task <IActionResult> Success()
        {
            List <CategoryViewModel> categoryList = await _categoryApiClient.GetList();

            ViewBag.CategoryList = categoryList;

            List <CartItems> cart = SessionExtensions.Get <List <CartItems> >(HttpContext.Session, "cart");
            var list = new List <CartItems>();

            if (cart != null)
            {
                list = cart;
            }
            ViewBag.Cart = list;

            decimal total = 0;

            foreach (var item in list)
            {
                total += (item.Price * item.Quantity);
            }
            ViewBag.total = total;

            SessionExtensions.Set(HttpContext.Session, "cart", null);
            return(View());
        }
Esempio n. 8
0
 public IActionResult Index()
 {
     if (!SessionExtensions.Get <List <ItemOrder> >(HttpContext.Session, "cart").IsNullOrEmpty() || !SessionExtensions.Get <List <DailyDealOrder> >(HttpContext.Session, "dcart").IsNullOrEmpty())
     {
         if (!SessionExtensions.Get <List <ItemOrder> >(HttpContext.Session, "cart").IsNullOrEmpty())
         {
             var items = _context.Item;
             ViewBag.items = items.ToList();
             var cart = SessionExtensions.Get <List <ItemOrder> >(HttpContext.Session, "cart");
             ViewBag.cart = cart.ToList();
             if (!cart.IsNullOrEmpty())
             {
                 ViewBag.total = cart.Sum(item => items.Where(a => a.ItemId == item.Item).FirstOrDefault().Price *item.Quantity);
             }
         }
         if (!SessionExtensions.Get <List <DailyDealOrder> >(HttpContext.Session, "dcart").IsNullOrEmpty())
         {
             var dailies = _context.DailyDeal.ToList();
             ViewBag.dailies = dailies;
             var dcart = SessionExtensions.Get <List <DailyDealOrder> >(HttpContext.Session, "dcart");
             ViewBag.dcart = dcart.ToList();
             if (!dcart.IsNullOrEmpty())
             {
                 ViewBag.dtotal = dcart.Sum(daily => dailies.Where(b => b.DailyDealId == daily.DailyDeal).FirstOrDefault().DailyDealPrice *daily.Quantity);
             }
         }
         return(View());
     }
     else
     {
         return(View("EmptyCart"));
     }
 }
Esempio n. 9
0
        public async Task <IActionResult> Order(int table, string message)
        {
            List <ItemOrder> cart = SessionExtensions.Get <List <ItemOrder> >(HttpContext.Session, "cart");

            if (!cart.IsNullOrEmpty())
            {
                foreach (ItemOrder item in cart)
                {
                    decimal total = _context.Item.Where(i => i.ItemId == item.Item).FirstOrDefault().Price *item.Quantity;
                    item.Price   = total;
                    item.Table   = table;
                    item.Message = message;
                    _context.ItemOrder.Add(item);
                    _ = await _context.SaveChangesAsync();
                }
            }
            List <DailyDealOrder> dcart = SessionExtensions.Get <List <DailyDealOrder> >(HttpContext.Session, "dcart");

            if (!dcart.IsNullOrEmpty())
            {
                foreach (DailyDealOrder item in dcart)
                {
                    decimal total = _context.DailyDeal.Where(i => i.DailyDealId == item.DailyDeal).FirstOrDefault().DailyDealPrice.GetValueOrDefault() * item.Quantity;
                    item.Price   = total;
                    item.Table   = table;
                    item.Message = message;
                    _context.DailyDealOrder.Add(item);
                    _ = await _context.SaveChangesAsync();
                }
            }
            HttpContext.Session.Clear();
            return(RedirectToAction("Index", "Items"));
        }
Esempio n. 10
0
        public ActionResult AddSession(string sessionguid)
        {
            if (SessionExtensions.ContainsKey(sessionguid))
            {
                MultiPlayerSession currsession = SessionExtensions.Get(sessionguid);

                TaskList.Add(currsession.HostPlayerId, () =>
                {
                    if (SessionExtensions.ContainsKey(currsession.HostPlayerId))
                    {
                        MultiPlayerSession currentActualSession = SessionExtensions.Get(currsession.HostPlayerId);

                        var clientList = currentActualSession.CurrentPlayerList.Select(n => n.UserId.ToString()).ToList();

                        IHubContext multiplayerHub = GlobalHost.ConnectionManager.GetHubContext <MultiplayerHub>();
                        multiplayerHub.Clients.Groups(clientList).broadcastYourClicks();
                    }
                    else
                    {
                        //remove this session.
                        RemoveSession(currsession.HostPlayerId);
                    }
                });
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Session not found."));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK, "Multiplayer session was added to the tasklist."));
        }
Esempio n. 11
0
        public IActionResult dRemove(int id)
        {
            List <DailyDealOrder> dcart = SessionExtensions.Get <List <DailyDealOrder> >(HttpContext.Session, "dcart");
            int index = disExist(id);

            dcart.RemoveAt(index);
            SessionExtensions.Set(HttpContext.Session, "dcart", dcart);
            return(RedirectToAction("Index"));
        }
Esempio n. 12
0
        public IActionResult Remove(int id)
        {
            List <ItemOrder> cart = SessionExtensions.Get <List <ItemOrder> >(HttpContext.Session, "cart");
            int index             = isExist(id);

            cart.RemoveAt(index);
            SessionExtensions.Set(HttpContext.Session, "cart", cart);
            return(RedirectToAction("Index"));
        }
Esempio n. 13
0
        public IActionResult DeleteCart(int id)
        {
            cart = SessionExtensions.Get <List <CartItems> >(HttpContext.Session, "cart");

            cart.RemoveAll(x => x.Id == id);

            SessionExtensions.Set(HttpContext.Session, "cart", cart);

            return(RedirectToAction("Index"));
        }
Esempio n. 14
0
        public List <ShoppingCartItem> GetShoppingCartItems()
        {
            List <ShoppingCartItem> currentShoppingCartItems = SessionExtensions.Get <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart");

            if (currentShoppingCartItems == null)
            {
                SessionExtensions.Set <List <ShoppingCartItem> >(this.httpContext.Session, "shoppingCart", new List <ShoppingCartItem>());
                currentShoppingCartItems = SessionExtensions.Get <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart");
            }
            return(currentShoppingCartItems);
        }
        private Cart GetCart()
        {
            Cart cart = SessionExtensions.Get(HttpContext.Session, "Cart");

            if (cart == null)
            {
                cart = new Cart();
                SessionExtensions.Set(HttpContext.Session, "Cart", cart);
            }
            return(cart);
        }
Esempio n. 16
0
        private int isExist(int id)
        {
            List <ItemOrder> cart = SessionExtensions.Get <List <ItemOrder> >(HttpContext.Session, "cart");

            for (int i = 0; i < cart.Count; i++)
            {
                if (cart[i].Item == id)
                {
                    return(i);
                }
            }
            return(-1);
        }
Esempio n. 17
0
        public IActionResult Display()
        {
            //get the session list
            IEnumerable <Item> theList = SessionExtensions.Get <IEnumerable <Item> >(HttpContext.Session, "ItemsList");

            //vm
            HomeDisplayViewModel vm = new HomeDisplayViewModel
            {
                Items = theList
            };

            return(View(vm));
        }
Esempio n. 18
0
        private int isExist(int id)
        {
            List <DailyDeal> cart = SessionExtensions.Get <List <DailyDeal> >(HttpContext.Session, "dcart");

            for (int i = 0; i < cart.Count; i++)
            {
                if (cart[i].DailyDealId == id)
                {
                    return(i);
                }
            }
            return(-1);
        }
Esempio n. 19
0
        public async Task <IActionResult> Details(int id)
        {
            List <CategoryViewModel> categoryList = await _categoryApiClient.GetList();

            ViewBag.CategoryList = categoryList;

            List <ProductImageViewModel> imageList = await _productApiClient.GetListImage(id);

            ViewBag.ImageList = imageList;

            List <CartItems> cart = SessionExtensions.Get <List <CartItems> >(HttpContext.Session, "cart");
            var list = new List <CartItems>();

            if (cart != null)
            {
                list = cart;
            }
            ViewBag.Cart = list;

            decimal total = 0;

            foreach (var item in list)
            {
                total += (item.Price * item.Quantity);
            }
            ViewBag.total = total;



            ViewBag.productId = id;

            var result = await _productApiClient.GetProductId(id);

            var request = new GetProductByCategoryPagingRequest()
            {
                CategoryId = result.categoryId,
                PageIndex  = 1,
                PageSize   = 6
            };
            var data = await _productApiClient.GetProductPagings(request);

            ViewBag.data = data;


            ViewBag.Url = _configuration["BaseAddress"];
            return(View(result));
        }
Esempio n. 20
0
        public async Task <IActionResult> AddCart(int productId)
        {
            var product = await _productApiClient.GetProductId(productId);

            cart = SessionExtensions.Get <List <CartItems> >(HttpContext.Session, "cart");
            if (cart != null)
            {
                if (cart.Exists(x => x.Id == productId))
                {
                    foreach (var item in cart)
                    {
                        if (item.Id == productId)
                        {
                            item.Quantity++;
                        }
                    }
                }
                else
                {
                    cart.Add(new CartItems
                    {
                        Id         = productId,
                        Name_Phone = product.Name_Phone,
                        ImagePath  = product.ImagePath,
                        Price      = product.Price,
                        Quantity   = 1
                    });
                }

                SessionExtensions.Set(HttpContext.Session, "cart", cart);
            }
            else
            {
                cart = new List <CartItems>();
                cart.Add(new CartItems
                {
                    Id         = productId,
                    Name_Phone = product.Name_Phone,
                    ImagePath  = product.ImagePath,
                    Price      = product.Price,
                    Quantity   = 1
                });
                SessionExtensions.Set(HttpContext.Session, "cart", cart);
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 21
0
        public int GetShoppingCartTotal()
        {
            int total = 0;
            List <ShoppingCartItem> currentShoppingCartItems = SessionExtensions.Get <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart");

            if (currentShoppingCartItems == null)
            {
                SessionExtensions.Set <List <ShoppingCartItem> >(this.httpContext.Session, "shoppingCart", new List <ShoppingCartItem>());
                currentShoppingCartItems = SessionExtensions.Get <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart");
            }
            for (int i = 0; i < currentShoppingCartItems.Count; i++)
            {
                Product currentProduct = context.Products.SingleOrDefault(p => p.ModellNumber == currentShoppingCartItems[i].ProductModellNumber);
                total += currentProduct.Price * currentShoppingCartItems[i].Quantity;
            }
            return(total);
        }
Esempio n. 22
0
        public void RemoveShoppingCartItem(int productModellNumber)
        {
            List <ShoppingCartItem> currentShoppingCartItems = SessionExtensions.Get <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart");

            // megkell nézni, hogy létezik e egyáltalán
            for (int i = 0; i < currentShoppingCartItems.Count; i++)
            {
                if (currentShoppingCartItems[i].ProductModellNumber == productModellNumber)
                {
                    currentShoppingCartItems[i].Quantity--;
                    if (currentShoppingCartItems[i].Quantity == 0)
                    {
                        currentShoppingCartItems.Remove(currentShoppingCartItems[i]);
                    }
                }
            }
            SessionExtensions.Set <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart", currentShoppingCartItems);
        }
Esempio n. 23
0
        // Lekérem a sessionből az adott terméket
        public ShoppingCartItem GetShoppingCartItem(int productModellNumber)
        {
            List <ShoppingCartItem> currentShoppingCartItems = SessionExtensions.Get <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart");

            if (currentShoppingCartItems == null)
            {
                SessionExtensions.Set <List <ShoppingCartItem> >(this.httpContext.Session, "shoppingCart", new List <ShoppingCartItem>());
                currentShoppingCartItems = SessionExtensions.Get <List <ShoppingCartItem> >(httpContext.Session, "shoppingCart");
            }
            for (int i = 0; i < currentShoppingCartItems.Count; i++)
            {
                if (currentShoppingCartItems[i].ProductModellNumber == productModellNumber)
                {
                    return(currentShoppingCartItems[i]);
                }
            }
            // ha nem volt ilyen termék
            return(null);
        }
Esempio n. 24
0
        public async Task <IActionResult> Payment(OrderCreateRequest request)
        {
            List <CategoryViewModel> categoryList = await _categoryApiClient.GetList();

            ViewBag.CategoryList = categoryList;

            cart = SessionExtensions.Get <List <CartItems> >(HttpContext.Session, "cart");
            var list = new List <CartItems>();

            if (cart != null)
            {
                list = cart;
            }
            ViewBag.Cart = list;

            decimal total = 0;

            foreach (var item in list)
            {
                total += (item.Price * item.Quantity);
            }
            ViewBag.total = total;

            if (!ModelState.IsValid)
            {
                return(View(request));
            }

            var id = await _orderApiClient.CreateOrder(request);

            cart = SessionExtensions.Get <List <CartItems> >(HttpContext.Session, "cart");
            var orderDetail = new OrderDetailsCreateRequest();

            foreach (var item in cart)
            {
                orderDetail.OrderId   = id;
                orderDetail.ProductId = item.Id;
                orderDetail.Price     = item.Price;
                orderDetail.Quantity  = item.Quantity;
                await _orderApiClient.CreateOrderDetail(orderDetail);
            }
            return(RedirectToAction("Success"));
        }
Esempio n. 25
0
        public IActionResult Subtract(int id)
        {
            List <ItemOrder> cart = SessionExtensions.Get <List <ItemOrder> >(HttpContext.Session, "cart");
            int index             = isExist(id);

            if (index != -1)
            {
                cart[index].Quantity--;
                if (cart[index].Quantity == 0)
                {
                    cart.RemoveAt(index);
                }
            }
            else
            {
                cart.RemoveAt(index);
            }
            SessionExtensions.Set(HttpContext.Session, "cart", cart);

            return(RedirectToAction("Index"));
        }
Esempio n. 26
0
        public IActionResult dSubtract(int id)
        {
            List <DailyDealOrder> dcart = SessionExtensions.Get <List <DailyDealOrder> >(HttpContext.Session, "dcart");
            int index = disExist(id);

            if (index != -1)
            {
                dcart[index].Quantity--;
                if (dcart[index].Quantity == 0)
                {
                    dcart.RemoveAt(index);
                }
            }
            else
            {
                dcart.RemoveAt(index);
            }
            SessionExtensions.Set(HttpContext.Session, "dcart", dcart);

            return(RedirectToAction("Index"));
        }
Esempio n. 27
0
        public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 10)
        {
            var request = new GetProductByCategoryPagingRequest()
            {
                Keyword   = keyword,
                PageIndex = pageIndex,
                PageSize  = pageSize
            };

            List <CategoryViewModel> categoryList = await _categoryApiClient.GetList();

            ViewBag.CategoryList = categoryList;

            List <CartItems> cart = SessionExtensions.Get <List <CartItems> >(HttpContext.Session, "cart");
            var list = new List <CartItems>();

            if (cart != null)
            {
                list = cart;
            }
            ViewBag.Cart = list;


            decimal total = 0;

            foreach (var item in list)
            {
                total += (item.Price * item.Quantity);
            }
            ViewBag.total = total;


            var data = await _productApiClient.GetProductPagings(request);

            ViewBag.Url     = _configuration["BaseAddress"];
            ViewBag.Keyword = keyword;

            return(View(data));
        }
Esempio n. 28
0
        public IActionResult Index(HomeIndexViewModel vm)
        {
            //get the session list
            IEnumerable <Item> theList = SessionExtensions.Get <IEnumerable <Item> >(HttpContext.Session, "ItemsList");

            if (theList == null)
            {
                theList = new List <Item>();
                SessionExtensions.Set <IEnumerable <Item> >(HttpContext.Session, "ItemsList", theList);
            }
            //add one item
            Item item = new Item {
                ItemName = vm.Search
            };

            theList = theList.Append(item);

            //set the list back to session
            SessionExtensions.Set <IEnumerable <Item> >(HttpContext.Session, "ItemsList", theList);

            return(RedirectToAction("Display"));
        }
Esempio n. 29
0
 public ActionResult Index()
 {
     return(View(SessionExtensions.Get()));
 }