public int PlaceOrder(int cartID, int userID) { Console.WriteLine("Start Place Order Details"); int orderID = -1; IWallet wallet = new Wallet(); ITax tax = new Tax(); ICart userCart = new ShoppingCartDetails(); IAddress address = new AddressDetails(); IOrder order = new Order(); //Step 1: Get Tax Percentage by State double stateTax = tax.GetTaxByState("ABC"); //Step 2: Apply Tax on Cart Items tax.ApplyTax(cartID, stateTax); //Step 3: Get User Wallet Balance double userWalletBalance = wallet.GetUserBalance(userID); //Step 4: Get Cart Items Price double cartPrice = userCart.GetCartPrice(cartID); //Step 5: Compare the balance and price if (userWalletBalance > cartPrice) { //Step 6: Get User Address and set to Cart Address userAddress = address.GetAddressDetails(userID); //Step 7: Place the order orderID = order.PlaceOrderDetails(cartID, userAddress.AddressID); } Console.WriteLine("End Place Order Details"); return(orderID); }
internal async Task Expand() { // set our initial states WhiteBackground.TranslationY = this.Height; WhiteBackground.IsVisible = true; GreenPanel.TranslationY = this.Height; ShoppingCartDetails.Opacity = 0; Header.Opacity = 0; this.Opacity = 1; this.IsVisible = true; CheckOutButton.ScaleX = 0; // expand the white panel (background) await WhiteBackground.TranslateTo(0, 0, animationSpeed); // expand the green panel (shopping cart list background) _ = GreenPanel.TranslateTo(0, 0, animationSpeed); _ = ShoppingCartDetails.FadeTo(1, animationSpeed * 2); _ = Header.FadeTo(1, animationSpeed * 2); // expand the button out Animation animation = new Animation(); animation.Add(0, 1, new Animation(t => CheckOutButton.ScaleX = t, 0, 1, Easing.SpringOut)); animation.Commit(this, "ButtonAnimation", 16, 500); }
public ShoppingCartDetails ToCartDetails() { var details = new ShoppingCartDetails() { Grocery = GetGroceryDetails(), Amount = (float)Amount, GroupID = ChamberOfSecrets.Instance.group.Id, AmountSpecified = true }; return(details); }
/// <summary> /// Adds shopping cart into the database /// </summary> /// <param name="model">Model which is used to create Shopping Cart entity</param> /// <returns>Message model with error message in case of error or success message.</returns> public async Task <MessageViewModel> AddAsync(AddToCartViewModel model) { var messageViewModel = new MessageViewModel(); var userCart = await this.GetOrCreateUserCartAsync(model.UserId); var productToAdd = this.dbContext.Products.FirstOrDefault(p => p.Id == model.ProductId); if (productToAdd == null) { messageViewModel.SetError($"Продукт с ID {model.ProductId} не съществува."); return(messageViewModel); } if (userCart.ShoppingCartDetails.Any(scd => scd.ProductId == productToAdd.Id)) { var productDetails = userCart.ShoppingCartDetails.FirstOrDefault(scd => scd.ProductId == productToAdd.Id); productDetails.Quantity++; if (productToAdd.AvailableQuantity < productDetails.Quantity) { messageViewModel.SetError($"Недостатъчно количесто, в момента наличното е: {productToAdd.AvailableQuantity}."); return(messageViewModel); } this.dbContext.ShoppingCartDetails.Update(productDetails); await this.dbContext.SaveChangesAsync(); } else { if (productToAdd.AvailableQuantity < model.Quantity) { messageViewModel.SetError($"Недостатъчно количесто, в момента наличното е: {productToAdd.AvailableQuantity}."); return(messageViewModel); } ShoppingCartDetails shoppingCartDetails = new ShoppingCartDetails { ProductId = productToAdd.Id, Quantity = model.Quantity, ShoppingCartId = userCart.Id }; await this.dbContext.ShoppingCartDetails.AddAsync(shoppingCartDetails); await dbContext.SaveChangesAsync(); } messageViewModel.SetSuccess("Продуктът успешно беше добавен към вашата количка."); return(messageViewModel); }
public ActionResult ViewCart() { if (Session["ACategory"] != null) { if (Session["ACategory"].ToString() == "Trading" && Session["ACategory"] != null) { ShoppingCartDetails mymodel = new ShoppingCartDetails(); string Sesson = Session["userEmail"].ToString(); mymodel.AddToCarts = db.addToCarts.Where(t => t.SessonId == Sesson).ToList(); mymodel.Customers = db.customers.ToList(); return(View(mymodel)); } } return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); }
public static void Handle(ProductItemRemovedFromShoppingCart @event, ShoppingCartDetails view) { var productItem = @event.ProductItem; var existingProductItem = view.ProductItems .Single(x => x.ProductId == @event.ProductItem.ProductId); if (existingProductItem.Quantity == productItem.Quantity) { view.ProductItems.Remove(existingProductItem); } else { existingProductItem.Quantity -= productItem.Quantity; } view.Version++; }
public int AddToCart(int itemID, int quantity) { Console.WriteLine("Start Add to cart"); ICart userCart = new ShoppingCartDetails(); int cartID = 0; //Step 1: GetItem Product product = userCart.GetItemDetails(itemID); //Step 2: CheckAvailability if (userCart.CheckItemAvailability(product)) { //Step 3: LockItemInStock userCart.LockItemInStock(itemID, quantity); //Step 4: AddItenToCart cartID = userCart.AddItemToCart(itemID, quantity); } Console.WriteLine("EndAddToCart"); return(cartID); }
public static void Handle(ProductItemAddedToShoppingCart @event, ShoppingCartDetails view) { var productItem = @event.ProductItem; var existingProductItem = view.ProductItems .FirstOrDefault(x => x.ProductId == @event.ProductItem.ProductId); if (existingProductItem == null) { view.ProductItems.Add(new ShoppingCartDetailsProductItem { ProductId = productItem.ProductId, Quantity = productItem.Quantity, UnitPrice = productItem.UnitPrice }); } else { existingProductItem.Quantity += productItem.Quantity; } view.Version++; }
public void UpdateCartItems(ShoppingCartDetails model) { var _modelToUpdate = (from a in _context.CartItems where a.CartId == model.CartID && a.ProductId == model.ProductID select a).FirstOrDefault(); if (_modelToUpdate != null) { _context.Entry(_modelToUpdate).CurrentValues.SetValues(model); _context.SaveChanges(); UpdateCartCount(); } }
public ActionResult CreateCart(ShoppingCartDetails cartDetails, FormCollection col)//[Bind(Include = "Id,GoodId,Name,ShortDetail,LongDetail,Thumbail,WholesaleRate,Quantity,CoupenCode,CreatedDate,CreatedBy,EditedBy,EditedDate,Imag ) { if (Session["ACategory"] != null) { if (Session["ACategory"].ToString() == "Trading" && Session["ACategory"] != null) { if (ModelState.IsValid) { try { if (Convert.ToInt32(col["customerId"]) != 0) { int customerId = Convert.ToInt32(col["customerId"]); decimal Vat = Convert.ToDecimal(col["vatTotal"]); decimal Subtotal = Convert.ToDecimal(col["Total"]); decimal GrandTotal = Convert.ToDecimal(col["GrandTotal"]); decimal other = Convert.ToDecimal(col["Other"]); var objInvoiceGoods = new Invoice(); var objInvoice = new INVProduct(); objInvoiceGoods.CustomerId = customerId; objInvoiceGoods.Vat = Vat; objInvoiceGoods.Subtotal = Subtotal; objInvoiceGoods.GrandTotal = GrandTotal; objInvoiceGoods.Other = other; InvoiceGenerate invoice = db.InvoiceGenerates.FirstOrDefault(); if (invoice == null) { db.InvoiceGenerates.Add(new InvoiceGenerate { InvoiceId = 1 }); db.SaveChanges(); invoice = db.InvoiceGenerates.FirstOrDefault(); } else { invoice.InvoiceId = invoice.InvoiceId + 1; db.SaveChanges(); } string invoicet = invoice.InvoiceId.ToString(); objInvoiceGoods.InvoiceNo = invoice.InvoiceId.ToString(); db.Invoices.Add(objInvoiceGoods); db.SaveChanges(); try { foreach (var item in cartDetails.AddToCarts) { objInvoice.InvoiceId = invoicet; objInvoice.Rate = item.price; objInvoice.Quantity = item.Quantity; objInvoice.TradingGoodsId = item.ProductId; objInvoice.Total = item.Subtotal; var goods = db.TradingGoods.Where(t => t.Id == item.ProductId).FirstOrDefault(); goods.Quantity -= item.Quantity; db.INVProducts.Add(objInvoice); db.SaveChanges(); } var Sesson = Session["userEmail"].ToString(); db.Database.ExecuteSqlCommand("Delete From cart where SessonId ='" + Sesson + "'"); return(RedirectToAction("Index", "TradingCompletes")); } catch { return(RedirectToAction("ViewCart")); } } TempData["message"] = "Please select costumer"; return(RedirectToAction("ViewCart")); } catch { return(RedirectToAction("ViewCart")); } } return(RedirectToAction("ViewCart")); } } return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); }
public static void Handle(ShoppingCartConfirmed @event, ShoppingCartDetails view) { view.Status = ShoppingCartStatus.Confirmed; view.Version++; }