示例#1
0
        public static bool AddCartItemQuantity(int movieId, string theMovieName, float theUnitPrice, int theQuantity)
        {
            bool noDuplicate   = false;
            var  duplicateTest = from eachItem in BasePage.shoppingCart
                                 where eachItem.MovieId == movieId
                                 select eachItem;
            int duplicateCount = duplicateTest.Count();

            if (duplicateTest == null || duplicateCount == 0)
            {
                // theTempOrderID = duplicateTest.FirstOrDefault().TempOrderID;
                ShoppingCartData shoppingItem = new ShoppingCartData()
                {
                    TempOrderID = ++theTempOrderID,
                    MovieId     = movieId,
                    Name        = theMovieName,
                    Price       = theUnitPrice,
                    Quantity    = theQuantity
                };
                // check that the same item isn't in the cart.
                // if it is get the Quantity and increment the Quantity.
                // and remove Quantity from stock
                AddRecord(shoppingItem);
                noDuplicate = true;
            }
            return(noDuplicate);
        }
        private void addToCart(int pId)
        {
            // check if product is valid
            Product product = _ctx.Products.FirstOrDefault(p => p.PID == pId);

            if (product != null && product.UnitsInStock > 0)
            {
                // check if product already existed
                ShoppingCartData cart = _ctx.ShoppingCartDatas.FirstOrDefault(c => c.PID == pId);
                if (cart != null)
                {
                    cart.Quantity++;
                }
                else
                {
                    cart = new ShoppingCartData
                    {
                        PName     = product.PName,
                        PID       = product.PID,
                        UnitPrice = product.UnitPrice,
                        Quantity  = 1
                    };

                    _ctx.ShoppingCartDatas.Add(cart);
                }
                product.UnitsInStock--;
                _ctx.SaveChanges();
            }
        }
 public void AddShoppingCartData(ShoppingCartData shoppingCartData)
 {
     using (var db = new VoetbalEntities())
     {
         db.ShoppingCartDatas.Add(shoppingCartData);
         db.SaveChanges();
     }
 }
示例#4
0
        //Delete record
        public static void DeleteRecord(ShoppingCartData record)
        {
            var result = from eachRecord in BasePage.shoppingCart
                         where eachRecord.TempOrderID == record.TempOrderID
                         select eachRecord;

            // delete movie item and quantity
            BasePage.shoppingCart.Remove(result.FirstOrDefault());
        }
示例#5
0
        protected void ViewShoppingCartContents(Object sender, EventArgs e)
        {
            DataTable tab = GetAllCartItems();

            ShoppingCartData.DataSource = tab;
            ShoppingCartData.DataBind();
            ShoppingCartContents.Visible = true;
            SubmitError.Text             = "";
        }
 public void RemoveShoppingCartData(int shoppingCartDataId)
 {
     using (var db = new VoetbalEntities())
     {
         ShoppingCartData toRemove = new ShoppingCartData {
             id = shoppingCartDataId
         };
         db.Entry(toRemove).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
     }
 }
示例#7
0
        protected static void UpdateRecordPending(ShoppingCartData newRecord)
        {
            // Find the original cart record to update
            int movieId = newRecord.MovieId;
            ShoppingCartData oldRecord = BasePage.shoppingCart.Find(x => x.MovieId.Equals(movieId));

            // if the quantities are the same delete the cart item and replace stock items(which is in the addcartitem method).
            if (oldRecord != null && newRecord != null)
            {
                oldRecord.Quantity++;
            }
        }
示例#8
0
        public void UpdateShoppingCartAsyncJson()
        {
            var itemId = int.Parse(id);

            _shoppingCart = ShoppingCartData.ShoppingCartUpdate(int.Parse(id));
            var res     = GetRequest.UpdateShoppingCartAsyncJson(_shoppingCart, itemId);
            var res1    = res.Content.ToString().TrimStart('"');
            var results = res1.ToString().TrimEnd('"');

            idUpdated = GetRequest.updateResults;
            var responce = $"Successfully updated user with Id:{idUpdated}";

            Assert.AreEqual(results, responce);
        }
