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