public ActionResult RemoveOneProduct(string idDT, string idCart)
        {
            DetailCart product = db.DetailCarts.Find(idCart, idDT);
            var        cartS   = (List <DetailCart>)Session["CartSession"];

            if (cartS != null && cartS.Count() > 0)
            {
                cartS.Remove(product);
            }
            if (product != null)
            {
                try
                {
                    db.DetailCarts.Attach(product);
                    db.DetailCarts.Remove(product);
                    db.SaveChanges();
                }
                catch
                {
                }
                //
            }
            var model = new List <VIEW_detailCart>();

            if (AccountController.username != null)
            {
                model = db.Database.SqlQuery <VIEW_detailCart>("select * from VIEW_detailCart where username = '******'").ToList();
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
            return(PartialView("_PartialPage_CartProduct", model));
        }
示例#2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["LoginSession"] == null)
     {
         Response.Redirect("../HomeView/Home.aspx");
     }
     else
     {
         String ID   = Session["LoginSession"].ToString();
         MsUser user = HomeController.FetchDataForHome(ID);
         if (user.RoleID != "RL2")
         {
             Response.Redirect("../HomeView/Home.aspx");
         }
         else
         {
             if (!IsPostBack)
             {
                 String     ProductID = Request.QueryString["id"];
                 DetailCart cart      = UpdateCartController.GetCart(ID, ProductID);
                 LabelProductName.Text  = cart.ProductName.ToString();
                 LabelProductPrice.Text = cart.ProductPrice.ToString();
                 BoxQuantity.Text       = cart.ProductQuantity.ToString();
             }
         }
     }
 }
        public void AddItemToCast(string idDT, string idCart)
        {
            var        tour    = db.DestinationTours.Find(idDT);
            var        cart    = db.Carts.Find(idCart);
            DetailCart product = new DetailCart();

            if (tour != null && cart != null)
            {
                product.cartID    = idCart;
                product.desTourID = idDT;
                if (product.sl == null)
                {
                    product.sl = 0;
                }
                product.sl     = product.sl + 1;
                product.dayADD = DateTime.Now;
                //them vào db
                try
                {
                    var DC = db.DetailCarts.Find(idCart, idDT);
                    if (DC != null)
                    {
                        DC.sl     = DC.sl + 1;
                        DC.dayADD = DateTime.Now;
                    }
                    else
                    {
                        db.DetailCarts.Attach(product);
                        db.DetailCarts.Add(product);
                    }
                    db.SaveChanges();
                }
                catch
                {
                }
                // them vào section
                var cartS = (List <DetailCart>)Session["CartSession"];
                if (cartS != null)
                {
                    cartS.Add(product);
                    //Gán vào session
                    Session["CartSession"] = cartS;
                }
                else
                {
                    //tạo mới đối tượng cart item
                    cartS = new List <DetailCart>();
                    cartS.Add(product);
                    //Gán vào session
                    Session["CartSession"] = cartS;
                }
            }
        }
