コード例 #1
0
        public int DeleteCart(Guid cartId, string SessionId, ApplicationUser user)
        {
            int value = 0;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                UserCart cart = db.UserCarts.Where(w => w.Id == cartId && w.SessionId == SessionId).FirstOrDefault();
                UserCart ct   = null;
                if (user != null)
                {
                    ct = db.UserCarts.Where(w => w.Id == cartId && w.UserId == user.Id).FirstOrDefault();
                }
                if (ct != null)
                {
                    db.UserCarts.Remove(ct);
                    db.SaveChanges();
                    value = 1;
                }
                else if (cart != null)
                {
                    db.UserCarts.Remove(cart);
                    db.SaveChanges();
                    value = 1;
                }
            }
            return(value);
        }
コード例 #2
0
        private void AddDomainToCart()
        {
            string yy  = SessionM["UserEnteredDomain"].ToString();
            string yy1 = SessionM["UserSelectedTDLs"].ToString();
            string yy2 = Request[ddlPrimeDominPlan.UniqueID];

            AddItemToCart(SessionM["UserEnteredDomain"].ToString() + SessionM["UserSelectedTDLs"].ToString(), Request[ddlPrimeDominPlan.UniqueID], APIC.WebService.Domain);
            if (UserCart.IsWebServiceSelected)
            {
                AddDomainToWebService(SessionM["UserEnteredDomain"].ToString() + SessionM["UserSelectedTDLs"].ToString());
            }
            if (Request["domainnamearr[]"] != null)
            {
                string[] selectDomains = Request["domainnamearr[]"].Split(new char[] { ',' });
                foreach (string domain in selectDomains)
                {
                    AddItemToCart(domain, Request[domain + "_plan"], APIC.WebService.Domain);

                    if (UserCart.IsWebServiceSelected)
                    {
                        AddDomainToWebService(domain);
                    }
                }
            }
            if (UserCart.IsWebServiceSelected)
            {
                UserCart.SetSelectedWebServiceNULL();
                Response.Redirect("CheckOut.aspx");
            }
            else
            {
                Response.Redirect("SelectWebService.aspx");
            }
        }
コード例 #3
0
        public int UpdateCart(Guid?cartId, string SessionId, ApplicationUser user, int Qty)
        {
            int result = 0;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                UserCart cart     = db.UserCarts.Where(w => w.Id == cartId && w.SessionId == SessionId).FirstOrDefault();
                UserCart userCart = null;
                if (user != null)
                {
                    userCart = db.UserCarts.Where(w => w.Id == cartId && w.UserId == user.Id).FirstOrDefault();
                }
                if (userCart != null)
                {
                    userCart.Qty = Qty;
                    db.SaveChanges();
                    result = 1;
                }
                else if (cart != null)
                {
                    cart.Qty = Qty;
                    db.SaveChanges();
                    result = 1;
                }
            }
            return(result);
        }
コード例 #4
0
        public void AddItemToCart(int id)
        {
            var user = _db.Users.
                       Include(x => x.Cart)
                       .SingleOrDefault(x => x.Nickname == RunTimeInfo.Instance.Username);

            var item = _db.Products
                       .SingleOrDefault(x => x.Id == id);

            var userCartExists = _db.UsersCart
                                 .SingleOrDefault(x => x.UserId == user.Id && item.Id == x.ProductId);

            if (userCartExists == null)
            {
                var userCart = new UserCart {
                    Product = item, User = user, Quantity = 1
                };
                user.Cart.Add(userCart);
            }
            else
            {
                userCartExists.Quantity++;
            }


            _db.SaveChanges();
        }
