public int OrderNow(int uid, int pid, OrderModel model)
        {
            using (ShoppingELFEntities context = new ShoppingELFEntities())
            {
                UserTable user = new UserTable();
                user = context.UserTable.FirstOrDefault(m => m.UserID == uid);
                SizeTable st = new SizeTable();
                st = context.SizeTable.FirstOrDefault(m => m.PID == pid);
                if (st.productQuantity > 0)
                {
                    OrderTable ot = new OrderTable()
                    {
                        UserID          = uid,
                        PID             = pid,
                        productBrand    = st.ProductTable.productBrand,
                        ProductName     = st.ProductTable.productName,
                        productPicture  = st.ProductTable.picture1,
                        productPrice    = st.productPrice,
                        productSize     = st.productSize,
                        productQuantity = 1
                    };
                    st.productQuantity -= 1;
                    context.OrderTable.Add(ot);
                    context.SaveChanges();

                    SizeTable seller = new SizeTable();
                    seller = context.SizeTable.FirstOrDefault(x => x.PID == pid);
                    ProductTable pp = new ProductTable();
                    pp = context.ProductTable.FirstOrDefault(m => m.ProductID == seller.ProductID);

                    SoldTable soldt = new SoldTable()
                    {
                        SellerID        = pp.SellerID,
                        productName     = st.ProductTable.productName,
                        productBrand    = st.ProductTable.productBrand,
                        productPrice    = st.productPrice,
                        productQuantity = 1,
                        productSize     = st.productSize,
                        productPicture  = st.ProductTable.picture1,
                        PID             = pid,
                        UserName        = user.email
                    };
                    context.SoldTable.Add(soldt);
                    context.SaveChanges();

                    return(1);
                }
                else
                {
                    return(0);
                }
            }
        }
        public int AddFromCartToOrder(int uid)
        {
            using (ShoppingELFEntities context = new ShoppingELFEntities())
            {
                CartTable ct   = new CartTable();
                SizeTable st   = new SizeTable();
                UserTable user = new UserTable();
                user = context.UserTable.FirstOrDefault(m => m.UserID == uid);
                var cart      = context.CartTable.Where(m => m.UserID == uid).ToList();
                var cartitems = context.CartTable.Where(m => m.UserID == uid).ToList();
                if (cart.Count > 0)
                {
                    foreach (var i in cartitems)
                    {
                        st = context.SizeTable.FirstOrDefault(x => x.PID == i.PID);
                        if (st.productQuantity > 0)
                        {
                            OrderTable ot = new OrderTable()
                            {
                                UserID          = uid,
                                productBrand    = i.SizeTable.ProductTable.productBrand,
                                ProductName     = i.SizeTable.ProductTable.productName,
                                productPicture  = i.SizeTable.ProductTable.picture1,
                                productPrice    = i.SizeTable.productPrice,
                                productSize     = i.SizeTable.productSize,
                                productQuantity = i.Quantity,
                                PID             = i.PID,
                            };

                            st.productQuantity -= i.Quantity;
                            context.OrderTable.Add(ot);
                            context.SaveChanges();

                            ProductTable seller = new ProductTable();
                            seller = context.ProductTable.FirstOrDefault(x => x.ProductID == i.SizeTable.ProductID);


                            SoldTable soldt = new SoldTable()
                            {
                                SellerID        = seller.SellerID,
                                productName     = i.SizeTable.ProductTable.productName,
                                productBrand    = i.SizeTable.ProductTable.productBrand,
                                productPrice    = i.SizeTable.productPrice,
                                productQuantity = i.SizeTable.productQuantity,
                                productSize     = i.SizeTable.productSize,
                                productPicture  = i.SizeTable.ProductTable.picture1,
                                PID             = i.PID,
                                UserName        = user.email
                            };
                            context.SoldTable.Add(soldt);
                            context.SaveChanges();
                            //return 1;
                        }
                        else
                        {
                            return(2);
                        }
                    }
                    return(3);
                }
                else
                {
                    return(0);
                }
            }
        }