示例#4
0
        public ActionResult UpdateCart(List <RolesModel> objects)
        {
            List <CartSessionModel> cartSessions = Session[CommonConstants.Cart_Session] as List <CartSessionModel>;

            if (objects != null)
            {
                var user = Session[CommonConstants.User_SESSION] as UserSession;
                if (user != null)
                {
                    foreach (var item in objects)
                    {
                        Product    find       = new ProductDAO().FindProduct(Convert.ToInt32(item.Id));
                        DetailCart detailCart = new DetailCart()
                        {
                            customerId = user.UserID,
                            prId       = find.prId,
                            price      = find.price,
                            amounts    = Convert.ToInt32(item.Amounts),
                            status     = 1
                        };
                        var addCart = new DetailCartDAO().AddDetailOrder(detailCart);
                    }
                    foreach (var item in objects)
                    {
                        var id = Convert.ToInt32(item.Id);
                        CartSessionModel update = cartSessions.FirstOrDefault(x => x.PrId == id);
                        if (update != null)
                        {
                            update.Amounts = Convert.ToInt32(item.Amounts);
                        }
                    }
                }
                else
                {
                    foreach (var item in objects)
                    {
                        var id = Convert.ToInt32(item.Id);
                        CartSessionModel update = cartSessions.FirstOrDefault(x => x.PrId == id);
                        if (update != null)
                        {
                            update.Amounts = Convert.ToInt32(item.Amounts);
                        }
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
示例#5
0
 public int AddDetailOrder(DetailCart orderDetail)
 {
     try
     {
         int      res;
         object[] parameter =
         {
             new SqlParameter("@PrId",    orderDetail.prId),
             new SqlParameter("@OrderId", orderDetail.customerId),
             new SqlParameter("@Amounts", orderDetail.amounts),
             new SqlParameter("@Price",   orderDetail.price),
             new SqlParameter("@Status",  orderDetail.status)
         };
         res = dbContext.Database.ExecuteSqlCommand("AddDetail_Order @PrId,@OrderId,@Amounts,@Price,@Status", parameter);
         return(1);
     }
     catch
     {
         return(0);
     }
 }
示例#6
0
        public static Cart ConvertoCartEntityTOCartModel(AbbigliamentoECommerceEntity.Cart pCart)
        {
            Cart wCart = new Cart();

            wCart.ShippingCost = 5.00;
            wCart.TotalPrice   = pCart.listProduct.Sum(p => p.quantita * p.singleProduct.prezzo);
            wCart.Vat          = 1.06;
            wCart.DetailsCart  = new List <DetailCart>();
            foreach (AbbigliamentoECommerceEntity.CartDetail wCartDetail in pCart.listProduct)
            {
                DetailCart wDetailCart = new DetailCart();
                wDetailCart.Quantity   = wCartDetail.quantita;
                wDetailCart.Quantities = new Dictionary <int, int>();
                for (int i = 0; i < wCartDetail.singleProduct.Quantity; i++)
                {
                    wDetailCart.Quantities.Add(i, i + 1);
                }
                wDetailCart.Product = ProductEntityToProductModel.ConvertoProdyctEntityTOProductModel(wCartDetail.singleProduct);
                wCart.DetailsCart.Add(wDetailCart);
            }
            return(wCart);
        }
示例#7
0
        public ActionResult Login(User customers)
        {
            if (Membership.ValidateUser(customers.Username, customers.Password) && ModelState.IsValid)
            {
                var user   = new UserDAO();
                var result = user.LoginCheck(customers.Username, customers.Password, true);
                var login  = user.UserLogin(customers.Username);

                if (result == 1)
                {
                    FormsAuthentication.SetAuthCookie(customers.Username, customers.RememberMe);
                    var usersession = new UserSession()
                    {
                        UserID   = login.customerId,
                        UserName = login.username,
                        GroupId  = login.GroupId
                    };
                    var getcredential = user.GetListCredential(customers.Username);
                    Session.Add(CommonConstants.Credential_User, getcredential);
                    Session.Add(CommonConstants.User_SESSION, usersession);
                    if (Session[CommonConstants.Cart_Session] == null)
                    {
                        Session[CommonConstants.Cart_Session] = new List <CartSessionModel>();
                    }
                    List <CartSessionModel> cartSessions = Session[CommonConstants.Cart_Session] as List <CartSessionModel>;
                    var userLogin = Session[CommonConstants.User_SESSION] as UserSession;
                    if (userLogin.GroupId == "MEMBER")
                    {
                        return(RedirectToAction("Locked", "Error"));
                    }
                    /*Tạo cart*/
                    /*Khi đã đăng nhập*/

                    var findcart = new DetailCartDAO().FindList(userLogin.UserID, 1);
                    if (userLogin != null)
                    {
                        if (cartSessions != null || cartSessions.Count != 0)
                        {
                            if (findcart != null || findcart.Count != 0)
                            {
                                foreach (var item in cartSessions)
                                {
                                    var        findPr     = new ProductDAO().FindProduct(Convert.ToUInt32(item.PrId));
                                    DetailCart detailCart = new DetailCart()
                                    {
                                        customerId = userLogin.UserID,
                                        prId       = findPr.prId,
                                        price      = findPr.price,
                                        amounts    = item.Amounts,
                                        status     = 1
                                    };
                                    var addCart = new DetailCartDAO().AddDetailOrder(detailCart);
                                }
                                cartSessions.Clear();
                                foreach (var itemcart in findcart)
                                {
                                    var find = new ProductDAO().FindProduct(Convert.ToUInt32(itemcart.prId));
                                    CartSessionModel cartModel = new CartSessionModel()
                                    {
                                        PrId       = itemcart.prId,
                                        PrName     = find.prName,
                                        Price      = find.price,
                                        Amounts    = itemcart.amounts,
                                        AmountsMax = find.amount,
                                        Images     = find.images
                                    };
                                    cartSessions.Add(cartModel);
                                }
                                return(Redirect("~/Admin/CartCustomer/Index"));
                            }
                            return(Redirect("~/Admin/CartCustomer/Index"));
                        }
                        else
                        {
                            foreach (var item in findcart)
                            {
                                var findPr = new ProductDAO().FindProduct(Convert.ToUInt32(item.prId));
                                CartSessionModel cartModel = new CartSessionModel()
                                {
                                    PrId       = item.prId,
                                    PrName     = findPr.prName,
                                    Price      = findPr.price,
                                    Amounts    = item.amounts,
                                    AmountsMax = findPr.amount,
                                    Images     = findPr.images
                                };
                                cartSessions.Add(cartModel);
                            }
                            return(Redirect("~/Admin/CartCustomer/Index"));
                        }
                    }
                    /*Hết truy xuất giỏ hàng*/

                    return(Redirect("~/Admin/CartCustomer/Index"));
                }
                else if (result == 0)
                {
                    return(RedirectToAction("LockedAccount", "Error"));
                }
                else if (result == -1)
                {
                    return(RedirectToAction("AccountError", "Error"));
                }
                else if (result == -2)
                {
                    return(RedirectToAction("AccountError", "Error"));
                }
                else if (result == -3)
                {
                    var usersession = new UserSession()
                    {
                        UserID   = login.customerId,
                        UserName = login.username,
                        GroupId  = login.GroupId
                    };
                    Session.Add(CommonConstants.User_SESSION, usersession);
                    ModelState.AddModelError("", "Tài khoản của bạn không có quyền truy cập.");
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Server không phản hồi");
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
示例#8
0
        public ActionResult Waite()
        {
            if (Session[CommonConstants.Buy_Session] == null)
            {
                Session[CommonConstants.Buy_Session] = new List <CartSessionModel>();
            }
            List <CartSessionModel> buySessions = Session[CommonConstants.Buy_Session] as List <CartSessionModel>;
            var user = Session[CommonConstants.User_SESSION] as UserSession;

            if (user != null)
            {
                var findcart = new DetailCartDAO().FindList(user.UserID, 2);
                if (buySessions != null && buySessions.Count != 0)
                {
                    buySessions.Clear();
                    if (findcart != null || findcart.Count != 0)
                    {
                        foreach (var item in buySessions)
                        {
                            var        findPr     = new ProductDAO().FindProduct(Convert.ToUInt32(item.PrId));
                            DetailCart detailCart = new DetailCart()
                            {
                                customerId = user.UserID,
                                prId       = findPr.prId,
                                price      = findPr.price,
                                amounts    = item.Amounts,
                                status     = 2
                            };
                            var addCart = new DetailCartDAO().AddDetailOrder(detailCart);
                        }
                        foreach (var itemcart in findcart)
                        {
                            CartSessionModel cartModel = new CartSessionModel()
                            {
                                IdCart     = itemcart.id,
                                PrId       = itemcart.prId,
                                PrName     = itemcart.Product.prName,
                                Price      = itemcart.Product.price,
                                Amounts    = itemcart.amounts,
                                AmountsMax = itemcart.Product.amount,
                                Images     = itemcart.Product.images,
                                Status     = itemcart.status
                            };
                            buySessions.Add(cartModel);
                        }
                        return(View());
                    }
                }
                else
                {
                    foreach (var item in findcart)
                    {
                        CartSessionModel cartModel = new CartSessionModel()
                        {
                            IdCart     = item.id,
                            PrId       = item.prId,
                            PrName     = item.Product.prName,
                            Price      = item.Product.price,
                            Amounts    = item.amounts,
                            AmountsMax = item.Product.amount,
                            Images     = item.Product.images
                        };
                        buySessions.Add(cartModel);
                    }
                    ViewBag.Title        = "Giỏ hàng";
                    ViewBag.StatusCart   = "0";
                    ViewBag.Message      = "Hiện chưa có sản phẩm nào được đặt";
                    ViewBag.MessageOrder = "Hãy quay lại trang giỏ hàng để đặt hàng";
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("NotAccount", "Error"));
            }
            if (buySessions != null && buySessions.Count != 0)
            {
                ViewBag.Title      = "Sản phẩm đã đặt";
                ViewBag.StatusCart = "1";
                return(View());
            }
            else
            {
                ViewBag.Title        = "Giỏ hàng";
                ViewBag.StatusCart   = "0";
                ViewBag.Message      = "Hiện chưa có sản phẩm nào được đặt";
                ViewBag.MessageOrder = "Hãy quay lại trang giỏ hàng để đặt hàng";
                return(View());
            }
        }
示例#9
0
        // GET: Cart
        public ActionResult Index()
        {
            if (Session[CommonConstants.Cart_Session] == null)
            {
                Session[CommonConstants.Cart_Session] = new List <CartSessionModel>();
            }
            List <CartSessionModel> cartSessions = Session[CommonConstants.Cart_Session] as List <CartSessionModel>;
            var user = Session[CommonConstants.User_SESSION] as UserSession;

            if (user != null)
            {
                var findcart = new DetailCartDAO().FindList(user.UserID, 1);
                if (cartSessions != null && cartSessions.Count != 0)
                {
                    cartSessions.Clear();
                    if (findcart != null || findcart.Count != 0)
                    {
                        foreach (var item in cartSessions)
                        {
                            var        findPr     = new ProductDAO().FindProduct(Convert.ToUInt32(item.PrId));
                            DetailCart detailCart = new DetailCart()
                            {
                                customerId = user.UserID,
                                prId       = findPr.prId,
                                price      = findPr.price,
                                amounts    = item.Amounts,
                                status     = 1
                            };
                            var addCart = new DetailCartDAO().AddDetailOrder(detailCart);
                        }
                        foreach (var itemcart in findcart)
                        {
                            CartSessionModel cartModel = new CartSessionModel()
                            {
                                IdCart     = itemcart.id,
                                PrId       = itemcart.prId,
                                PrName     = itemcart.Product.prName,
                                Price      = itemcart.Product.price,
                                Amounts    = itemcart.amounts,
                                AmountsMax = itemcart.Product.amount,
                                Images     = itemcart.Product.images
                            };
                            cartSessions.Add(cartModel);
                        }
                        return(View());
                    }
                    ViewBag.Title        = "Giỏ hàng";
                    ViewBag.StatusCart   = "0";
                    ViewBag.Message      = "Hiện tại không có sản phẩm trong giỏ";
                    ViewBag.MessageOrder = "Hãy quay lại trang sản phẩm để mua thêm";
                    return(View());
                }
                else
                {
                    foreach (var item in findcart)
                    {
                        CartSessionModel cartModel = new CartSessionModel()
                        {
                            IdCart     = item.id,
                            PrId       = item.prId,
                            PrName     = item.Product.prName,
                            Price      = item.Product.price,
                            Amounts    = item.amounts,
                            AmountsMax = item.Product.amount,
                            Images     = item.Product.images
                        };
                        cartSessions.Add(cartModel);
                    }
                }
                return(View());
            }
            else if (cartSessions != null && cartSessions.Count != 0)
            {
                ViewBag.Title      = "Giỏ hàng";
                ViewBag.StatusCart = "1";
                return(View());
            }
            else
            {
                ViewBag.Title        = "Giỏ hàng";
                ViewBag.StatusCart   = "0";
                ViewBag.Message      = "Hiện tại không có sản phẩm trong giỏ";
                ViewBag.MessageOrder = "Hãy quay lại trang sản phẩm để mua thêm";
                return(View());
            }
        }
示例#10
0
        public ActionResult AddCart(long id, int amounts)
        {
            if (Session[CommonConstants.Cart_Session] == null)
            {
                Session[CommonConstants.Cart_Session] = new List <CartSessionModel>();
            }
            List <CartSessionModel> cartSessions = Session[CommonConstants.Cart_Session] as List <CartSessionModel>;
            var user = Session[CommonConstants.User_SESSION] as UserSession;

            if (user != null)
            {
                cartSessions.Clear();
                var        findlistcart = new DetailCartDAO().FindList(user.UserID, 1);
                var        findPr       = new ProductDAO().FindProduct(Convert.ToUInt32(id));
                DetailCart detailCart   = new DetailCart()
                {
                    customerId = user.UserID,
                    prId       = findPr.prId,
                    price      = findPr.price,
                    amounts    = amounts,
                    status     = 1
                };

                var addCart = new DetailCartDAO().AddDetailOrder(detailCart);
                if (addCart == 1)
                {
                    foreach (var item in findlistcart)
                    {
                        var find = new ProductDAO().FindProduct(Convert.ToUInt32(item.prId));
                        CartSessionModel cartModel = new CartSessionModel()
                        {
                            IdCart     = item.id,
                            PrId       = item.prId,
                            PrName     = find.prName,
                            Price      = find.price,
                            Amounts    = item.amounts,
                            AmountsMax = find.amount,
                            Images     = findPr.images
                        };
                        cartSessions.Add(cartModel);
                    }
                }
            }
            else
            {
                if (cartSessions.FirstOrDefault(m => m.PrId == id) == null)
                {
                    Product          find      = new ProductDAO().FindProduct(id);
                    CartSessionModel cartModel = new CartSessionModel()
                    {
                        IdCart     = Convert.ToInt32(id),
                        PrId       = find.prId,
                        PrName     = find.prName,
                        Price      = find.price,
                        Images     = find.images,
                        Amounts    = amounts,
                        AmountsMax = find.amount
                    };
                    cartSessions.Add(cartModel);
                }
                else
                {
                    CartSessionModel cartModel = cartSessions.FirstOrDefault(m => m.PrId == id);
                    cartModel.Amounts += amounts;
                }
            }
            return(RedirectToAction("Index"));
        }