示例#9
0
        public JsonResult QuanityChange(int type, int pId)
        {
            JewelryBizOnlineEntities context = new JewelryBizOnlineEntities();

            ShoppingCartData product = context.ShoppingCartDatas.FirstOrDefault(p => p.PID == pId);

            if (product == null)
            {
                return(Json(new { d = "0" }));
            }

            Product actualProduct = context.Products.FirstOrDefault(p => p.PID == pId);
            int     quantity;

            // if type 0, decrease quantity
            // if type 1, increase quanity
            switch (type)
            {
            case 0:
                product.Quantity--;
                actualProduct.UnitsInStock++;
                break;

            case 1:
                product.Quantity++;
                actualProduct.UnitsInStock--;
                break;

            case -1:
                actualProduct.UnitsInStock += product.Quantity;
                product.Quantity            = 0;
                break;

            default:
                return(Json(new { d = "0" }));
            }

            if (product.Quantity == 0)
            {
                context.ShoppingCartDatas.Remove(product);
                quantity = 0;
            }
            else
            {
                quantity = product.Quantity;
            }

            context.SaveChanges();
            return(Json(new { d = quantity }));
        }
示例#10
0
        public IActionResult AddItem([FromBody] Add add)
        {
            //simulate extracting userId from Session
            int userId = 1;

            //store identifier as Add object and convert to integer
            int productId = Convert.ToInt32(add.Id);

            //send identifier to database to update quantity record
            ShoppingCartData.AddItem(userId, productId);

            return(Json(new
            {
                success = true
            }));
        }
示例#11
0
        public IActionResult RemoveItem([FromBody] Remove remove)
        {
            //simulate extracting userId from Session
            int userId = 1;

            //store identifier as Remove object and convert to integer
            int productId = Convert.ToInt32(remove.Id);

            //send identifier to database to remove record
            ShoppingCartData.RemoveItem(userId, productId);

            return(Json(new
            {
                success = true
            }));
        }
示例#12
0
        static void Main(string[] args)
        {
            bool isFirstTime = true;
            int  exit        = 0;


            while (exit != 101)
            {
                ProductList(isFirstTime);
                isFirstTime = false;


                var productNumber = Convert.ToInt32(Console.ReadLine());
                exit = productNumber;
                if (exit == 101)
                {
                    return;
                }

                Product selectedProduct = ProductData.products.Where(p => p.Id == productNumber).FirstOrDefault();

                Console.WriteLine("Sepete eklemek istediğiniz ürünün miktarını giriniz ya çıkmak için '101' yazınız...:");
                var productAmount = Convert.ToInt32(Console.ReadLine());
                exit = productAmount;
                if (exit == 101)
                {
                    return;
                }

                ShoppingCart shoppingCart = new ShoppingCart();
                shoppingCart.ProductId   = productNumber;
                shoppingCart.ProductName = selectedProduct.Name;
                shoppingCart.Price       = selectedProduct.Price;
                shoppingCart.Amount      = productAmount;

                ShoppingCartData.AddProduct(shoppingCart);

                Console.WriteLine(productNumber + "-" + selectedProduct.Name);

                Console.WriteLine("Sepeteki ürünler...:");
                foreach (var item in ShoppingCartData.shoppingCarts)
                {
                    Console.WriteLine($"No:{item.ProductId} - {item.ProductName} -Adet: {item.Amount} - Fiyatı:{item.Price}-{item.TotalPrice}");
                }
                Console.WriteLine("Sepet toplamı...:" + ShoppingCartData.totalPirce.ToString());
            }
        }
