public void CreateOrder(ShoppingCarts cart, Order order) { double totalCost = 0; foreach (var item in cart.CartsItems) { Product product = productRepository.GetById(item.ProductId); OrderDetails newOrder = new OrderDetails { OrderId = order.Id, ProductId = item.ProductId, Price = item.Price, Quantity = item.Quantity, TotalPrice = item.Price * item.Quantity }; orderDetailsRepository.Add(newOrder); totalCost += newOrder.TotalPrice; product.Quantity -= item.Quantity; productRepository.Update(product); } order.TotalCost = totalCost; Update(order); shoppingCartRepository.EmptyCart(cart); }
public void AddTicketToUser(int customerID, int ticketToBuyID, int quantity = 1) { if (quantity < 1) { return; } ShoppingCarts customerCartLine = CartInfo.FirstOrDefault( p => (p.UserID == customerID && p.TicketID == ticketToBuyID)); if (customerCartLine != null) { if (customerCartLine.CheckOutTime != null) { TicketInfo.First(x => x.TicketID == ticketToBuyID).AmountRemaining += customerCartLine.Quantity; } customerCartLine.Quantity += quantity; customerCartLine.CheckOutTime = null; } else { customerCartLine = new ShoppingCarts(); customerCartLine.Quantity = quantity; customerCartLine.Ticket = context.Tickets.Find(ticketToBuyID); customerCartLine.User = context.Users.Find(customerID); customerCartLine.DateAdded = DateTime.UtcNow; context.CartInformation.Add(customerCartLine); } context.SaveChanges(); }
public IActionResult AddShoppingCarts([FromBody] ShoppingCarts shoppingCart) { var claimsIdentity = User.Identity as ClaimsIdentity; int userid = Convert.ToInt32(claimsIdentity.FindFirst(ClaimTypes.Name)?.Value); int productid = shoppingCart.ProductID; var cart = new ShoppingCarts() { //ShoppingCartID 自增 UserID = userid, ProductID = productid, ProductName = shoppingCart.ProductName, ProductImg = shoppingCart.ProductImg, Number = shoppingCart.Number, UnitPrice = shoppingCart.UnitPrice, TotalPrice = shoppingCart.TotalPrice, }; int result = _shoppingCartsRepository.GetShoppingCartsCount(userid, productid); if (result > 0) { return(StatusCode(403, "商品已存在与购物车")); } else { _shoppingCartsRepository.AddShoppingCarts(cart); return(Ok("添加成功")); } }
public async Task <IActionResult> PutShoppingCarts(int id, ShoppingCarts shoppingCarts) { if (id != shoppingCarts.Id) { return(BadRequest()); } _context.Entry(shoppingCarts).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShoppingCartsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult AddToCart(int id) { //cek apakah user sudah login if (Session["username"] == null) { if (User.Identity.IsAuthenticated) { Session["username"] = User.Identity.Name; } else { var tempUser = Guid.NewGuid().ToString(); Session["username"] = tempUser; //return RedirectToAction("Login", "Account"); } } using (ShoppingCartDAL scService = new ShoppingCartDAL()) { var newShoppingCart = new ShoppingCarts { CartID = Session["username"].ToString(), Quantity = 1, id_barang = id, DateCreated = DateTime.Now }; scService.TambahCart(newShoppingCart); } return(RedirectToAction("Index")); }
// the ID is actually total to pay public ActionResult BuyCart(int ID) { int Current_Customer_ID = ((SmartSuper.Models.Customers)System.Web.HttpContext.Current.Session["user"]).ID; int Customer_ShoppingCart_ID = ((SmartSuper.Models.Customers)System.Web.HttpContext.Current.Session["user"]).Current_Shoppingcart_ID; var Current_ShoppingCart = db.ShoppingCarts.Find(Customer_ShoppingCart_ID); // Here, the customers pay money with credit card Current_ShoppingCart.Paid = true; Current_ShoppingCart.CustomerID = Current_Customer_ID; Current_ShoppingCart.TotalPricePaid = ID; db.SaveChanges(); // Creating a new shopping cart ShoppingCarts Customer_New_Shopping_Cart = new ShoppingCarts(); db.ShoppingCarts.Add(Customer_New_Shopping_Cart); db.SaveChanges(); int Current_ShoppingCard_ID = db.ShoppingCarts .OrderByDescending(p => p.ID) .FirstOrDefault().ID; // updating the Customer's shopping cart var current_customer = db.Customer.Find(Current_Customer_ID); current_customer.Current_Shoppingcart_ID = Current_ShoppingCard_ID; db.SaveChanges(); System.Web.HttpContext.Current.Session["user"] = current_customer; return(RedirectToAction("Index")); }
public ActionResult EditPost(ShoppingCarts shop) { using (ShoppingCartDAL service = new ShoppingCartDAL()) { return(RedirectToAction("Index")); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,ClientId,ProductId,Amount,DateOrder,IsInCart")] ShoppingCarts shoppingCarts) { if (id != shoppingCarts.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(shoppingCarts); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShoppingCartsExists(shoppingCarts.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "ClientName", shoppingCarts.ClientId); ViewData["ProductId"] = new SelectList(_context.Product, "Id", "ProductName", shoppingCarts.ProductId); return(View(shoppingCarts)); }
public ActionResult DeleteConfirmed(int id) { ShoppingCarts shoppingCarts = db.ShoppingCarts.Find(id); db.ShoppingCarts.Remove(shoppingCarts); db.SaveChanges(); return(RedirectToAction("Index")); }
private ShoppingCarts LoadShoppingCart() { // lấy thông tin giỏ hàng ra. if (!(Session[SHOPPING_CART_NAME] is ShoppingCarts sc)) { sc = new ShoppingCarts(); } return(sc); }
public ActionResult Edit([Bind(Include = "ID,Paid")] ShoppingCarts shoppingCarts) { if (ModelState.IsValid) { db.Entry(shoppingCarts).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shoppingCarts)); }
// Quản lý đơn đặt hàng của user public ActionResult OrderManagement() { User user = (User)Session["user"]; ShoppingCarts sc = (ShoppingCarts)Session["sptt"]; if (user == null) { return(Redirect(login)); } return(View(db.Bill.Where(n => n.user_id == user.user_id).ToList())); }
public ActionResult Create([Bind(Include = "ID,Paid")] ShoppingCarts shoppingCarts) { if (ModelState.IsValid) { db.ShoppingCarts.Add(shoppingCarts); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shoppingCarts)); }
public ActionResult Create(string id) { if (id != null) { ShoppingCarts cart = new ShoppingCarts { CustomerId = id }; shoppingCartRepository.Add(cart); } return(RedirectToAction("Index", "Home")); }
public ActionResult Add(int id, int price, string name, string picture) { cart = new ShoppingCarts(); cart.ProductID = id; cart.ClientID = picture; cart.DatePurchased = name; cart.Amount = price; cart.UserName = User.Identity.Name;; db.ShoppingCarts.Add(cart); db.SaveChanges(); return(RedirectToAction("Show", "ShoppingCarts")); }
public async Task <IActionResult> Create([Bind("Id,ClientId,ProductId,Amount,DateOrder,IsInCart")] ShoppingCarts shoppingCarts) { if (ModelState.IsValid) { _context.Add(shoppingCarts); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "ClientName", shoppingCarts.ClientId); ViewData["ProductId"] = new SelectList(_context.Product, "Id", "ProductName", shoppingCarts.ProductId); return(View(shoppingCarts)); }
public void Edit(ShoppingCarts shop) { var result = GetItemByID(shop.RecordID); if (result != null) { result.Quantity = shop.Quantity; db.SaveChanges(); } else { throw new Exception("Data not Found!"); } }
public async Task <ActionResult <ShoppingCarts> > PostShoppingCarts(AddCartInput aci) { ShoppingCarts shoppingCarts = new ShoppingCarts { Count = aci.Count, Size = aci.Size, ProductId = aci.ProductId }; _context.ShoppingCarts.Add(shoppingCarts); await _context.SaveChangesAsync(); return(CreatedAtAction("GetShoppingCarts", new { id = shoppingCarts.Id }, shoppingCarts)); }
// GET: ShoppingCarts/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ShoppingCarts shoppingCarts = db.ShoppingCarts.Find(id); if (shoppingCarts == null) { return(HttpNotFound()); } return(View(shoppingCarts)); }
public ShoppingCartEntity GetShoppingCartById(string id) { var query = ShoppingCarts.Include(x => x.TaxDetails) .Include(x => x.Discounts) .Where(x => x.Id == id); var addresses = Addresses.Where(x => x.ShoppingCartId == id).ToArray(); var payments = Payments.Include(x => x.Addresses).Where(x => x.ShoppingCartId == id).ToArray(); var lineItems = LineItems.Include(x => x.Discounts) .Include(x => x.TaxDetails) .Where(x => x.ShoppingCartId == id).ToArray(); var shipments = Shipments.Include(x => x.TaxDetails) .Include(x => x.Discounts) .Where(x => x.ShoppingCartId == id).ToArray(); return(query.FirstOrDefault()); }
public string SubtractTicket(ShoppingCarts customerCartLine) { if (customerCartLine.CheckOutTime != null) { return(""); } if (customerCartLine.Ticket.AmountRemaining < customerCartLine.Quantity) { return(customerCartLine.Ticket.TicketName); } customerCartLine.Ticket.AmountRemaining -= customerCartLine.Quantity; customerCartLine.CheckOutTime = DateTime.UtcNow; return(""); }
public void A11_Access_Key_Expire_When_User_Completed_the_Content_Bundle_34189() { #region Create General Course and Bundle With Cost and Access keys Enabled CommonSection.CreateLink.GeneralCourse(); _test.Log(Status.Info, "Creating a Paid General Course"); GeneralCoursePage.CreateGeneralCourse(generalcourse + "TC34189", "Test General Course"); GeneralCoursePage.setCost("5"); DocumentPage.ClickButton_CheckIn(); _test.Log(Status.Info, "Paid general course created"); CommonSection.Learn.Home(); CommonSection.CreateLink.Bundle(); _test.Log(Status.Info, "Creating a Paid Bundle Course with Access Keys"); objCreate.FillBundlePage(browserstr + "TC34189"); GeneralCoursePage.setCost("5"); _test.Log(Status.Info, "Cost Has Been Set"); BundlesPage.enableAccessKeys(); _test.Log(Status.Info, "Access Keys Enabled"); BundlesPage.addContentIntoBundle(generalcourse + "TC34189"); _test.Log(Status.Info, "Adding Paid General Course into Bundle"); DocumentPage.ClickButton_CheckIn(); #endregion #region Purchase Access Keys for Bundle ShoppingCarts.purchaseAccessKeys("Bundle", Variables.bundleTitle + browserstr + "TC34189"); ShoppingCarts.completePurchaseProcess(); _test.Log(Status.Info, "Keys has been purchased from shopping cart"); CommonSection.Manage.Training(); CommonSection.Manage.AccessKeys(); AccessKeysPage.searchForContent(Variables.bundleTitle + browserstr + "TC34189"); AccessKeysPage.assignKeysToLearner("*****@*****.**"); _test.Log(Status.Info, "Keys has been assigned to learner"); driver.LogoutUser(ObjectRepository.LogoutHoverLink, ObjectRepository.HoverMainLink); #endregion LoginPage.LoginAs("ssuser1").WithPassword("password").Login(); Assert.IsTrue(BundlesPage.searchforBundle(Variables.bundleTitle + browserstr + "TC34189", generalcourse + "TC34189")); _test.Log(Status.Info, "General Course Displaying inside Bundle, Assertion Pass"); Assert.IsTrue(Driver.Instance.IsElementVisible(By.XPath("//input[@value='Enroll']"))); _test.Log(Status.Info, "Cost of General Course Override, Assertion Pass"); GeneralCoursePage.completeGeneralCourse(); BundlesPage.simplysearchforBundle(Variables.bundleTitle + browserstr + "TC34189"); Assert.IsTrue(Driver.Instance.IsElementVisible(By.XPath("//p[contains(.,'You have already completed this item. You must use another access key to begin a new attempt.')]"))); driver.LogoutUser(ObjectRepository.LogoutHoverLink, ObjectRepository.HoverMainLink); LoginPage.LoginAs("").WithPassword("").Login(); }
public void A16_Test_Access_Keys_with_Curriculum_34153() { #region Create General Course and Curriculum With Cost and Access keys Enabled CommonSection.CreateLink.GeneralCourse(); _test.Log(Status.Info, "Creating a Paid General Course"); GeneralCoursePage.CreateGeneralCourse(generalcourse + "Curr", "Test General Course"); GeneralCoursePage.setCost("5"); DocumentPage.ClickButton_CheckIn(); _test.Log(Status.Info, "Paid general course created"); CommonSection.Learn.Home(); CommonSection.CreateLink.Curriculam(); _test.Log(Status.Info, "Creating a Paid Curriculum Course with Access Keys"); objCreate.FillCurriculumPage("AK", browserstr); GeneralCoursePage.setCost("5"); _test.Log(Status.Info, "Cost Has Been Set"); BundlesPage.enableAccessKeys(); _test.Log(Status.Info, "Access Keys Enabled"); CurriculumsPage.CurriculumContent.addContentIntoCurriculam(generalcourse + "Curr"); _test.Log(Status.Info, "Adding Paid General Course into Curriculum"); DocumentPage.ClickButton_CheckIn(); #endregion #region Purchase Access Keys for Curriculam ShoppingCarts.purchaseAccessKeys("Curriculam", Variables.curriculumTitle + browserstr + "AK"); ShoppingCarts.completePurchaseProcess(); _test.Log(Status.Info, "Keys has been purchased from shopping cart"); CommonSection.Manage.Training(); CommonSection.Manage.AccessKeys(); AccessKeysPage.searchForContent(Variables.curriculumTitle + browserstr + "AK"); AccessKeysPage.assignKeysToLearner("*****@*****.**"); _test.Log(Status.Info, "Keys has been assigned to learner"); driver.LogoutUser(ObjectRepository.LogoutHoverLink, ObjectRepository.HoverMainLink); #endregion LoginPage.LoginAs("ssuser1").WithPassword("password").Login(); Assert.IsTrue(CurriculumsPage.searchforCurriculam(Variables.curriculumTitle + browserstr + "AK", generalcourse + "Curr")); _test.Log(Status.Info, "General Course Displaying inside Curriculuam, Assertion Pass"); Assert.IsTrue(Driver.Instance.IsElementVisible(By.XPath("//input[@value='Enroll']"))); // TC_10823 = true; _test.Log(Status.Info, "Cost of General Course Override, Assertion Pass"); driver.LogoutUser(ObjectRepository.LogoutHoverLink, ObjectRepository.HoverMainLink); LoginPage.LoginAs("").WithPassword("").Login(); }
public ActionResult Create(Customers customer) { if (ModelState.IsValid) { if (db.Customer.Where(c => c.Email == customer.Email).Count() > 0) { ViewBag.ErrMsg = "כתובת האימייל שהוזנה כבר קיימת במערכת, אנא נסה כתובת מייל אחרת"; } else { // Creating a new shopping cart ShoppingCarts Customer_New_Shopping_Cart = new ShoppingCarts(); Customer_New_Shopping_Cart.CustomerID = 111; db.ShoppingCarts.Add(Customer_New_Shopping_Cart); db.SaveChanges(); int Current_ShoppingCard_ID = db.ShoppingCarts .OrderByDescending(p => p.ID) .FirstOrDefault().ID; // Adding the Customer customer.Current_Shoppingcart_ID = Current_ShoppingCard_ID; db.Customer.Add(customer); db.SaveChanges(); // Adding the row to Customer_ShoppingCart //int Current_Customer_ID = db.Customer //.OrderByDescending(p => p.ID) //.FirstOrDefault().ID; //Customer_ShoppingCart newCustShopCart = new Customer_ShoppingCart(); //newCustShopCart.Customer_ID = Current_Customer_ID; //newCustShopCart.ShoppingCart_ID = Current_ShoppingCard_ID; //db.Customer_ShoppingCart.Add(newCustShopCart); //db.SaveChanges(); System.Web.HttpContext.Current.Session["user"] = customer; return(RedirectToAction("Index", "Home")); } } return(View(customer)); }
public ActionResult Carts(ShoppingCarts carts) { int goodid = Convert.ToInt32(Session["goodid"]); int userid = Convert.ToInt32(Session["UserID"]); int result = shoppingcarsmanager.ShopCartsCount(userid, goodid); if (result > 0) { return(Content("<script>alert('该商品已存在购物车');history.go(-1)</script>")); } else { carts.UserID = userid; carts.GoodsID = goodid; carts.UnitPrice = Convert.ToDecimal(Request.Form["price"]); carts.Number = Convert.ToInt32(Request.Form["Jm_Amount"]); carts.TotalAmount = carts.Number * carts.UnitPrice; shoppingcarsmanager.AddShopCarts(carts); //return RedirectToAction("Carts", "Goods", new { UserID=1}); return(Content("<script>alert('添加成功');history.go(-1)</script>")); } }
/// <summary> /// 添加购物车 /// </summary> /// <param name="shoppingCartInput"></param> /// <returns></returns> public (int, string) AddCarts(ShoppingCartInputDto shoppingCartInput) { int rowCount = 1; string addType = null; try { //var carts = ListShoppingCartByCustomerNo (shoppingCartInput.CustomerNo); //var currCart = carts.Find (m => m.ProductNo == shoppingCartInput.ProductNo); var carts = RedisHelper.GetHashMemory <ShoppingCarts> ($"carts:{shoppingCartInput.CustomerNo}:*"); var currCart = carts.Find(m => m.ProductNo == shoppingCartInput.ProductNo); //如果存在购物车则说明是添加数量 ,如果不存在 则添加新的购物车信息 if (currCart != null) { currCart.ProductNum += shoppingCartInput.BuyNum; //rowCount = _cartRepository.Update (currCart); addType = "u"; //"u"代表update } else { currCart = new ShoppingCarts { CartGuid = Guid.NewGuid().ToString(), CustomerNo = shoppingCartInput.CustomerNo, ProductNo = shoppingCartInput.ProductNo, ProductNum = shoppingCartInput.BuyNum, CartSelected = false }; //rowCount = _cartRepository.Insert (currCart); addType = "i"; //"i"代表insert } RedisHelper.SetHashMemory($"carts:{currCart.CustomerNo}:{currCart.CartGuid}", currCart); return(rowCount, addType); } catch (System.Exception) { return(0, addType); throw; } }
//xu ly them vao gio hang public ActionResult CreateCart(int?id) { //In so tren thanh gio hang (truong hop khong co) if (Session["sptt"] == null) { Session["sptt"] = new List <ShoppingCarts>(); Session["dem"] = "Trống"; } //xu ly lu sesion va +so ngay gio hang lay theo id san pha List <ShoppingCarts> ghtt = Session["sptt"] as List <ShoppingCarts>; if (ghtt.FirstOrDefault(n => n.product_id == id) == null) { Product sp = db.Product.Find(id); if (Session["dem"].ToString() == "Trống") { Session["dem"] = "0"; } Session["dem"] = Int32.Parse(Session["dem"].ToString()) + 1; ShoppingCarts giatri = new ShoppingCarts() { product_id = sp.product_id, product_image = sp.product_image, product_name = sp.product_name, pay_amount = 1, product_price = decimal.ToInt32(sp.product_price.Value) }; ghtt.Add(giatri); } else { ShoppingCarts gh = ghtt.FirstOrDefault(n => n.product_id == id); gh.pay_amount++; } return(Redirect(Request.UrlReferrer.ToString())); }
public void TambahCart(ShoppingCarts sc) { var result = GetItemByUser(sc.CartID, sc.id_barang); if (result != null) { //update result.Quantity += 1; } else { //tambah baru db.ShoppingCarts.Add(sc); } try { db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message, ex.InnerException); } }
public void RemoveShoppingCarts(ShoppingCarts shopcart) { db.ShoppingCarts.Remove(shopcart); db.SaveChanges(); }
public ShoppingCarts GetShoppingCarts(byte[] result) { return(ShoppingCarts.ParseFrom(result)); }