Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var conn = Configuration.GetConnectionString("PixgramDbContextConnection");

            services.AddDbContext <PixgramDbContext>(options => options.UseSqlServer(conn));

            services.AddScoped(f => CartSession.GetCart(f));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddMemoryCache();
            services.AddSession(options =>
            {
                options.Cookie.Name = ".ToolShed.Cart.Session";
                options.IdleTimeout = TimeSpan.FromDays(2);
            });


            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Esempio n. 2
0
        public ActionResult AddCart(string id)
        {
            string username = SessionHelper.GetUserSession();
            if (username != null)
            {
                if (SessionHelper.GetCartSession(username) == null)
                {
                    CartSession cartsession = new CartSession();
                    cartsession.sp = db.SANPHAMs.Where(sp => sp.MA.Equals(id) && sp.DAXOA.Value.Equals(false) && sp.SANPHAMBAN.Value.Equals(true)).SingleOrDefault();
                    cartsession.soluong = 1;
                    List<CartSession> cartsessionlist = new List<CartSession>();
                    cartsessionlist.Add(cartsession);
                    SessionHelper.SetCartSession(username, cartsessionlist);
                }
                else
                {
                    CartSession cartsession = new CartSession();
                    cartsession.sp = db.SANPHAMs.Where(sp => sp.MA.Equals(id) && sp.DAXOA.Value.Equals(false) && sp.SANPHAMBAN.Value.Equals(true)).SingleOrDefault();
                    cartsession.soluong = 1;
                    List<CartSession> cartsessionlist = SessionHelper.GetCartSession(username);
                    cartsessionlist.Add(cartsession);
                    SessionHelper.SetCartSession(username, cartsessionlist);

                }
            }

            return RedirectToAction("Index", "Home");
        }
        public async Task <CartExtendedResponse> Handle(CreateCartCommand request, CancellationToken cancellationToken)
        {
            var entity = new CartSession
            {
                Id    = Guid.NewGuid().ToString(),
                Items = request.ItemsIds.Select(item => new CartItem
                {
                    CartItemId = new Guid(item),
                    Quantity   = 1,
                }).ToList(),
                User = new CartUser
                {
                    Email = request.UserEmail,
                },
                ValidityDate = DateTimeOffset.Now.AddMonths(2),
            };

            var result = await _repository.AddOrUpdateAsync(entity);

            var response = _mapper.Map <CartExtendedResponse>(result);

            var tasks = response.Items
                        .Select(async x => await _catalogService.EnrichCartItem(x, cancellationToken));

            response.Items = await Task.WhenAll(tasks);

            return(response);
        }
Esempio n. 4
0
        public ActionResult RemoveCart(int id)
        {
            CartSession cart = Session["CartSession"] as CartSession;

            cart.Remove_Cart_Item(id);
            return(RedirectToAction("ShowToCart", "ShoppingCart"));
        }
Esempio n. 5
0
        public async Task <IActionResult> Checkout(int id)
        {
            List <CartItemViewModel> cart = CartSession.GetObjectFromJson <List <CartItemViewModel> >(HttpContext.Session, "cart");

            ViewBag.cart  = cart;
            ViewBag.total = cart.Sum(item => item.Price * item.Quantity);
            var order = new OrderViewModel();

            foreach (var item in cart)
            {
                order.Items.Add(new ItemOrder
                {
                    Prod_ID   = item.Prod_ID,
                    Prod_Name = item.Prod_Name,
                    ImagePath = item.ImagePath,
                    Quantity  = item.Quantity,
                    Price     = item.Price
                });
            }

            //var user = CartSession.GetUser(HttpContext.Session,"Token");
            //string iduser = user.UserName;
            //var result = await _order.Ordercart(iduser, order);
            //if (result.IsSuccessed)
            //{
            //    CartSession.SetObjectAsJson(HttpContext.Session, "cart", cart);
            //    cart.Clear();
            //    return RedirectToAction("Index");
            //}
            //ModelState.AddModelError("", result.Message);
            return(View());
        }
