Exemplo n.º 1
0
        void BindExample()
        {
            ShoppingData ds   = new ShoppingData();
            var          vrow = ds.Vendor.AddVendorRow("Kroger");

            ds.Item.AddItemRow("", "Butter", vrow, new DateTime(2030, 1, 1), 4, false);
            ds.Item.AddItemRow("", "Eggs", vrow, new DateTime(2030, 1, 5), 12, true);

            this.Gridc.BindGrid(ds.Item);

            IEnumerable <Col> cols = new[] {
                new Col(ds.Item.QuantityColumn),
                new Col(ds.Item.NameColumn),
                new Col(ds.Item.StockColumn)
                {
                    Tooltip = "have any in the pantry"
                },
                new Col(ds.Item.DateColumn)
                {
                    Format = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern
                }
            };

            this.Gridc.ConfigureColumns(cols);
        }
Exemplo n.º 2
0
 public static bool ValidateEmptyCart(int orderid)
 {
     if (OrderDataValidation.ValidateOrderExists(orderid))
     {
         if (ShoppingData.OrderCart(orderid).Count() == 0)
         {
             return(true);
         }
         else
         {
             if (ShoppingData.OrderCart(orderid).Where(c => c.C_Count != 0).Count() == 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     else
     {
         return(true);
     }
 }
 public IHttpActionResult GetCartDetail()
 {
     if (ShoppingData.CartsList().Any())
     {
         return(Ok(ShoppingData.CartsList()));
     }
     else
     {
         return(NotFound());
     }
 }
 public IHttpActionResult GetOrders()
 {
     if (ShoppingData.OrdersList().Any())
     {
         return(Ok(ShoppingData.OrdersList()));
     }
     else
     {
         return(NotFound());
     }
 }
 public IHttpActionResult GetProducts()
 {
     if (ShoppingData.ProductList().Any())
     {
         return(Ok(ShoppingData.ProductList()));
     }
     else
     {
         return(NotFound());
     }
 }
 public IHttpActionResult GetOrderDetails(int OrderID)
 {
     if (ShoppingData.CartsList().Any(c => c.C_OrderID == OrderID))
     {
         return(Ok(ShoppingData.CartsList().Where(c => c.C_OrderID == OrderID).ToList()));
     }
     else
     {
         return(NotFound());
     }
 }
Exemplo n.º 7
0
        public ActionResult ShopDetail()
        {
            ShoppingData shoppingData = (ShoppingData)Session["shopping_data"];
            string       code         = (string)Session["random_code"];

            ViewBag.code = code;
            if (shoppingData == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View(shoppingData));
            }
        }
        public IHttpActionResult RemoveProductFromCart(int OrderID, int ProductID)
        {
            if (OrderDataValidation.ValidateOpenOrder(OrderID))
            {
                if (ShoppingData.ProductList().Any(p => p.P_ID == ProductID))
                {
                    using (ShoppingEntities entities = new ShoppingEntities())
                    {
                        if (entities.Cart.Any(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID))
                        {
                            int NoOfItems = entities.Cart.Where(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID).First().C_Count;

                            if (NoOfItems > 0)
                            {
                                NoOfItems = NoOfItems - 1;

                                entities.Cart.First(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID).C_Count = NoOfItems;
                                entities.SaveChanges();
                                return(Ok("1 Item removed from Cart"));
                            }
                            else
                            {
                                return(BadRequest("0 items in Cart"));
                            }
                        }
                        else
                        {
                            return(BadRequest("Items not present in Cart"));
                        }
                    }
                }
                else
                {
                    return(BadRequest("Invalid Product ID"));
                }
            }
            else
            {
                return(BadRequest("Invalid OrderID"));
            }
        }
Exemplo n.º 9
0
        public ActionResult Buy(ShoppingData shoppingData)
        {
            Cart   cart       = (Session["cart"] == null) ? new Cart() : (Cart)Session["cart"];
            String randomCode = RandomString(10, false);

            if (cart.lstBooksId != null && cart.lstBooksId.Count > 0)
            {
                foreach (int book_id in cart.lstBooksId)
                {
                    db.Shops.Add(new Shop
                    {
                        Id_AspNetUsers = cart.User_Id,
                        Id_Book        = book_id,
                        Code           = randomCode
                    });
                }
            }
            var a = db.SaveChanges();

            Session["cart"]          = null;
            Session["shopping_data"] = shoppingData;
            Session["random_code"]   = randomCode;
            return(RedirectToAction("ShopDetail"));
        }
Exemplo n.º 10
0
        public ActionResult Buy()
        {
            Cart         cart         = (Session["cart"] == null) ? new Cart() : (Cart)Session["cart"];
            decimal      total        = (Session["total_shop"] == null) ? 0.0M : (decimal)Session["total_shop"];
            ShoppingData shoppingData = new ShoppingData();

            if (User.Identity.IsAuthenticated)
            {
                AspNetUser user = db.AspNetUsers.Where(x => x.UserName == User.Identity.Name).First();
                cart.User_Id            = user.Id;
                shoppingData.Address    = user.Address;
                shoppingData.City       = user.City;
                shoppingData.Country    = user.Country;
                shoppingData.PostalCode = user.PostalCode;
                shoppingData.Name       = user.UserName;
                shoppingData.Total      = total;
                return(View(shoppingData));
            }
            else
            {
                string returnUrl = Url.Action("Buy", "Cart");
                return(RedirectToAction("Login", "Account", new { returnUrl = returnUrl }));
            }
        }
Exemplo n.º 11
0
    public async static Task <string> ShoppingListData(string query)
    {
        var conn = new NpgsqlConnection(connectionString);
        await conn.OpenAsync();

        var shoppingData = new ShoppingData();

        using (var cmd = new NpgsqlCommand(query, conn))
            using (var reader = await cmd.ExecuteReaderAsync())
            {
                while (await reader.ReadAsync())
                {
                    shoppingData.UserId        = reader["userid"].ToString();
                    shoppingData.ShoppingItems = reader["shoppinglist"].ToString();
                    shoppingData.TickedItems   = reader["ticked"].ToString();
                }
            }

        conn.Close();

        var json = JsonConvert.SerializeObject(shoppingData);

        return(json);
    }
        public IHttpActionResult AddProductToCart(int OrderID, int ProductID)
        {
            if (OrderDataValidation.ValidateOpenOrder(OrderID))
            {
                if (ShoppingData.ProductList().Any(p => p.P_ID == ProductID))
                {
                    using (ShoppingEntities entities = new ShoppingEntities())
                    {
                        if (entities.Cart.Any(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID))
                        {
                            int NoOfItems = entities.Cart.Where(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID).First().C_Count;
                            NoOfItems = NoOfItems + 1;

                            entities.Cart.First(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID).C_Count = NoOfItems;
                            entities.SaveChanges();
                        }
                        else
                        {
                            entities.Cart.Add(new Cart {
                                C_OrderID = OrderID, C_ProductID = ProductID, C_Count = 1
                            });
                            entities.SaveChanges();
                        }
                        return(Ok("Item added in Cart"));
                    }
                }
                else
                {
                    return(BadRequest("Invalid Product ID"));
                }
            }
            else
            {
                return(BadRequest("Invalid OrderID"));
            }
        }
        public decimal TotalAfterDiscount(int orderid)
        {
            List <Cart>     myOrderCart;
            List <Products> allProducts;
            List <Discount> allDiscounts;

            decimal totalAmount = 0;
            decimal itemCost    = 0;

            myOrderCart  = ShoppingData.OrderCart(orderid).ToList();
            allDiscounts = ShoppingData.Discounts().ToList();
            allProducts  = ShoppingData.ProductList().ToList();

            foreach (var item in myOrderCart)
            {
                itemCost = 0;

                if (CartDataValidation.ValidateEmptyCartProduct(item))
                {
                    itemCost = 0;
                }
                else
                {
                    itemCost = itemCost + ItemCost(item, allProducts.First(p => p.P_ID == item.C_ProductID));

                    if (allDiscounts.Any(d => d.D_ProductID == item.C_ProductID))
                    {
                        foreach (var discount in allDiscounts.Where(d => d.D_ProductID == item.C_ProductID))
                        {
                            switch (discount.D_DiscountCode.ToUpper())
                            {
                            case "3FOR2":
                                itemCost = itemCost - ThreeForTwoDiscount(item, allProducts.First(p => p.P_ID == item.C_ProductID), discount);
                                continue;

                            default:
                                itemCost = itemCost - ProductDiscount(item, allProducts.First(p => p.P_ID == item.C_ProductID), discount);
                                continue;
                            }
                        }
                    }
                }

                totalAmount = totalAmount + itemCost;
            }

            if (allDiscounts.Any(d => d.D_ProductID == 0))
            {
                foreach (var discount in allDiscounts.Where(d => d.D_ProductID == 0))
                {
                    switch (discount.D_DiscountCode.ToUpper())
                    {
                    case "ALL10":
                        totalAmount = totalAmount - CommonDiscount(totalAmount, discount);
                        continue;

                    default:
                        totalAmount = totalAmount - CommonDiscount(totalAmount, discount);
                        continue;
                    }
                }
            }

            return(totalAmount);
        }