예제 #1
0
        public static void DeleteProduct(String UserID, String ProductID)
        {
            MsCart cart = SearchCart(UserID, ProductID);

            db.MsCarts.Remove(cart);
            db.SaveChanges();
        }
예제 #2
0
        public static Response DoAddCart(String UserID, String ProductID, int qty)
        {
            MsProduct product   = Repository.RepositoryMsProduct.SearchProductByID(ProductID);
            int       servedqty = Repository.RepositoryCart.GetServedQty(ProductID);
            MsCart    cart      = Repository.RepositoryCart.SearchCart(UserID, ProductID);

            if (qty > product.ProductStock)
            {
                return(new Response(false, "Must Be Less than Or Equals to Product Stock"));
            }
            if ((qty + servedqty) > product.ProductStock)
            {
                return(new Response(false, "Must Be Less than Or Equals to Product Stock"));
            }

            if (cart == null)
            {
                Repository.RepositoryCart.InsertCart(UserID, ProductID, qty);
            }
            else
            {
                Repository.RepositoryCart.AppendCart(UserID, ProductID, qty);
            }

            return(new Response(true));
        }
예제 #3
0
        public static void AppendCart(String UserID, String ProductID, int qty)
        {
            MsCart cart = SearchCart(UserID, ProductID);

            cart.Quantity = cart.Quantity + qty;
            db.SaveChanges();
        }
예제 #4
0
        public static void UpdateCart(String ProductID, String UserID, int Quantity)
        {
            MsCart cart = SearchCart(UserID, ProductID);

            cart.Quantity = Quantity;
            db.SaveChanges();
        }
예제 #5
0
        public static MsCart InitCart(String UserID, String ProductID, int qty)
        {
            MsCart newcart = new MsCart();

            newcart.UserID    = UserID;
            newcart.ProductID = ProductID;
            newcart.Quantity  = qty;
            return(newcart);
        }
예제 #6
0
        public static int GetServedQty(String ProductID)
        {
            MsCart temp = (from x in db.MsCarts
                           where x.ProductID == ProductID
                           select x).FirstOrDefault();

            if (temp != null)
            {
                return((from x in db.MsCarts
                        where x.ProductID == ProductID
                        select x.Quantity).Sum());
            }
            else
            {
                return(0);
            }
        }
예제 #7
0
        public static void DoCheckout(String UserID, String PaymentID)
        {
            int numbercart = Repository.RepositoryCart.CountCart(UserID);
            int ID         = Repository.RepositoryHeaderTransaction.CountHeeader();

            Repository.RepositoryHeaderTransaction.InsertHeader(ID, UserID, PaymentID);

            for (int i = 0; i < numbercart; i++)
            {
                MsCart cart          = Repository.RepositoryCart.SearchUserCart(UserID);
                String TransactionID = "TR" + ID;
                String ProductID     = cart.ProductID;
                int    Quantity      = cart.Quantity;

                Repository.RepositoryDetailTransaction.insertDetail(TransactionID, ProductID, Quantity);
                Repository.RepositoryCart.DeleteProduct(UserID, ProductID);
                Repository.RepositoryMsProduct.UpdateStockProduct(ProductID, cart.Quantity);
            }
        }
예제 #8
0
        public static Response UpdateCart(String UserID, String ProductID, int Qty)
        {
            MsProduct product   = Repository.RepositoryMsProduct.SearchProductByID(ProductID);
            int       servedqty = Repository.RepositoryCart.GetServedQty(ProductID);
            MsCart    cart      = Repository.RepositoryCart.SearchCart(UserID, ProductID);

            if (Qty == cart.Quantity)
            {
                return(new Response(true));
            }
            if (Qty > product.ProductStock)
            {
                return(new Response(false, "Must Be Less than Or Equals to Product Stock"));
            }
            if ((Qty + servedqty) > product.ProductStock)
            {
                return(new Response(false, "Must Be Less than Or Equals to Product Stock"));
            }
            RepositoryCart.UpdateCart(ProductID, UserID, Qty);
            return(new Response(true));
        }