Esempio n. 6
0
        public ActionResult AddCart(string id)
        {
            string username = SessionHelper.GetUserSession();

            if (username != null)
            {
                if (SessionHelper.GetCartSession(username) == null)
                {
                    CartSession cartsession = new CartSession();
                    cartsession.sp      = db.SANPHAMs.Where(sp => sp.MA.Equals(id) && sp.DAXOA.Value.Equals(false) && sp.SANPHAMBAN.Value.Equals(true)).SingleOrDefault();
                    cartsession.soluong = 1;
                    List <CartSession> cartsessionlist = new List <CartSession>();
                    cartsessionlist.Add(cartsession);
                    SessionHelper.SetCartSession(username, cartsessionlist);
                }
                else
                {
                    CartSession cartsession = new CartSession();
                    cartsession.sp      = db.SANPHAMs.Where(sp => sp.MA.Equals(id) && sp.DAXOA.Value.Equals(false) && sp.SANPHAMBAN.Value.Equals(true)).SingleOrDefault();
                    cartsession.soluong = 1;
                    List <CartSession> cartsessionlist = SessionHelper.GetCartSession(username);
                    cartsessionlist.Add(cartsession);
                    SessionHelper.SetCartSession(username, cartsessionlist);
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 7
0
        public void RefreshCart()
        {
            string cartID = String.Empty;

            if (CartSession != null && CartSession.Count > 0)
            {
                cartID = CartSession.First().Id;
            }
            List <SHOPPING_CART> carts = ApplicationContext.Current.Carts.GetShoppingCartItems(cartID);

            decimal total = 0;
            int     i     = 0;

            CartSession = new List <SessionCart>();
            if (carts != null)
            {
                foreach (SHOPPING_CART cart in carts)
                {
                    total += cart.Amount.Value;
                    i     += cart.Quantity;
                    SessionCart sC = new SessionCart(cart);
                    CartSession.Add(sC);
                }
            }
            TotalAmount = total;
        }
        public IActionResult Remove(int id)
        {
            List <CartItemViewModel> cart = CartSession.GetObjectFromJson <List <CartItemViewModel> >(HttpContext.Session, "cart");
            int index = isExist(id);

            cart.RemoveAt(index);
            CartSession.SetObjectAsJson(HttpContext.Session, "cart", cart);
            return(RedirectToAction("Index"));
        }
Esempio n. 9
0
        void Page_Init(object sender, EventArgs e)
        {
            //Stopping the one-click attack
            // force the session to exist, so the session id doesn't change with every request
            if (Session.IsNewSession)
            {
                Session["ForceSession"] = DateTime.Now;
            }
            // 'sign' the viewstate with the current session
            ViewStateUserKey = Session.SessionID;


            if (Page.EnableViewState)
            {
                if (!String.IsNullOrEmpty(Request.QueryString["__VIEWSTATE"]))
                {
                    throw new Exception("Viewstate on query string detected!");
                }
            }

            if (String.IsNullOrEmpty(Request.Form["__VIEWSTATE"]) && Page.IsPostBack)
            {
                throw new Exception("Viewstate did not exist on the form!");
            }

            // session terminated, redirect to login
            try
            {
                if (CurrentCustomer == null)
                {
                    if (User.Identity.IsAuthenticated)
                    {
                        FormsAuthentication.SignOut();
                        Response.Redirect(Request.RawUrl);

                        if (CartSession != null && CartSession.Count > 0)
                        {
                            ApplicationContext.Current.Carts.DeleteShoppingCart(CartSession.First().Id);
                        }

                        CartSession = null;
                        Session.Abandon();
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                Log(ex, ex.Message, ex.StackTrace, "BasePage.Pre_Init");
                FormsAuthentication.SignOut();
                Response.Redirect(Request.RawUrl);

                Session.Abandon();
            }
        }
Esempio n. 10
0
        public ActionResult ShowToCart()
        {
            if (Session["CartSession"] == null)
            {
                return(RedirectToAction("ShowToCart", "ShoppingCart"));
            }
            CartSession cart = Session["CartSession"] as CartSession;

            return(View(cart));
        }
Esempio n. 11
0
        // GET: ShoppingCart
        public CartSession GetCart()
        {
            CartSession cart = Session["CartSession"] as CartSession;

            if (cart == null || Session["CartSession"] == null)
            {
                cart = new CartSession();
                Session["CartSession"] = cart;
            }
            return(cart);
        }
Esempio n. 12
0
        public async Task <CartSession> AddOrUpdateAsync(CartSession item)
        {
            var created = await _database.StringSetAsync(item.Id, JsonConvert.SerializeObject(item));

            if (!created)
            {
                return(null);
            }

            return(await GetAsync(new Guid(item.Id)));
        }
Esempio n. 13
0
        public ActionResult Index(string metatitle, int id, int attribute_pa_chon_chat_lieu_op_lung = 0, string cart_item_key = "")
        {
            if (metatitle.Length <= 0 || metatitle.Split('-').Count() <= 1)
            {
                return(RedirectToAction("NotFound", "Error"));
            }


            var product = ProductDAO.GetProductByID(id);

            if (product == null)
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            product.avatar.OrderBy(x => x.displayorder);
            product.slide.OrderBy(x => x.displayorder);

            if (product.collectionid > 0)
            {
                ViewBag.CollectionName = BrandModel.GetCollectionByID(Convert.ToInt32(product.collectionid)).name;
            }
            else
            {
                ViewBag.BrandName = BrandModel.GetBrandByID(Convert.ToInt32(product.brandid)).name;
            }

            ViewBag.CurrentMaterialID = attribute_pa_chon_chat_lieu_op_lung;
            CartSession cart = new CartSession();

            if (!String.IsNullOrEmpty(cart_item_key))
            {
                List <CartSession> lstCartItem = Session["fancycart"] as List <CartSession>;
                if (lstCartItem != null)
                {
                    cart = lstCartItem.Where(x => x.ItemKey == cart_item_key).FirstOrDefault();
                }
            }
            if (cart == null)
            {
                cart = new CartSession();
            }
            if (!String.IsNullOrEmpty(cart.Order))
            {
                cart.OrderObject            = JsonConvert.DeserializeObject <dynamic>(cart.Order);
                cart.OrderObject_Additional = cart.OrderObject.product[0];
            }

            ViewBag.CurrentCartItem = cart;
            var commonInfo = LocationDAO.GetCommonInfoByID("commoninfo");

            ViewBag.CommonInfo = commonInfo;
            return(View(product));
        }
        public int Checkexistproduct(CartSession cartsession, List <CartSession> listCartSession)
        {
            for (int i = 0; i < listCartSession.Count; i++)
            {
                if (cartsession.sp.MA == listCartSession[i].sp.MA)
                {
                    return(i);
                }
            }

            return(-1);
        }
Esempio n. 15
0
        public PartialViewResult BagCart()
        {
            int         _t_item = 0;
            CartSession cart    = Session["CartSession"] as CartSession;

            if (cart != null)
            {
                _t_item = cart.Total_Quantity();
            }
            ViewBag.infoCart = _t_item;
            return(PartialView("BagCart"));
        }
        private int isExist(int id)
        {
            List <CartItemViewModel> cart = CartSession.GetObjectFromJson <List <CartItemViewModel> >(HttpContext.Session, "cart");

            for (int i = 0; i < cart.Count; i++)
            {
                if (cart[i].Prod_ID.Equals(id))
                {
                    return(i);
                }
            }
            return(-1);
        }
Esempio n. 17
0
        private void updAvailListInOptimisticScenario(DropDownList ddl, int prodAttrId, int alreadyInCart, int newQuantity, LinkButton lnk)
        {
            List <int>        qtyList;
            PRODUCT_ATTRIBUTE prodAttr = ApplicationContext.Current.Products.GetProductAvailability(prodAttrId, out qtyList, alreadyInCart);

            if (!qtyList.Contains(newQuantity))
            {
                ddl.SelectedValue = alreadyInCart.ToString();
                lnk.Text          = alreadyInCart.ToString();
                lblMessage.Text   = Resources.Lang.InsufficientAvailabilityMessage;
                CartSession.Find(c => c.ProductAttributeId == prodAttrId).Quantity = alreadyInCart;
            }
        }
Esempio n. 18
0
            public async Task <Unit> Handle(Execute request, CancellationToken cancellationToken)
            {
                var cartSession = new CartSession
                {
                    CreatedAt = request.CreatedAt
                };

                var result = await _context.CartSession.AddAsync(cartSession);

                if (result?.Entity == null)
                {
                    throw new Exception("Error while adding new cart session.");
                }


                var transactions = await _context.SaveChangesAsync();

                if (transactions == 0)
                {
                    throw new Exception("Error while saving cart session.");
                }

                int cartSessionId = cartSession.CartSessionId;

                foreach (var bookGuid in request.BooksGuid)
                {
                    var detail = new CartSessionDetail
                    {
                        CreatedAt     = DateTime.Now,
                        CartSessionId = cartSessionId,
                        BookGuid      = bookGuid
                    };

                    var detailResult = await _context.CartSessionDetail.AddAsync(detail);

                    if (detailResult?.Entity == null)
                    {
                        throw new Exception("Error while adding new cart session detail.");
                    }
                }

                transactions = await _context.SaveChangesAsync();

                if (transactions == 0)
                {
                    throw new Exception("Error while saving cart session detail.");
                }


                return(Unit.Value);
            }
Esempio n. 19
0
        public void ConfigureServices(IServiceCollection services)
        {
            var conn = _configuration.GetConnectionString("ToolShedProducts");

            services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(conn));

            services.AddTransient <IProductRepository, ProductRepository>();


            //services.AddTransient<IPasswordValidator<IdentityUser>, CorporatePasswordValidator>();

            //services.AddTransient<IUserValidator<IdentityUser>, CorporateUserValidator>();

            //services.AddAutoMapper();


            services.AddIdentity <IdentityUser, IdentityRole>().
            AddEntityFrameworkStores <ApplicationDbContext>().
            AddDefaultTokenProviders();

            services.AddTransient <IIdentitySeeder, IdentitySeeder>();



            services.Configure <IdentityOptions>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequiredLength         = 3;
            });



            services.Configure <RouteOptions>(options => options.LowercaseUrls = true);

            services.AddScoped(f => CartSession.GetCart(f));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddTransient <IOrderRepository, OrderRepository>();

            services.AddMemoryCache();
            services.AddSession(options =>
            {
                options.Cookie.Name = ".ToolShed.Cart.Session";
                options.IdleTimeout = TimeSpan.FromDays(2);
            });

            services.AddMvc();
        }
Esempio n. 20
0
        protected void ddlQty_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddl = sender as DropDownList;
            int          selectedQty;

            if (Int32.TryParse(ddl.SelectedValue, out selectedQty))
            {
                RepeaterItem item  = (RepeaterItem)ddl.NamingContainer;
                HiddenField  field = (HiddenField)item.FindControl("ProdAttrID");
                int          prodAttrId;
                if (Int32.TryParse(field.Value, out prodAttrId))
                {
                    SessionCart cart = CartSession.Find(c => c.ProductAttributeId == prodAttrId);
                    if (cart != null)
                    {
                        // we already have the right version in the session variable cartsession
                        int           oldQuantity = cart.Quantity;
                        SHOPPING_CART shopping    = new SHOPPING_CART()
                        {
                            ID = cart.Id, ProdAttrID = prodAttrId
                        };
                        // session var
                        cart.Quantity  = selectedQty;
                        cart.DateAdded = DateTime.Now;

                        shopping.Quantity  = selectedQty;
                        shopping.DateAdded = DateTime.Now;
                        shopping.ProductAttributeVersion = cart.ProductAttributeVersion;

                        LinkButton lnk = (LinkButton)item.FindControl("lnkEdit");

                        try
                        {
                            ApplicationContext.Current.Carts.Update(shopping, oldQuantity);
                            lblMessage.Text = String.Empty;
                        }
                        catch (Exception ex)
                        {
                            BasePage.Log(ex, ex.Message, ex.StackTrace, "Cart Control");
                            updAvailListInOptimisticScenario(ddl, prodAttrId, oldQuantity, selectedQty, lnk);
                        }
                        finally
                        {
                            DataBind();
                            ddl.Visible = false;
                            lnk.Visible = true;
                        }
                    }
                }
            }
        }
Esempio n. 21
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().AddJsonOptions(
                options => options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                );

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            var conn = _configuration.GetConnectionString("Picks");

            services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(conn));

            // Project services.
            services.AddTransient <IImageRepository, ImageRepository>();
            services.AddTransient <IImageService, ImageService>();

            services.AddTransient <ICategoryRepository, CategoryRepository>();
            services.AddTransient <ICategoryService, CategoryService>();

            services.AddTransient <CartSession>();

            services.AddTransient <UploadImageHelper>();
            services.AddTransient <AzureCognitiveServicesSettings>();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddScoped(x => CartSession.GetCart(x));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddMemoryCache();
            services.AddSession(opt =>
            {
                opt.Cookie.Name = "Picks.io";
            });

            services.AddDistributedRedisCache(opt =>
            {
                opt.Configuration = _configuration.GetConnectionString("Redis");
                //opt.InstanceName = "main_";
            });

            services.AddAutoMapper();
        }
        public IActionResult Index()
        {
            var cart = CartSession.GetObjectFromJson <List <CartItemViewModel> >(HttpContext.Session, "cart");

            if (cart == null)
            {
                ViewBag.cart  = "";
                ViewBag.total = 0;
                return(View());
            }
            ViewBag.cart  = cart;
            ViewBag.total = cart.Sum(item => item.Price * item.Quantity);
            return(View());
        }