示例#13
0
        public void AddShoppingCartData(string user, Ticket ticket, int bestellingId, int wedstrijdId)
        {
            if (MagGebruikerNogEenTicketToevoegen(user, wedstrijdId))
            {
                ShoppingCartData shoppingCartData = new ShoppingCartData();
                shoppingCartData.Ticketid     = ticket.id;
                shoppingCartData.BestellingId = bestellingId;
                shoppingCartData.prijs        = ticket.prijs;

                shoppingCartDataDAO = new ShoppingCartDataDAO();
                shoppingCartDataDAO.AddShoppingCartData(shoppingCartData);
            }
            else
            {
                throw new TeveelTicketsException("Er mogen slechts 4 tickets per wedstrijd besteld worden!");
            }
        }
示例#14
0
        public IActionResult UpdateQuantity([FromBody] Update update)
        {
            //simulate extracting userId from Session
            int userId = 1;

            //store identifier and quantity as Update object and convert to integer
            int productId = Convert.ToInt32(update.Id);
            int quantity  = Convert.ToInt32(update.Quantity);

            //send identifier to database to update quantity record
            ShoppingCartData.UpdateQuantity(userId, productId, quantity);

            return(Json(new
            {
                success = true
            }));
        }
示例#15
0
        public IActionResult Index()
        {
            //simulate extracting userId from Session
            int userId = 1;

            //retrieve records from Cart
            List <Cart> cart = ShoppingCartData.GetCart(userId);

            //create variable to store total price
            double total = 0;

            //add price of each item into total
            foreach (var item in cart)
            {
                total += item.Price * item.Quantity;
            }

            //send data to View
            if (total == 0)
            {
                ViewData["total"] = "0.00";
            }
            else
            {
                ViewData["total"] = total.ToString("#0.00");
            }
            ViewData["cart"]          = cart;
            ViewData["images_prefix"] = "/img/";

            // to highlight "Shopping" as the selected menu-item
            ViewData["Is_Shopping"] = "menu_hilite";

            // use sessionId to determine if user has already logged in
            ViewData["sessionId"] = Guid.NewGuid().ToString();
            //ViewData["sessionId"] = null;

            //html response
            return(View());
        }
示例#16
0
        public int FindTicketBasedOnShoppingCartId(int shoppingCartDataId)
        {
            ShoppingCartData shoppingCartData = shoppingCartDataDAO.FindShoppingCartData(shoppingCartDataId);

            return(shoppingCartData.Ticketid);
        }
示例#17
0
 public ShoppingCartSteps(ShoppingCartData shoppingCartData)
 {
     _shoppingCartData = shoppingCartData;
 }
示例#18
0
 public static void UpdateRecord(ShoppingCartData newRecord)
 {
     UpdateRecordPending(newRecord);
 }
示例#19
0
 public static void AddRecord(ShoppingCartData record)
 {
     BasePage.shoppingCart.Add(record);
 }
示例#20
0
 public void Setup()
 {
     shoppingCart = ShoppingCartData.ShoppingCartInit();
 }
    protected void GridViewProducts_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "cmdAddToShoppingCart")
        {
            linqTestingDataContext db = new linqTestingDataContext();
            db.Connection.ConnectionString =
        System.Configuration.ConfigurationManager.AppSettings["linqTest"];
            var prod =
                from p in db.Products
                where (p.PID == Convert.ToInt32(e.CommandArgument.ToString()))
                select p;

            var shopping =
                    from scd in db.ShoppingCartDatas
                    where (scd.PID == Convert.ToInt32(e.CommandArgument.ToString()))
                    select scd;
            bool alreadyThere = false;
            foreach(ShoppingCartData scd in shopping)
                alreadyThere = true;

            if (!alreadyThere)
            {
                foreach (Product pp in prod)
                {
                    pID = pp.PID;
                    pName = pp.PName;
                    unitPrice = pp.UnitPrice;
                }

                ShoppingCartData scd = new ShoppingCartData
                {
                    PID = pID,
                    PName = pName,
                    UnitPrice = unitPrice,
                    Quantity = 1
                };

                db.ShoppingCartDatas.InsertOnSubmit(scd);
                db.SubmitChanges();

                DisplayShoppingCart();
                displayCatalogue();
            }
            else
                LabelAlreadyThere.Text="Item Already in the shopping Cart";
        }
    }