Esempio n. 1
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.");
            }
        }