Esempio n. 23
0
 public int?CartExpirationMinutes()
 {
     if (CartSession != null && CartSession.Count > 0)
     {
         List <SessionCart> cSession    = CartSession.OrderByDescending(c => c.DateAdded).ToList();
         SessionCart        sessionCart = cSession.First();
         TimeSpan           ts          = DateTime.Now - sessionCart.DateAdded;
         return(FashionZone.BL.Configuration.CartExpirationValue - (int)ts.TotalMinutes);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 24
0
        public ActionResult CheckOut(FormCollection form)
        {
            var session = (Website_Panda.Models.Login.UserLogin)Session[Website_Panda.Models.Login.Common.USER_SESSION];

            if (session == null)
            {
                return(View());
            }
            else
            {
                CartSession cart   = Session["CartSession"] as CartSession;
                Order       _order = new Order();
                _order.OrderDate = DateTime.Now;
                _order.IdCus     = session.UserID;
                db.Order.Add(_order);
                foreach (var item in cart.Items)
                {
                    OrderDetail _order_Detail = new OrderDetail();
                    _order_Detail.IDOrder      = _order.IDOrder;
                    _order_Detail.IDProduct    = item._shopping_product.IDProduct;
                    _order_Detail.Price        = item._shopping_product.Price;
                    _order_Detail.QuantitySale = item._shopping_quantity;
                    db.OrderDetails.Add(_order_Detail);
                }
                db.SaveChanges();
                cart.ClearCart();
                return(RedirectToAction("Shopping_Success", "ShoppingCart"));
                //CartSession cart = Session["Cart"] as CartSession;
                //var result = from r in db.Customers
                //             where r.IdCus == session.UserID
                //             select r;
                //var cus2 = result.ToList().First();
                //Order _order = new Order();
                //_order.OrderDate = DateTime.Now;
                //_order.Email_Cus = cus2.Email_Cus;
                //_order.SDT_Cus = cus2.Phone_Cus;
                //_order.Password_cus = cus2.Password;
                //_order.Descriptions = cus2.Address_Cus;
                //_order.CodeCus = cus2.CodeCus;
                //_order.Deleted = false;
                //_order.Cancelled = false;
                //_order.Paid = false;
                //_order.Status = false;
                //db.Orders.Add(_order);
            }
        }
Esempio n. 25
0
        protected void rptDetails_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandSource is LinkButton)
            {
                LinkButton lnk = e.CommandSource as LinkButton;
                if (!String.IsNullOrWhiteSpace(lnk.CommandArgument))
                {
                    int prodAttrID;
                    if (Int32.TryParse(lnk.CommandArgument, out prodAttrID))
                    {
                        if (lnk.ID == "lnkEdit")
                        {
                            RepeaterItem item = (RepeaterItem)lnk.NamingContainer;

                            DropDownList ddlQty = (DropDownList)item.FindControl("ddlQty");
                            ddlQty.Visible = true;
                            lnk.Visible    = false;

                            List <int>        qtyList;
                            PRODUCT_ATTRIBUTE prodAttr = ApplicationContext.Current.Products.GetProductAvailability(prodAttrID, out qtyList, Int32.Parse(lnk.Text));

                            // updating version
                            SessionCart cart = CartSession.Find(c => c.ProductAttributeId == prodAttrID);
                            cart.ProductAttributeVersion = prodAttr.Version;
                            ddlQty.DataSource            = qtyList;
                            ddlQty.DataBind();
                            ddlQty.SelectedValue = lnk.Text;
                        }
                        else if (lnk.ID == "lnkRemove")
                        {
                            ApplicationContext.Current.Carts.DeleteById(CartSession.First().Id, prodAttrID);
                            DataBind();
                        }
                        if (CartSession == null || CartSession.Count == 0)
                        {
                            lblMessage.Text    = Resources.Lang.EmptyCartLabel;
                            rptDetails.Visible = false;
                        }
                        else
                        {
                            lblMessage.Text = String.Empty;
                        }
                    }
                }
            }
        }
