예제 #1
0
 public void applyCoupon(Coupon coupon)
 {
     if (coupon.MinProductPurchase <= ShoppingCartList.Sum(x => x.Product.Price * x.Quantity))
     {
         UsedCoupon.Add(coupon);
     }
 }
예제 #2
0
        public ActionResult OrderProduct(string Command)
        {
            if (Command == "AddMore")
            {
                ShoppingCartList sc = new ShoppingCartList();
                sc.PID    = Convert.ToInt32(Request.Form["txtid"]);
                sc.Qty    = Convert.ToInt32(Request.Form["txtqty"]);
                sc.TotAmt = sc.Qty * Convert.ToDecimal(Request.Form["txtprice"]);
                string data = sc.PID + "," + sc.Qty + "," + sc.TotAmt + ":";
                Session["templst"] += data;

                return(RedirectToAction("CreateOrder", "User"));
            }
            if (Command == "Pay Now")
            {
                ShoppingCartList sc = new ShoppingCartList();
                sc.PID    = Convert.ToInt32(Request.Form["txtid"]);
                sc.Qty    = Convert.ToInt32(Request.Form["txtqty"]);
                sc.TotAmt = sc.Qty * Convert.ToDecimal(Request.Form["txtprice"]);
                string data = sc.PID + "," + sc.Qty + "," + sc.TotAmt + ":";
                Session["templst"] += data;
                return(RedirectToAction("CardInfo", "Gateway"));
            }
            return(View());
        }
예제 #3
0
        protected void stockList_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            ShoppingCartList.Visible = true;
            totalLabel.Visible       = true;
            TotalbuttonLabel.Visible = true;

            string username = User.Identity.Name;
            int    itemid   = int.Parse(e.CommandArgument.ToString());
            int    employeeid;

            MessageUserControl.TryRun(() =>
            {
                //connect to your BLL
                ApplicationUserManager secmgr = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                EmployeeInfo info             = secmgr.User_GetEmployee(username);
                employeeid   = info.EmployeeID;
                int quantity = int.Parse((e.Item.FindControl("QuantityLabel") as TextBox).Text);
                ShoppingCartItemController sysmgr = new ShoppingCartItemController();
                sysmgr.Add_AddToCart(employeeid, itemid, quantity);//Need to put the quantity in the list!!!!!

                List <UserShoppingCartItem> infos = sysmgr.List_ItemsForShoppingCart(employeeid);
                notificationIcon.Style.Remove("visibility");
                //TotalButton.InnerText = (e.Item.FindControl("Total") as Label).ToString();
                ShoppingCartList.DataSource = infos;
                notificationIcon.Value      = infos.Count.ToString();
                ShoppingCartList.DataBind();

                refresh_totallabel();
            }, "Shopping Items Added", $"The item has been addded, you have currently {notificationIcon.Value} items in the shopping cart");
        }
예제 #4
0
        // GET: Gateway
        public ActionResult CardInfo()
        {
            decimal finalamt = 0.0M;

            if (Session["templst"] == null)
            {
            }
            else
            {
                string   data = Session["templst"].ToString();
                string[] rows = data.Split(':');
                foreach (var r in rows)
                {
                    if (!string.IsNullOrEmpty(r))
                    {
                        string[]         cols = r.Split(',');
                        ShoppingCartList sc   = new ShoppingCartList();
                        sc.PID    = Convert.ToInt32(cols[0]);
                        sc.Qty    = Convert.ToInt32(cols[1]);
                        sc.TotAmt = Convert.ToDecimal(cols[2]);
                        lst.Add(sc);
                        finalamt += sc.TotAmt;
                    }
                }
            }
            Session["finalamt"] = finalamt;
            Session["lst"]      = lst;
            return(View(lst));
        }
예제 #5
0
 public void removeItem(Product Product, int Quantity)
 {
     if (ShoppingCartList.Single(x => x.Product == Product).Quantity > Quantity)
     {
         ShoppingCartList.Single(x => x.Product == Product).Quantity -= Quantity;
     }
     else
     {
         ShoppingCartList.Remove(ShoppingCartList.Single(x => x.Product == Product));
     }
 }
 public void CheckIfCartEmpty()
 {
     if (ShoppingCartList.Any())
     {
         CartVisibility = Visibility.Visible;
     }
     else
     {
         CartVisibility = Visibility.Collapsed;
     }
 }
예제 #7
0
 public void addItem(Product Product, int Quantity)
 {
     if (ShoppingCartList.Where(x => x.Product == Product).Count() > 0)
     {
         ShoppingCartList.Single(x => x.Product == Product).Quantity += Quantity;
     }
     else
     {
         ShoppingCartList.Add(new ShoppingChartItem(Product, Quantity));
     }
 }
