protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e) { mShoppingBag = (ShoppingBag)Session["mShoppingBag"]; ProductInBag product = new ProductInBag(); GridViewRow row = GridView2.Rows[e.RowIndex]; product.ProdID = int.Parse(row.Cells[0].Text); mShoppingBag.DeleteProduct(product); Session["mShoppingBag"] = mShoppingBag; GridView2.EditIndex = -1; populate_GridView2(); }
public ShoppingBag GetShoppingBagAndCreateIfNeeded(Guid userGuid) { var bag = GetByUserGuidOrNulld(userGuid); if (bag == null) { bag = new ShoppingBag(userGuid); Add(new ShoppingBag(userGuid)); } Update(bag); return(bag); }
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e) { mShoppingBag = (ShoppingBag)Session["mShoppingBag"]; ProductInBag product = new ProductInBag(); GridViewRow row = GridView2.Rows[e.RowIndex]; product.ProdID = int.Parse(row.Cells[0].Text); product.Quantity = short.Parse(((TextBox)row.Cells[2].Controls[0]).Text); mShoppingBag.UpdateProduct(product); Session["mShoppingBag"] = mShoppingBag; GridView2.EditIndex = -1; populate_GridView2(); }
public async Task <IActionResult> Details(int id) { var menuItemFromDb = await _db.MenuItem.Include(m => m.Category).Include(m => m.SubCategory).Where(m => m.Id == id).FirstOrDefaultAsync(); ShoppingBag cartObj = new ShoppingBag() { MenuItem = menuItemFromDb, MenuItemId = menuItemFromDb.Id }; return(View(cartObj)); }
protected void Page_Load(object sender, EventArgs e) { if (Session["mShoppingBag"] == null) { mShoppingBag = new ShoppingBag(); Button1.Visible = false; } else { mShoppingBag = (ShoppingBag)Session["mShoppingBag"]; Button1.Visible = true; } }
private static void VerifyShoppingBagWithProducts(ShoppingBag expected, ShoppingBag actual) { Assert.NotNull(actual); Assert.AreEqual(expected.Guid, actual.Guid); Assert.AreEqual(expected.UserGuid, actual.UserGuid); Assert.AreEqual(expected.ShoppingCarts.Count, actual.ShoppingCarts.Count); for (var i = 0; i < actual.ShoppingCarts.Count; i++) { var expec = expected.ShoppingCarts.ElementAt(i); var act = actual.ShoppingCarts.ElementAt(i); VerifyCart(expec, act); } }
public void RecalcShoppingBag(int shoppingBagId) { ShoppingBag sb = GetById(shoppingBagId); double total = 0; foreach (ShoppingItem shoppingItem in sb.Items) { total += shoppingItem.Quantity * shoppingItem.Product.Price; } sb.TotalPrice = total; _context.ShoppingBags.Update(sb); _context.SaveChanges(); }
public IActionResult NewShoppingBag(NewShoppingBagVM newShoppingBagVM) { ShoppingBag sb = new ShoppingBag() { Customer = _customerService.GetById(newShoppingBagVM.Customer.Id), Date = newShoppingBagVM.Date }; _ShoppingBagService.NewShoppingBag(sb); return(RedirectToAction("DetailBag", new { id = sb.Id })); }
public void showShoppingBag(ShoppingBag sb) { if (sb == null || sb.GetProducts().Count == 0) { ShowShoppingbag.Visible = false; Response.Write("<script>alert('הסל ריק')</script>"); } else { ShowShoppingbag.Visible = true; ShowShoppingbag.DataSource = sb.GetProducts(); ShowShoppingbag.DataBind(); } }
public IShoppingBag GetShoppingBag(int totalSnackProduct, double productCost) { IShoppingBag shoppingBag = new ShoppingBag(); shoppingBag.AddProduct(new Product(ProductName.KitchenEquipment, 195.50)); shoppingBag.AddProduct(new Product(ProductName.Furniture, 150)); for (int i = 0; i < totalSnackProduct; i++) { shoppingBag.AddProduct(new Product(ProductName.Snack, productCost)); } return(shoppingBag); }
public IShoppingBag GetShoppingBag(int totalSnackProduct, double totalFurnitureCost) { var shoppingBag = new ShoppingBag(); shoppingBag.AddProduct(new Product(ProductName.Book, 150)); shoppingBag.AddProduct(new Product(ProductName.Furniture, totalFurnitureCost)); shoppingBag.AddProduct(new Product(ProductName.Medicine, _medicineCostForDiscountPromotionTest)); shoppingBag.AddProduct(new Product(ProductName.KitchenEquipment, 100)); for (int i = 0; i < totalSnackProduct; i++) { shoppingBag.AddProduct(new Product(ProductName.Snack, _snackCostForDiscountPromotionTest)); } return(shoppingBag); }
private ShoppingBag GetShoppingBag(string customerId) { var shoppingBag = _shoppingBagRepository.GetShoppingBag(customerId); if (shoppingBag == null) { var newShoppingBag = new ShoppingBag { Customer = _customerRepository.GetCustomer(customerId), Date = DateTime.Now, Items = new List <ShoppingItem>() }; shoppingBag = newShoppingBag; _shoppingBagRepository.AddItem(shoppingBag); } return(shoppingBag); }
public ActionResult AddToCart(string ProductId) { var prodId = int.Parse(ProductId); var product = productHandler.GetProduct(prodId); var productForCart = new ProductViewModel { Name = product.Name, Price = product.Price, Quantity = 1, ProductId = product.ProductId }; ShoppingBag.AddToCart(productForCart); return(null); }
public ShoppingBag GetShoppingBag(string customerId) { var userShoppingBag = _bikeDbContext.ShoppingBags.Include(s => s.Items).ThenInclude(i => i.Product).Include(c => c.Customer).FirstOrDefault(s => s.Customer.Id == customerId); if (userShoppingBag == null) { userShoppingBag = new ShoppingBag { UserId = customerId, Date = DateTime.Now, }; _bikeDbContext.ShoppingBags.Add(userShoppingBag); _bikeDbContext.SaveChanges(); return(userShoppingBag); } return(userShoppingBag); }
protected void SeeShoppingBag_Click(object sender, EventArgs e) { User temp = (User)Session["user"]; if (temp == null) { Response.Write("<script>alert('על מנת לרכוש מוצרים עליך להיות לקוח רשום')</script>"); Response.Write("<script>window.open('http://localhost:49675/GuestHome.aspx');</script>"); return; } ShoppingBag sb = (ShoppingBag)Session["myShoppingBag"]; if (sb == null || sb.isEmpty()) { Response.Write("<script>alert('הסל ריק')</script>"); return; } Response.Write("<script>window.open('http://localhost:49675/UserShoppingBag.aspx','_blank');</script>"); }
public ShoppingBagService(IServiceProvider services, IProductService productService) { ISession session = services.GetRequiredService <IHttpContextAccessor>()?.HttpContext.Session; _productService = productService; string bagId = session.GetString("bagId") ?? Guid.NewGuid().ToString(); session.SetString("bagId", bagId); ShoppingBagId = Guid.Parse(bagId); var shoppingBag = _shoppingBag.Where(b => b.Id == Guid.Parse(bagId)).FirstOrDefault(); if (shoppingBag == null) { shoppingBag = new ShoppingBag(ShoppingBagId); } _shoppingBag.Add(shoppingBag); }
internal void FillCheckoutInfoData(ShoppingBag bag, string action) { if (action.Equals("Contact Info")) { logOut.ClickButton(); Wait.Seconds(2); checkoutEmail.InputKey(bag.Email); DictionaryProperties.Details["Email"] = bag.Email; } else if (action.Equals("Shipping address")) { checkoutAddress1.InputKey(bag.AddressEdit); autocompleteAddress.UntilElementIsDisplayed(new TimeSpan(0, 0, 30)); autocompleteAddress.SelectElementFromLooping(bag.AddressToBeSelectedEdit).ClickAndHold(); Wait.Seconds(1); checkoutEmail.Click(); DictionaryProperties.Details["Address"] = checkoutAddress1.GetElementValueByAttribute("value"); DictionaryProperties.Details["City"] = checkoutCity.GetElementValueByAttribute("value"); DictionaryProperties.Details["PinCode"] = checkoutZipCode.GetElementValueByAttribute("value"); } }
public void CalculateTotalSales_NotImport_NonExempt() { List <Product> products = new List <Product>(); ShoppingBag cart = new ShoppingBag(); products.Add(new Product { ShoppingBagID = 1, ProductName = "stuff", Quantity = 1, Price = 10.00M, IsImport = false, IsExempt = false }); cart.Products = products; RecieptGenerator.Calculation tax = new RecieptGenerator.Calculation(); var result = tax.CalculateTotalSales(cart); Assert.AreEqual(result, 11.00M); }
static void Main() { var shoppingBag = new ShoppingBag { Items = new ShoppingBagItems { Fruits = new List <Fruit>(new[] { new Fruit { Name = "pineapple" }, new Fruit { Name = "kiwi" }, }), TestAttribute = "foo" } }; var serializer = new XmlSerializer(typeof(ShoppingBag)); serializer.Serialize(Console.Out, shoppingBag); }
public void AddRandomData() { ShoppingBag newBag = new ShoppingBag(); newBag.Customer = PickRandomCustomer(); newBag.Date = DateTime.Now; int randomshoppingitems = r.Next(1, 5); for (int i = 0; i < randomshoppingitems; i++) { Product p; do { p = PickRandomProduct(); } while (newBag.Items != null && newBag.Items.Where(item => item.Product.Id == p.Id).Any()); int randomQty = r.Next(1, 11); ShoppingItem s = new ShoppingItem { Bag = newBag, Product = p, Quantity = randomQty }; _context.ShoppingItems.Add(s); newBag.Items.Add(s); } foreach (ShoppingItem item in newBag.Items) { newBag.TotalPrice += item.Quantity * item.Product.Price; } _context.ShoppingBags.Add(newBag); _context.SaveChanges(); }
public async Task <IActionResult> Details(ShoppingBag ShopCart) { ShopCart.Id = 0; if (ModelState.IsValid) { var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShopCart.ApplicationUserId = claim.Value; ShoppingBag cartFromDb = await _db.ShoppingBag.Where(c => c.ApplicationUserId == ShopCart.ApplicationUserId && c.MenuItemId == ShopCart.MenuItemId).FirstOrDefaultAsync(); if (cartFromDb == null) { await _db.ShoppingBag.AddAsync(ShopCart); } else { cartFromDb.Count += ShopCart.Count; } await _db.SaveChangesAsync(); var count = _db.ShoppingBag.Where(c => c.ApplicationUserId == ShopCart.ApplicationUserId).ToList().Count; HttpContext.Session.SetInt32(SD.ssShoppingCartCount, count); return(RedirectToAction("Index")); } else { var MenuItemFromDb = await _db.MenuItem.Include(m => m.Category).Include(m => m.SubCategory).Where(m => m.Id == ShopCart.MenuItem.Id).FirstOrDefaultAsync(); ShoppingBag cartObj = new ShoppingBag() { MenuItem = MenuItemFromDb, MenuItemId = MenuItemFromDb.Id }; return(View(cartObj)); } }
public int CreateOrder(ShoppingBag bag, string email) { var user = this.GetUser(email); var order = new Order { State = State.Received, User = user, Timestamp = DateTime.UtcNow }; var books = this.GetBooksByIds(bag.BookIds); foreach (var item in bag.BookIds) { var orderItem = new OrderItem { Order = order, Book = books.Single(x => x.BookId == item), Quantity = bag.Quantity(item) }; order.Items.Add(orderItem); } user.Orders.Add(order); this._ctx.SaveChanges(); this._diagnosticSource.Write("OnOrderCreated", new { orderId = order.OrderId }); return(order.OrderId); }
public ActionResult AddtoCart(string Souvenir) { List <Souvenir> ShoppingBag; // reference to null if (Session["Cart"] == null) // the cart is empty! { Session.Add("Cart", new List <Souvenir>()); ShoppingBag = new List <Souvenir>(); } else// user has items in the cart, so go and retrive it! { ShoppingBag = (List <Souvenir>)Session["Cart"]; } /////////////////////////// maedbEntities2 ItemList = new maedbEntities2(); Souvenir Option = ItemList.Souvenirs.Find(Souvenir); ShoppingBag.Add(Option); Session["Cart"] = ShoppingBag;// save changes you made to your cart! ViewBag.Cart = ShoppingBag; maedbEntities2 NewList = new maedbEntities2(); List <Souvenir> AllProducts = NewList.Souvenirs.ToList(); ViewBag.PList = AllProducts; return(RedirectToAction("Product")); }
protected void CheckoutButton_Click(object sender, EventArgs e) { User temp = (User)Session["user"]; if (temp == null) { Response.Write("<script>alert('על מנת לרכוש מוצרים עליך להיות לקוח רשום')</script>"); Response.Write("<script>window.open('http://localhost:49675/GuestHome.aspx');</script>"); return; } ShoppingBag sb = (ShoppingBag)Session["myShoppingBag"]; if (sb == null || sb.isEmpty()) { Response.Write("<script>alert('הסל ריק')</script>"); return; } //delete all the prescription from database presList = (List <DataSet>)Session["presList"]; int presId; PrescriptioService ps = new PrescriptioService(); if (presList != null) { foreach (DataSet d in presList) { presId = Convert.ToInt32(d.Tables[0].Rows[0]["PrescriptionId"].ToString()); ps.DeletePrescription(presId); } } //update all the medicine stock according to the current count Pharmcy.PharmcyWS webser = new Pharmcy.PharmcyWS(); int totalPrice = sb.GetTotalPrice(); List <MedicineInBag> medList = sb.GetProducts(); int countOfMedicine = 0, size = sb.getSize(), index = 0; //create medicineInBag variables string[] id = new string[size], name = new string[size], pn = new string[size], cn = new string[size]; int[] price = new int[size], s = new int[size], pro = new int[size], cat = new int[size], count = new int[size]; bool[] p = new bool[size]; foreach (MedicineInBag m in medList) { id[index] = m.CMedicineId; name[index] = m.CMedicineName; pn[index] = m.CMedicineInBagProducerName; cn[index] = m.CMedicineInBagCatagoryName; price[index] = m.CMedicinePrice; s[index] = m.CMedicineStock; pro[index] = m.CMedicineProducer; cat[index] = m.CMedicineCatagory; p[index] = m.CMedicineNeedPrescription; count[index] = m.CMedicineInBagMedicineCount; index++; ///////////////////////////////////////////////////////////////////////// /* * int currentStock = webser.GetMedicineStock(Convert.ToInt32(m.CMedicineId)); * countOfMedicine = currentStock - m.CMedicineInBagMedicineCount; * webser.UpdateMedCount(countOfMedicine,Convert.ToInt32(m.CMedicineId)); */ ////////////////////////////////////////////////////////////////////////// } //inseat to data base User u = (User)Session["user"]; /* * * /////////// * os.InsertOrder(o); * //////////////// * ///*/ //////////////////////////////////////////////////////////////////////////// webser.InseartOrder(id, name, price, p, s, pro, cat, pn, cn, count, u.CUserId); //////////////////////////////////////////////////////////////////////////// //init the shopping bag and the prescription list presList = new List <DataSet>(); Session["presList"] = new List <DataSet>(); sb = new ShoppingBag(); Session["myShoppingBag"] = new ShoppingBag(); Response.Write("<script>alert('ההזמנה בוצעה בהצלחה, עלות ההזמנה היא: " + totalPrice + " שקלים')</script>"); SortButton_Click(sender, e); }
public void Update(ShoppingBag shoppingBag) { context.ShoppingBags.Update(shoppingBag); context.SaveChanges(); }
public void Add(ShoppingBag shoppingBag) { context.ShoppingBags.Add(shoppingBag); context.SaveChanges(); }
public DataSet convertToTable(ShoppingBag shoppingBag, int orderID) { DataTable dtShopingBag = new DataTable(); DataColumn[] dtColumd = new DataColumn[] { new DataColumn("OrderID"), new DataColumn("ProductID"), new DataColumn("UnitPrice"), new DataColumn("Quantity"), new DataColumn("Discount"), }; dtShopingBag.Columns.AddRange(dtColumd); for (int i = 0; i < shoppingBag.Products.Count; i++) { DataRow currRow = dtShopingBag.NewRow(); currRow["OrderID"] = orderID; currRow["ProductID"] = ((ProductInBag)shoppingBag.Products[i]).ProdID; currRow["UnitPrice"] = ((ProductInBag)shoppingBag.Products[i]).Price; currRow["Quantity"] = ((ProductInBag)shoppingBag.Products[i]).Quantity; currRow["Discount"] = 0; dtShopingBag.Rows.Add(currRow); } DataSet ds = new DataSet(); ds.Tables.Add(dtShopingBag); ds.Tables[0].TableName = "ShoppingBasketDs"; return ds; }
public void UpdateShoppingBag(ShoppingBag shoppingBag) { repository.Update(shoppingBag); }
public void NewShoppingBag(ShoppingBag sb) { _shoppingBagData.NewShoppingBag(sb); }
public ShoppingBag GetBagById(int id) { ShoppingBag sb = _shoppingBagData.GetById(id); return(sb); }
public void Add(ShoppingBag entity) { ShoppingBags.Add(entity); }
public void Delete(ShoppingBag entity) { ShoppingBags.Remove(entity); }
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer && e.Row.RowType != DataControlRowType.Pager) { short Quantity = 0; if (e.Row.RowState != (DataControlRowState.Edit | DataControlRowState.Alternate) && e.Row.RowState != (DataControlRowState.Edit | DataControlRowState.Normal)) { Quantity = Convert.ToInt16(e.Row.Cells[2].Text); } else { Quantity = Convert.ToInt16(((TextBox)e.Row.Cells[2].Controls[0]).Text); } Label labelSum = (Label)e.Row.Cells[5].FindControl("Label1"); decimal price = Convert.ToDecimal(e.Row.Cells[3].Text); decimal sum = (decimal)(price * Quantity); labelSum.Text = sum.ToString(); } if (e.Row.RowType == DataControlRowType.Footer) { Label labelFooter = (Label)e.Row.Cells[5].FindControl("Label2"); mShoppingBag = (ShoppingBag)Session["mShoppingBag"]; decimal sum = (decimal)mShoppingBag.GetFinalPrice(); labelFooter.Text = sum.ToString(); } }
protected void SearchReasultGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "AddMedicine") { //check if the user is logged in, if not get him a message about it and redirect him to the regestrataion page User s = (User)Session["user"]; if (s == null) { Response.Write("<script>alert('על מנת לרכוש מוצרים עליך להיות לקוח רשום')</script>"); Response.Write("<script>window.open('http://localhost:49675/GuestHome.aspx','_blank');</script>"); return; } //get the shopping bag myShoppingBag = (ShoppingBag)Session["myShoppingBag"]; int rowNumber = Convert.ToInt32(e.CommandArgument); //create the medicineInBag var Pharmcy.PharmcyWS webser = new Pharmcy.PharmcyWS(); MedicineInBag MIB = new MedicineInBag(); MIB.CMedicineName = SearchReasultGrid.Rows[rowNumber].Cells[1].Text; MIB.CMedicineId = SearchReasultGrid.Rows[rowNumber].Cells[0].Text; MIB.CMedicinePrice = Convert.ToInt32(SearchReasultGrid.Rows[rowNumber].Cells[2].Text); MIB.CMedicineInBagMedicinePrice = Convert.ToInt32(MIB.CMedicinePrice); MIB.CMedicineNeedPrescription = Convert.ToBoolean(SearchReasultGrid.Rows[rowNumber].Cells[6].Text); MIB.CMedicineStock = Convert.ToInt32(SearchReasultGrid.Rows[rowNumber].Cells[3].Text); //same in MedicineCatagory MIB.CMedicineProducer = webser.GetMedicineProducer(Convert.ToInt32(MIB.CMedicineId)); MIB.CMedicineCatagory = webser.GetMedicineCatagory(Convert.ToInt32(MIB.CMedicineId)); DataSet temp = webser.GetMedicineCataAndProName(MIB.CMedicineCatagory, MIB.CMedicineProducer); MIB.CMedicineInBagCatagoryName = temp.Tables[0].Rows[0]["MedicineCatagoryName"].ToString(); MIB.CMedicineInBagProducerName = temp.Tables[0].Rows[0]["MedicineProducerName"].ToString(); /////////////////////////////////////////////////////////////////////////////////// //check count of medicine //because we didnt change the current stock of the medicine we need to check if there is //enough from this medicine to buy int countOfMedicine = myShoppingBag.GetMedicineCount(Convert.ToInt32(MIB.CMedicineId)); User u = (User)Session["user"]; if (MIB.CMedicineStock - countOfMedicine <= 0) { Response.Write("<script>alert('אין מספיק תרופות במלאי')</script>"); return; } /////////////////////////////////////////////////////////////////////////////////// //check prescription int MedIdNumber = Convert.ToInt32(MIB.CMedicineId); //still dont change the current stock of medicine if (MIB.CMedicineNeedPrescription) { PrescriptioService ps = new PrescriptioService(); DataSet ds = ps.GetPrescriptionByMedicineId(MedIdNumber, u.CUserId); if (ds.Tables[0].Rows.Count == 0) { Response.Write("<script>alert('תרופה זאת צריכה מרשם')</script>"); return; } else { //לבדוק אם הוא באמת הכניס אותה כמות //אם הוא הכניס אותה כמות אז הכל בסדר //צריך לזכור לבטל את המרשם ברגע שהקנייה מתבצעת //אם הכמות לא שווה אז ליידע את הלקוח שהוא צריך לבדוק כמה כדורים נתנו לו //אפשרות לחשוף קישור בדף לעמוד של המרשמים כדי שיוכל להסתכל //או שאפשר להגיד למשתמש כמה כדורים הוא יכול לקחת(מעדיף שלא נשמע קצת מוזר) presList = (List <DataSet>)Session["presList"]; if (presList != null) { foreach (DataSet d in presList) { if (ds.Tables[0].Rows[0]["PrescriptionId"].ToString() == d.Tables[0].Rows[0]["PrescriptionId"].ToString()) { Response.Write("<script>alert('מרשם זה כבר שומש')</script>"); return; } } } presList.Add(ds); Session["presList"] = presList; int count = Convert.ToInt32(ds.Tables[0].Rows[0]["PrescriptionMedicineCount"].ToString()); MIB.CMedicineInBagMedicineCount = count; } } else { MIB.CMedicineInBagMedicineCount = 1; } myShoppingBag.AddMedicine(MIB); Session["myShoppingBag"] = myShoppingBag; Response.Write("<script>alert('המוצר הוסף לסל')</script>"); CheckoutButton.Visible = true; SeeShoppingBag.Visible = true; } }
public void Update(ShoppingBag entity) { ShoppingBags.Remove(entity); ShoppingBags.Add(entity); }