Esempio n. 26
0
        protected void ddlQty_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddl = sender as DropDownList;
            int          selectedQty;

            if (Int32.TryParse(ddl.SelectedValue, out selectedQty))
            {
                RepeaterItem item  = (RepeaterItem)ddl.NamingContainer;
                HiddenField  field = (HiddenField)item.FindControl("ProdAttrID");
                int          prodAttrId;
                if (Int32.TryParse(field.Value, out prodAttrId))
                {
                    SHOPPING_CART cart;
                    if ((cart = CartSession.Where(c => c.ID == CartID && c.ProdAttrID == prodAttrId).FirstOrDefault()) != null)
                    {
                        // we already have the right version in the session variable cartsession
                        int      oldQuantity = cart.Quantity;
                        DateTime oldDate     = cart.DateAdded;
                        cart.Quantity  = selectedQty;
                        cart.DateAdded = DateTime.Now;
                        try
                        {
                            ApplicationContext.Current.Carts.Update(cart, oldQuantity);
                        }
                        catch (Exception ex)
                        {
                            OrderNew parent = this.Page as OrderNew;
                            parent.writeResult(ex.Message, true);

                            // reverse situation because of optimistic error
                            cart.Quantity  = oldQuantity;
                            cart.DateAdded = oldDate;
                        }
                        // refresh session, optional
                        //CartSession = ApplicationContext.Current.Carts.GetShoppingCartItems(CartID);
                        DataBind(CartSession);
                        // notify parent for a partial refresh
                        NeedRefresh(sender, e);
                        ddl.Enabled = false;
                        LinkButton lnk = (LinkButton)item.FindControl("lnkEdit");
                        lnk.Enabled = false;
                    }
                }
            }
        }
        public IActionResult Info()
        {
            List <CartItemViewModel> cart = CartSession.GetObjectFromJson <List <CartItemViewModel> >(HttpContext.Session, "cart");

            // int index = isExist(id);
            //List<CartItemViewModel> xuly= CartSession.GetObjectFromJson<List<CartItemViewModel>>(HttpContext.Session, "xuly");
            // xuly.Add(new CartItemViewModel { Id = 1.ToString(), Prod_ID = cart[1].Prod_ID, Prod_Name = cart[1].Prod_Name, Price = cart[1].Price, Quantity = cart[1].Quantity });
            // CartSession.SetObjectAsJson(HttpContext.Session, "xuly", cart);
            // List<CartItemViewModel> xu = CartSession.GetObjectFromJson<List<CartItemViewModel>>(HttpContext.Session, "xuly");
            // var u=  HttpContext.Session.GetString(SystemConstants.AppSettings.Token);
            //  LoginRequest user = CartSession.GetUser<LoginRequest>(HttpContext.Session, "Token");
            //User.Identity.Name;


            // cart.Clear();
            CartSession.SetObjectAsJson(HttpContext.Session, "cart", cart);
            return(View());
        }