예제 #8
0
        private void Bind()
        {
            if (CurrentCart.Items.Count() == 0)
            {
                EmptyCartPanel.Visible = true;
            }
            else
            {
                EmptyCartPanel.Visible = false;
            }

            ShoppingCartList.DataSource = CurrentCart.Items;
            ShoppingCartList.DataBind();
        }
        /// <summary>
        /// Executes the order command
        /// </summary>
        public void OrderExecute()
        {
            try
            {
                service.AddOrder(LoggedUser.CurrentUser.UserID);
                UserOrderList = service.GetAllUserOrders(LoggedUser.CurrentUser.UserID).ToList();

                UserShoppingCartList.Clear();
                ShoppingCartList.RemoveAll(i => i.UserID == LoggedUser.CurrentUser.UserID);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
 /// <summary>
 /// Checks if the order can be added
 /// </summary>
 /// <returns>true if possible</returns>
 public bool CanOrderExecute()
 {
     if (LoggedUser.CurrentUser.UserAddress == null)
     {
         return(false);
     }
     if (!ShoppingCartList.Any())
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
예제 #11
0
        protected void ShoppingCartList_OnDataBound(object sender, EventArgs e)
        {
            if (CurrentCart.Items.Count() == 0)
            {
                return;
            }

            Literal SubTotal        = (Literal)ShoppingCartList.FindControl("SubTotal");
            var     ShoppingCartTax = (Literal)ShoppingCartList.FindControl("ShoppingCartTax");
            Literal Total           = (Literal)ShoppingCartList.FindControl("Total");

            SubTotal.Text        = CurrentCart.GetSubTotal().ToString();
            Total.Text           = CurrentCart.GetTotal().ToString();
            ShoppingCartTax.Text = SettingsMapper.GetSettings().ShoppingCartTax.ToString();
        }
예제 #12
0
        public void refresh_shoppingcart()
        {
            string username = User.Identity.Name;
            int    employeeid;
            ApplicationUserManager secmgr = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            EmployeeInfo           info   = secmgr.User_GetEmployee(username);

            employeeid = info.EmployeeID;

            ShoppingCartItemController  systemmgr = new ShoppingCartItemController();
            List <UserShoppingCartItem> infos     = systemmgr.List_ItemsForShoppingCart(employeeid);

            ShoppingCartList.DataSource = infos;
            ShoppingCartList.DataBind();
            totalLabel.DataBind();
        }
 /// <summary>
 /// Executes the add command
 /// </summary>
 public void RemoveItemExecute()
 {
     try
     {
         if (Item != null)
         {
             service.RemoveItem(Item, LoggedUser.CurrentUser.UserID);
             ShoppingCartList.RemoveAll(i => i.UserID == LoggedUser.CurrentUser.UserID && i.ItemID == Item.ItemID);
             ShoppingCartList = service.GetAllUserShoppingCarts(LoggedUser.CurrentUser.UserID).ToList();
             TotalLabel       = service.TotalValue();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
 /// <summary>
 /// Executes the add command
 /// </summary>
 public void RemoveItemExecute()
 {
     try
     {
         if (Item != null)
         {
             service.RemoveItem(Item, Service.LoggedInUser[0].UserID);
             UserShoppingCartList.RemoveAll(i => i.UserID == Service.LoggedInUser[0].UserID && i.ItemID == Item.ItemID);
             ShoppingCartList.RemoveAll(i => i.UserID == Service.LoggedInUser[0].UserID && i.ItemID == Item.ItemID);
             UserShoppingCartList = service.GetAllUserShoppingCarts(Service.LoggedInUser[0].UserID).ToList();
             ShoppingCartList     = service.GetAllShoppingCarts();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
예제 #15
0
        public double getCampaignDiscount(List <Campaign> campaigns)
        {
            double CampaignDiscount = 0;

            foreach (var item in campaigns)
            {
                if (ShoppingCartList.Count(x => x.Product.Category == item.Category) >= item.MinProductQuantity)
                {
                    if (item.Type == DiscountType.Amount)
                    {
                        CampaignDiscount += item.DiscountPrice;
                    }
                    else
                    {
                        CampaignDiscount += ShoppingCartList.Where(x => x.Product.Category == item.Category).Sum(x => x.Quantity * x.Product.Price) * item.DiscountPrice / 100;
                    }
                }
            }
            return(CampaignDiscount);
        }
예제 #16
0
        public double getCouponDiscount()
        {
            double CouponDiscount = 0;

            foreach (var item in UsedCoupon)
            {
                if (ShoppingCartList.Sum(x => x.Quantity * x.Product.Price) >= item.MinProductPurchase)
                {
                    if (item.Type == DiscountType.Amount)
                    {
                        CouponDiscount += item.DiscountPrice;
                    }
                    else
                    {
                        CouponDiscount += ShoppingCartList.Sum(x => x.Quantity * x.Product.Price) * item.DiscountPrice / 100;
                    }
                }
            }
            return(CouponDiscount);
        }
예제 #17
0
    protected void ShoppingCartList_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        ListViewDataItem row = e.Item as ListViewDataItem;

        string username = User.Identity.Name;

        int partid = int.Parse(e.CommandArgument.ToString());

        SalesController sysmgr = new SalesController();

        if (e.CommandName == "Change")
        {
            int quantity = int.Parse((row.FindControl("QuantityTextBox") as TextBox).Text.ToString());

            if (quantity < 1)
            {
                MessageUserControl.ShowInfo("Warning", "Quantity must be at least 1");
            }
            else
            {
                MessageUserControl.TryRun(() =>
                {
                    sysmgr.Update_CartItem(username, partid, quantity);
                }, "Success", "Item quantity updated");
            }
        }
        else
        {
            MessageUserControl.TryRun(() =>
            {
                sysmgr.Remove_CartItem(username, partid);
            }, "Success", "Item removed");
        }

        ShoppingCartList.DataBind();

        TotalsGridView.DataBind();

        Page_Load(this, e);
    }
    protected void PlaceOrderBtn_Click(object sender, EventArgs e)
    {
        string username = User.Identity.Name;

        int couponid = int.Parse(CouponListDD.SelectedValue);

        FinalTotalPOCO totals = new FinalTotalPOCO();

        totals.SubTotal = decimal.Parse(TotalsGridView.DataKeys[0].Values[0].ToString());
        totals.Discount = decimal.Parse(TotalsGridView.DataKeys[0].Values[1].ToString());
        totals.GST      = decimal.Parse(TotalsGridView.DataKeys[0].Values[2].ToString());
        totals.Total    = decimal.Parse(TotalsGridView.DataKeys[0].Values[3].ToString());

        string paymethod = PaymentMethodRB.SelectedValue;

        MessageUserControl.TryRun(() =>
        {
            SalesController sysmgr  = new SalesController();
            List <Part> backordered = sysmgr.Place_Order(username, couponid, totals, paymethod);

            if (backordered.Count > 0)
            {
                backorderalertlabel.Text = "";
                string backorderalert    = "The following items have been backordered: ";

                foreach (Part part in backordered)
                {
                    backorderalert += part.Description + " ";
                }

                backorderalertlabel.Visible = true;
                backorderalertlabel.Text    = backorderalert;
            }

            ShoppingCartList.DataBind();
            TotalsGridView.DataBind();
        }, "Success", "Your order has been processed.");
    }
예제 #19
0
        protected void ShoppingCartList_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "remove")
            {
                string username = User.Identity.Name;
                int    itemid   = int.Parse(e.CommandArgument.ToString());
                int    employeeid;

                if (ShoppingCartList.Items.Count == 0)
                {
                    MessageUserControl.ShowInfo("Warning", "You have clear the shopping cart.");
                }
                else
                {
                    MessageUserControl.TryRun(() =>
                    {
                        ApplicationUserManager secmgr = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                        EmployeeInfo info             = secmgr.User_GetEmployee(username);
                        employeeid = info.EmployeeID;
                        ShoppingCartItemController sysmgr = new ShoppingCartItemController();
                        sysmgr.DeleteShoppingItems(employeeid, itemid);

                        List <UserShoppingCartItem> infos = sysmgr.List_ItemsForShoppingCart(employeeid);
                        ShoppingCartList.DataSource       = infos;
                        notificationIcon.Value            = infos.Count.ToString();
                        ShoppingCartList.DataBind();
                        totalLabel.DataBind();

                        refresh_totallabel();
                    }, "Removed", $"Item(s) {itemid} have been removed");
                }
            }
            else if (e.CommandName == "refresh")
            {
                string username = User.Identity.Name;
                int    itemid   = int.Parse(e.CommandArgument.ToString());
                int    employeeid;
                int    quantity = int.Parse((e.Item.FindControl("QuantityLabel") as TextBox).Text);

                MessageUserControl.TryRun(() =>
                {
                    ApplicationUserManager secmgr = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                    EmployeeInfo info             = secmgr.User_GetEmployee(username);
                    employeeid = info.EmployeeID;
                    ShoppingCartItemController sysmgr = new ShoppingCartItemController();
                    sysmgr.Update_RefreshCart(employeeid, itemid, quantity);

                    List <UserShoppingCartItem> infos = sysmgr.List_ItemsForShoppingCart(employeeid);
                    ShoppingCartList.DataSource       = infos;
                    notificationIcon.Value            = infos.Count.ToString();
                    ShoppingCartList.DataBind();
                    totalLabel.DataBind();

                    refresh_totallabel();
                }, "Updated", $"Item(s) {itemid} have been updated");
            }
            else
            {
                MessageUserControl.ShowInfo("Glad you found this error, cauz I don't even know what should I call this error.");
            }
        }
예제 #20
0
 public double getDeliveryCost(List <Campaign> campaigns)
 {
     return(ShoppingCartList.Sum(x => x.Quantity * x.Product.Price) - getTotalAmountAfterDiscounts(campaigns));
 }
예제 #21
0
        protected void PlaceOrder_Click(object sender, EventArgs e)
        {
            List <SaleDetailsList> listsaledetails = new List <SaleDetailsList>();
            List <ListSale>        listsales       = new List <ListSale>();
            string username = User.Identity.Name;
            int    employeeid;

            if (SaleList.Items.Count == 0)
            {
                MessageUserControl.ShowInfo("Warning", "Please add at least one product in order to place order.");
            }
            else
            {
                if (PaymentTypeDDL.SelectedIndex == 0)
                {
                    MessageUserControl.ShowInfo("Warning", "Please select a payment method to place order.");
                }
                else
                {
                    MessageUserControl.TryRun(() =>
                    {
                        ApplicationUserManager secmgr = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                        EmployeeInfo info             = secmgr.User_GetEmployee(username);
                        employeeid = info.EmployeeID;

                        foreach (ListViewItem item in SaleList.Items)
                        {
                            Label quantityLabel     = item.FindControl("QuantityLabel") as Label;
                            Label priceLabel        = item.FindControl("PriceLabel") as Label;
                            HiddenField itemIDLabel = item.FindControl("StockItemIDLabel") as HiddenField;
                            Label descriptionLabel  = item.FindControl("DescriptionLabel") as Label;

                            SaleDetailsList newSaleDetailsList = new SaleDetailsList();
                            newSaleDetailsList.Description     = descriptionLabel.Text;
                            newSaleDetailsList.Price           = decimal.Parse(priceLabel.Text.Replace(@"$", string.Empty));
                            newSaleDetailsList.Quantity        = int.Parse(quantityLabel.Text);
                            newSaleDetailsList.StockItemID     = int.Parse(itemIDLabel.Value);
                            listsaledetails.Add(newSaleDetailsList);
                        }

                        Label SubtotalLabel    = (Label)UpdatePanel3.FindControl("totalLabel2") as Label;
                        Label taxLabel         = (Label)UpdatePanel3.FindControl("TaxLabel") as Label;
                        CouponController cpmgr = new CouponController();
                        Coupon coupon          = cpmgr.Coupons_Get(CouponTextBox.Text);

                        ListSale newSaleList    = new ListSale();
                        newSaleList.PaymentType = PaymentTypeDDL.SelectedItem.ToString();
                        newSaleList.CouponID    = coupon == null ? null : coupon.CouponID;
                        newSaleList.SubTotal    = decimal.Parse(SubtotalLabel.Text.Replace(@"$", string.Empty));
                        newSaleList.TaxAmount   = decimal.Parse(taxLabel.Text.Replace(@"$", string.Empty));
                        listsales.Add(newSaleList);

                        SaleDetailController sysmgr = new SaleDetailController();
                        sysmgr.Add_AddToSale(employeeid, listsales, listsaledetails);

                        foreach (ListViewItem item in SaleList.Items)
                        {
                            HiddenField itemidLabel = item.FindControl("ItemIDLabel") as HiddenField;
                            int itemid = int.Parse(itemidLabel.Value);
                            ShoppingCartItemController spcitemmgr = new ShoppingCartItemController();
                            spcitemmgr.DeleteShoppingItems(employeeid, itemid);
                        }

                        ShoppingCartController spcmgr = new ShoppingCartController();
                        spcmgr.DeleteShoppingCart(employeeid);

                        //refresh the table
                        ShoppingCartItemController systemmgr = new ShoppingCartItemController();
                        List <UserShoppingCartItem> infos    = systemmgr.List_ItemsForShoppingCart(employeeid);
                        ShoppingCartList.DataSource          = infos;
                        ShoppingCartList.DataBind();

                        subtotalLabel.Text           = "$" + "0";
                        TaxLabel.Text                = "$" + "0";
                        CouponTextBox.Text           = "";
                        DiscountLabel.Text           = "$" + "0";
                        totalLabel2.Text             = "$" + "0";
                        PaymentTypeDDL.SelectedIndex = 0;
                    }, "Success", "Order has been placed");
                }
            }
        }