コード例 #5
0
ファイル: UserRepository.cs プロジェクト: poojaghosh/testgit
        public bool MoveFromSaveItemToCart(string sku, string email)
        {
            bool status = false;

            try
            {
                UserCart objCart = context.UserCarts.Where(x => x.ProductSKU == sku && x.UserEmail == email).FirstOrDefault();
                if (objCart != null)
                {
                    objCart.Active = true;
                    context.SaveChanges();

                    UserSavedItem objSavedItem = writeContext.UserSavedItems.Where(x => x.ProductSKU == sku && x.UserEmail == email).FirstOrDefault();
                    if (objSavedItem != null)
                    {
                        writeContext.UserSavedItems.Remove(objSavedItem);
                        writeContext.SaveChanges();
                    }
                    status = true;
                }
            }
            catch (Exception ex)
            {
            }
            return(status);
        }
コード例 #6
0
        public ActionResult AddToCart(string itemId)
        {
            var objId = new ObjectId(itemId);
            var c     = Request.Cookies.Get("cart");

            if (c == null || Request.Cookies["cart"].Value == null || Request.Cookies["cart"].Value == "")
            {
                CreateNewCookies("cart");
            }
            string userId = Request.Cookies["cart"].Value;
            IMongoCollection <UserCart> cartsCollection = Database.GetCollection <UserCart>("Carts");
            UserCart cart = cartsCollection.Find(x => x.UserId == userId).FirstOrDefault();

            if (cart == null)
            {
                cart = new UserCart(userId, itemId);
                cartsCollection.InsertOne(cart);
            }
            else
            {
                cart.Items.Add(itemId);
                cartsCollection.ReplaceOne(x => x.Id == cart.Id, cart);
            }
            return(Json(cart.Items));
        }
コード例 #7
0
        public void GetTotalPrice(int result)
        {
            List <Item> _items = new List <Item>()
            {
                new Item()
                {
                    ProductName = "A",
                    Price       = 10
                },
                new Item()
                {
                    ProductName = "B",
                    Price       = 20
                }
            };

            var userCart = new UserCart();

            foreach (var item in _items)
            {
                userCart.AddItem(item);
            }

            Assert.AreEqual(userCart.TotalPrice(), result);
        }
コード例 #8
0
        public async Task AddAsync(UserCart userCart, CancellationToken cancellationToken = default)
        {
            await toolShedContext.UserCartSet
            .AddAsync(userCart);

            await toolShedContext.SaveChangesAsync(cancellationToken);
        }