Esempio n. 28
0
 protected void lnkCancel_Click(object sender, EventArgs e)
 {
     try
     {
         if (CartSession != null && CartSession.Count > 0)
         {
             ApplicationContext.Current.Carts.DeleteShoppingCart(CartSession.First().Id);
         }
         CartSession = null;
         Response.Redirect("/home/");
     }
     catch (System.Threading.ThreadAbortException ex)
     {
     }
     catch (Exception ex)
     {
         Log(ex, ex.Message, ex.StackTrace, "Checkout - Cancel");
     }
 }
Esempio n. 29
0
        public ActionResult AddItem(long productID, int quanlity, string url)
        {
            var prod = new ProductDAO().GetProductByID(productID);
            var cart = Session[CommondConstant.CART_SESSION];

            if (cart != null)
            {
                var listCartItem = (List <CartSession>)cart;
                if (listCartItem.Exists(x => x.product.ID == productID))
                {
                    foreach (var item in listCartItem)
                    {
                        if (item.product.ID == productID)
                        {
                            item.Quanlity += quanlity;
                        }
                    }
                }
                else
                {
                    var item = new CartSession();
                    item.product  = prod;
                    item.Quanlity = quanlity;
                    listCartItem.Add(item);

                    //assign listCartItem into session
                    Session[CommondConstant.CART_SESSION] = listCartItem;
                }
            }
            else
            {
                //Create a new cart item
                var item = new CartSession();
                item.product  = prod;
                item.Quanlity = quanlity;
                var listCartItem = new List <CartSession>();
                listCartItem.Add(item);

                //assign listCartItem into session
                Session[CommondConstant.CART_SESSION] = listCartItem;
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 30
0
        //public ActionResult CartShow()
        //{
        //    CartSession cart = Session["CartSession"] as CartSession;
        //    return View(cart);
        //}

        //public ActionResult CartShowMenu()
        //{
        //    CartSession cart = Session["CartSession"] as CartSession;
        //    return View(cart);
        //}
        public ActionResult Update_Quantity_Cart(FormCollection form)
        {
            CartSession cart   = Session["CartSession"] as CartSession;
            int         id_pro = int.Parse(form["ID_Product"]);

            Product _pro = db.Products.Find(id_pro);

            int quantity = int.Parse(form["Quantity"]);

            if (quantity > _pro.Quantity)
            {
                return(RedirectToAction("Err", "ShoppingCart"));
            }
            else
            {
                cart.Update_Quantity_Shopping(id_pro, quantity);
            }
            return(RedirectToAction("ShowToCart", "ShoppingCart"));
        }
Esempio n. 31
0
        private CartSession GetSession(Guid sessionId)
        {
            var session = _cartContext.CartSessions.FirstOrDefault(x => x.Id == sessionId);

            if (session == null || session.ExpiresDateTime < DateTime.Now)
            {
                session = new CartSession()
                {
                    CreateDateTime  = DateTime.Now,
                    ExpiresDateTime = DateTime.Now.AddHours(1),
                    Id = sessionId
                };

                _cartContext.Add(session);
                _cartContext.SaveChanges();
            }

            return(session);
        }