コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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("添加成功"));
            }
        }
コード例 #4
0
        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());
        }
コード例 #5
0
 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"));
 }
コード例 #6
0
        // 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"));
        }
コード例 #7
0
 public ActionResult EditPost(ShoppingCarts shop)
 {
     using (ShoppingCartDAL service = new ShoppingCartDAL())
     {
         return(RedirectToAction("Index"));
     }
 }
コード例 #8
0
        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));
        }
コード例 #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            ShoppingCarts shoppingCarts = db.ShoppingCarts.Find(id);

            db.ShoppingCarts.Remove(shoppingCarts);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #10
0
 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);
 }
コード例 #11
0
 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));
 }
コード例 #12
0
        // 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()));
        }
コード例 #13
0
        public ActionResult Create([Bind(Include = "ID,Paid")] ShoppingCarts shoppingCarts)
        {
            if (ModelState.IsValid)
            {
                db.ShoppingCarts.Add(shoppingCarts);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(shoppingCarts));
        }
コード例 #14
0
        public ActionResult Create(string id)
        {
            if (id != null)
            {
                ShoppingCarts cart = new ShoppingCarts
                {
                    CustomerId = id
                };
                shoppingCartRepository.Add(cart);
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #15
0
        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"));
        }
コード例 #16
0
        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));
        }
コード例 #17
0
        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!");
            }
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        // 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));
        }
コード例 #20
0
        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());
        }
コード例 #21
0
        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("");
        }
コード例 #22
0
        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();
        }
コード例 #23
0
        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();
        }
コード例 #24
0
        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));
        }
コード例 #25
0
        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>"));
            }
        }
コード例 #26
0
        /// <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;
            }
        }
コード例 #27
0
        //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()));
        }
コード例 #28
0
        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);
            }
        }
コード例 #29
0
 public void RemoveShoppingCarts(ShoppingCarts shopcart)
 {
     db.ShoppingCarts.Remove(shopcart);
     db.SaveChanges();
 }
コード例 #30
0
 public ShoppingCarts GetShoppingCarts(byte[] result)
 {
     return(ShoppingCarts.ParseFrom(result));
 }