コード例 #9
0
        public async Task <IActionResult> DecreaseQuantity(
            [Bind("Quantity")] UserCart UserCart,
            int?boardGameID,
            int?lineItemId)
        {
            if (lineItemId == null || boardGameID == null)
            {
                return(NotFound());
            }

            var userCartToUpdate = await _db.UserCart.FindAsync(lineItemId);

            if (userCartToUpdate == null)
            {
                return(NotFound());
            }

            await TryUpdateModelAsync <UserCart>(
                userCartToUpdate,
                "item",
                u => u.Quantity);

            {
                if (userCartToUpdate.Quantity <= 1)
                {
                    return(RedirectToAction("Index"));
                }

                userCartToUpdate.Quantity -= 1;
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
        }
コード例 #10
0
        public HttpResponseMessage checkoutReceipt(int cartId)
        {
            try
            {
                //UserCart queryUserCart = UserCart.u.Where(u => u.cartId == cartId).FirstOrDefault();
                UserCart queryUserCart = new UserCart();

                queryUserCart.user = db.USER.Where(u => u.cartId == cartId).FirstOrDefault();



                //USER queryUser = db.USER.Where(u => u.cartId == cartId).FirstOrDefault();

                if (queryUserCart.user == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, "User with cart Id " + cartId + " not found"));
                }
                else
                {
                    queryUserCart.cart = db.CART.Where(u => u.cartId == cartId && u.isClosed == false).ToList();



                    return(Request.CreateResponse(HttpStatusCode.OK, queryUserCart));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
コード例 #11
0
        public JsonResult getCartItems(int userId)
        {
            string StoredProcedureName             = UserCartProcedures.getCartItems;
            Dictionary <string, object> Parameters = new Dictionary <string, object>();

            Parameters.Add("@user_id", userId);

            var dt = dbMan.ExecuteReader(StoredProcedureName, Parameters);

            if (dt == null)
            {
                return(Json(null));
            }
            List <UserCart> UserCarts = new List <UserCart>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var Cart = new UserCart();
                Cart.drugId     = Convert.ToInt32(dt.Rows[i]["drugId"]);
                Cart.drugName   = Convert.ToString(dt.Rows[i]["drugName"]);
                Cart.sellerId   = Convert.ToInt32(dt.Rows[i]["sellerId"]);
                Cart.sellerName = Convert.ToString(dt.Rows[i]["sellerName"]);
                Cart.listingId  = Convert.ToInt32(dt.Rows[i]["listingId"]);
                Cart.shreets    = Convert.ToInt32(dt.Rows[i]["shreets"]);
                Cart.elbas      = Convert.ToInt32(dt.Rows[i]["elbas"]);
                Cart.price      = Convert.ToInt32(dt.Rows[i]["price"]);

                UserCarts.Add(Cart);
            }


            return(Json(UserCarts));
        }
コード例 #12
0
        public void GetListOfItemsInCart()
        {
            List <Item> _items = new List <Item>()
            {
                new Item()
                {
                    ProductName = "A",
                    Price       = 10
                },
                new Item()
                {
                    ProductName = "B",
                    Price       = 20
                }
            };

            var userCart = new UserCart();

            foreach (var item in _items)
            {
                userCart.AddItem(item);
            }

            Assert.IsTrue(userCart.Items.Count == 2);
        }
コード例 #13
0
        public JsonResult <Object> RemoveBookFromBasket(string UserID, int BookID)
        {
            bool results = false;

            try
            {
                using (var db = new BookPoolEntities())
                {
                    UserCart userCart = db.UserCarts.FirstOrDefault(x => x.UserID == UserID);
                    if (userCart != null)
                    {
                        List <int> booksIDsInCart = userCart.BooksIDsCSV.Split(',').Select(int.Parse).ToList();
                        booksIDsInCart.Remove(BookID);

                        userCart.BooksIDsCSV = string.Join(",", booksIDsInCart);
                        db.SaveChanges();
                    }
                }

                results = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(Json((object)new { results }));
        }
コード例 #14
0
 public static Models.Repository.UserCart CreateUserCartDto(this UserCart userCart)
 {
     return(new Models.Repository.UserCart
     {
         UserId = userCart.UserId
     });
 }
コード例 #15
0
        public IActionResult Quantity([FromBody] Object obj)
        {
            // int count = Convert.ToInt32(HttpContext.Session.GetInt32("count"));
            UserCart cart_model = System.Text.Json.JsonSerializer.Deserialize <UserCart>(obj.ToString());
            //dBTester.updateCart(cart_model);
            List <UserCart> selectedproducts = JsonConvert.DeserializeObject <List <UserCart> >(HttpContext.Session.GetString("selectedproducts"));
            UserCart        prod             = selectedproducts.Single(model => model.ProductId == cart_model.ProductId);

            if (prod != null)
            {
                prod.ProductQuantity = cart_model.ProductQuantity;
                prod.subTotal        = cart_model.subTotal;
                HttpContext.Session.SetString("selectedproducts", JsonConvert.SerializeObject(selectedproducts));

                return(Json(new
                {
                    success = true,
                }));
            }
            else
            {
                return(Json(new
                {
                    success = false,
                }));
            }
        }
コード例 #16
0
        public ActionResult PartialCartListView()
        {
            UserCart uc = (UserCart)Session["CurrentCart"];

            //int n = uc.PrdList.Count();
            return(PartialView(uc.PrdList));
        }
コード例 #17
0
        public bool UpdateItemQuantity(string Type, long id)
        {
            bool status = false;

            try
            {
                UserCart objCart = context.UserCarts.Where(x => x.Id == id).FirstOrDefault();
                if (objCart != null)
                {
                    if (Type.Trim().ToLower() == "inc")
                    {
                        objCart.Quantity = objCart.Quantity + 1;
                    }
                    if (Type.Trim().ToLower() == "des")
                    {
                        objCart.Quantity = objCart.Quantity - 1;
                    }

                    context.SaveChanges();
                    status = true;
                }
            }
            catch (Exception ex)
            {
            }
            return(status);
        }
コード例 #18
0
        public UserCart GetCartByUserId(int userId)
        {
            var userCart = _CartList.Find((cart => cart.UserId == userId));

            if (userCart == null)
            {
                userCart = new UserCart {
                    UserId = userId
                };
            }

            var    userOrders  = OrderRepository.getOrderRepository().GetLast12Months(userId);
            double totalOrders = userOrders.Sum(order => order.Total);

            var    discount   = 0.0;
            double goldGoal   = double.Parse(ConfigurationManager.AppSettings["GoldGoal"] ?? "1500");
            double silverGoal = double.Parse(ConfigurationManager.AppSettings["SilverGoal"] ?? "500");

            if (totalOrders >= goldGoal)
            {
                discount = double.Parse(ConfigurationManager.AppSettings["GoldDiscount"] ?? "2");
            }
            else if (totalOrders >= silverGoal)
            {
                discount = double.Parse(ConfigurationManager.AppSettings["SilverDiscount"] ?? "2");
            }

            userCart.UserDiscount = 1.0 - (discount / 100.0);

            return(userCart);
        }
コード例 #19
0
        public string AddCart(int id)
        {
            UserCart uc;

            if (Session["CurrentCart"] == null)
            {
                uc = new UserCart();
            }
            else
            {
                uc = (UserCart)Session["CurrentCart"];
            }
            string messageAddCart = "";

            Product prd = ctx.Products.FirstOrDefault(x => x.ProductID == id);

            foreach (Product prod in uc.PrdList)
            {
                if (id == prod.ProductID)
                {
                    messageAddCart = "Seçmiş olduğunuz ürün sepette var";
                    return(messageAddCart);
                }
            }

            uc.PrdList.Add(prd);
            Session["CurrentCart"] = uc;
            messageAddCart         = "Ürün sepete eklendi";
            return(messageAddCart);
        }
コード例 #20
0
        public void SetUserCart([FromBody] string cartJson)
        {
            if (cartJson == null)
            {
                return;
            }

            //Get id of currently authorized user
            string id = User.FindFirstValue(ClaimTypes.NameIdentifier);

            //Get saved cart data, if any, from database
            UserCart cart = _context.UserCart
                            .Where(c => c.UserId.Equals(id))
                            .FirstOrDefault();

            //If the cart data is null, create a new UserCart object and save to the database. Otherwise update the existing.
            if (cart == null)
            {
                cart = new UserCart()
                {
                    UserId   = id,
                    CartData = cartJson
                };

                _context.Add(cart);
            }
            else
            {
                cart.CartData = cartJson;
                _context.Update(cart);
            }

            _context.SaveChanges();
        }
コード例 #21
0
ファイル: UserRepository.cs プロジェクト: poojaghosh/testgit
        public bool MoveFromCartToSaveItem(long id)
        {
            bool status = false;

            try
            {
                UserCart objCart = context.UserCarts.Where(x => x.Id == id).FirstOrDefault();
                if (objCart != null)
                {
                    UserSavedItem objSavedItem = new UserSavedItem();
                    objSavedItem.ProductName        = objCart.ProductName;
                    objSavedItem.ProductSKU         = objCart.ProductSKU;
                    objSavedItem.ProductDescription = objCart.ProductDescription;
                    objSavedItem.UserId             = objCart.UserId;
                    objSavedItem.UserEmail          = objCart.UserEmail;
                    objSavedItem.Quantity           = objCart.Quantity;
                    objSavedItem.MSRP     = objCart.MSRP;
                    objSavedItem.UnitRate = objCart.UnitRate;
                    objSavedItem.Discount = objCart.Discount;
                    objSavedItem.Active   = true;

                    writeContext.UserSavedItems.Add(objSavedItem);
                    writeContext.SaveChanges();

                    objCart.Active = false;
                    context.SaveChanges();
                    status = true;
                }
            }
            catch (Exception ex)
            {
            }
            return(status);
        }
コード例 #22
0
        private void ClearCart()
        {
            var userId = Request.Cookies["cart"].Value;
            IMongoCollection <UserCart> cartsCollection = Database.GetCollection <UserCart>("Carts");
            UserCart cart = cartsCollection.Find(x => x.UserId == userId).FirstOrDefault();

            cartsCollection.DeleteMany(x => x.Id == cart.Id);
        }
コード例 #23
0
 public static UserCart ToModel(this UserCart cart)
 {
     return(new UserCart()
     {
         UserId = cart.UserId,
         ItemId = cart.ItemId
     });
 }
コード例 #24
0
        public Task SaveUserCartAsync(UserCart userCart)
        {
            var db           = this.mux.GetDatabase();
            var userCartData = UserCartData.FromUserCart(userCart);
            var key          = GetKey(userCartData.UserId);

            return(db.StringSetAsync(key, JsonConvert.SerializeObject(userCartData)));
        }
コード例 #25
0
        public void JustTest()
        {
            // SETUP ITEMS
            List <Item> _items = new List <Item>()
            {
                new Item()
                {
                    ProductName = "A",
                    Price       = 10,
                    Quantity    = 10
                },
                new Item()
                {
                    ProductName = "B",
                    Price       = 20,
                    Quantity    = 3
                }
            };

            _items.Add(new Item()
            {
                ProductName = "B",
                Price       = 20,
                Quantity    = 7
            });

            var userCart = new UserCart();

            foreach (var item in _items)
            {
                userCart.AddItem(item);
            }

            // SETUP DISCOUNTS
            List <Discount> discounts = new List <Discount>();

            discounts.Add(new Discount()
            {
                Product    = "A",
                Percentage = 50,
                Threshold  = 3
            });

            discounts.Add(new Discount()
            {
                Product    = "B",
                Percentage = 25,
                Threshold  = 4
            });

            // AFTER DISCOUNT TOTAL PRICE
            // A: 85
            // B: 190
            // TOTAL: 275
            userCart.ApplyDiscounts(discounts);

            Assert.AreEqual(userCart.TotalPrice(), 275);
        }
コード例 #26
0
        public UserCart EmptyCart(int productId)
        {
            UserDetail userDetail = GetUserDetail();
            UserCart   userCart   = _cartRepo.GetCartByUserId(userDetail.UserId);

            userCart.EmptyCart();
            _cartRepo.UpdateCart(userCart);
            return(userCart);
        }
コード例 #27
0
        Boolean PaymentInterface.payForProduct(string creditCard, User session, UserCart product)
        {
            if (impl != null)
            {
                return(impl.payForProduct(creditCard, session, product));
            }

            return(false);
        }
コード例 #28
0
        //Update
        public static void updateCart(int cartId, int userId, int shoeId, int quantity)
        {
            UserCart updateCart = DBSingleton.getDB().UserCart.Where(y => y.CartId == cartId).SingleOrDefault();

            updateCart.UserId   = userId;
            updateCart.ShoeId   = shoeId;
            updateCart.Quantity = quantity;
            DBSingleton.getDB().SaveChanges();
        }
コード例 #29
0
        public UserCart DecreaseQuantity(int productId)
        {
            UserDetail userDetail = GetUserDetail();
            UserCart   userCart   = _cartRepo.GetCartByUserId(userDetail.UserId);

            userCart.DecreaseQuantity(productId);
            _cartRepo.UpdateCart(userCart);
            return(userCart);
        }
コード例 #30
0
        public void editExistingUserCart()
        {
            Boolean check = userCartsArchive.editUserCarts("itamar", 1, 20);

            Assert.IsTrue(check);
            UserCart uc = userCartsArchive.getUserCart("itamar", 1);

            Assert.AreEqual(uc.getAmount(), 20);
        }