Example #1
0
        public async Task <int> RemoveProductFromBasket(string UserID, string ProductID)
        {
            string basketID = await _basketRepository.GetBasketIDByUserID(UserID);

            BasketProducts basketProduct = await _basketProductsRepository.GetProductFromBasket(basketID, ProductID);

            return(await _basketProductsRepository.RemoveProductFromBasket(basketProduct));
        }
Example #2
0
 public void AddProduct(Product product)
 {
     if (product == null)
     {
         throw new ArgumentNullException(nameof(product));
     }
     BasketProducts.Add(product);
 }
Example #3
0
        public async Task <int> AddProductToBasket(string UserID, string ProductID, int Quantity)
        {
            string basketID = await _basketRepository.GetBasketIDByUserID(UserID);

            BasketProducts basketProducts = new BasketProducts(basketID, ProductID, Quantity);

            return(await _basketProductsRepository.AddProductToBasket(basketProducts));
        }
Example #4
0
 /// <summary>
 /// Gets the basket items with the passed Id.
 /// If the ID is null or -1 returns the products inside all baskets
 /// </summary>
 /// <param name="basketId">The basket identifier.</param>
 /// <returns>IEnumerable&lt;BasketItem&gt;.</returns>
 public IEnumerable <BasketItem> GetBasketItems(int?basketId)
 {
     if (basketId == -1 || basketId == null)
     {
         return(BasketProducts);
     }
     else
     {
         return(BasketProducts.Where(i => i.BasketId == basketId));
     }
 }
 public async Task <int> RemoveProductFromBasket(BasketProducts basketProducts)
 {
     _context.BasketProducts.Remove(basketProducts);
     try
     {
         return(await _context.SaveChangesAsync());
     }
     catch (Exception e)
     {
         return(0);
     }
 }
 public async Task <int> AddProductToBasket(BasketProducts basketProduct)
 {
     _context.BasketProducts.Add(basketProduct);
     try
     {
         return(await _context.SaveChangesAsync());
     }
     catch (Exception e)
     {
         return(0);
     }
 }
Example #7
0
        /// <summary>
        /// Deletes the basket and all elements inside the basket.
        /// Returns BasketDeleteResult.NotFound In case the basket with the passed Id is non existent
        /// </summary>
        /// <param name="basketId">The basket identifier.</param>
        /// <returns>BasketDeleteResult.</returns>
        public BasketDeleteResult DeleteBasketAndAllElements(int basketId)
        {
            var basket = Baskets.FirstOrDefault(i => i.BasketId == basketId);

            if (basket == null)
            {
                return(BasketDeleteResult.NotFound);
            }
            else
            {
                var products = BasketProducts.FirstOrDefault(i => i.BasketId == basketId);
                if (products != null)
                {
                    BasketProducts.RemoveRange(products);
                }
                Baskets.Remove(basket);
                SaveChanges();
            }
            return(BasketDeleteResult.Ok);
        }
Example #8
0
        /// <summary>
        /// Adds the passed product into the basket with the specified ID.
        /// If the basket with tha ID is null a new basket it will be automatically created before adding the item
        /// </summary>
        /// <param name="basketItem">The basket item.</param>
        /// <param name="basketId">The basket identifier.</param>
        public void AddProduct(BasketItem basketItem, int basketId)
        {
            var basket = Baskets.FirstOrDefault(i => i.BasketId == basketId);

            if (basket == null)
            {
                CreateNewBasket(basketId);
            }
            basketItem.BasketId = basketId;
            BasketItem existingItem = BasketProducts.FirstOrDefault(i => i.ProductId == basketItem.ProductId && i.BasketId == basketId);

            if (existingItem == null)
            {
                BasketProducts.Add(basketItem);
            }
            else
            {
                existingItem.Quantity += basketItem.Quantity;
            }
            UpdateBasketProperty(basketItem, basketId);
            UpdateProductStockQuantity(basketItem, null);
            SaveChanges();
        }
Example #9
0
        /// <summary>
        /// Modifies the quantity of the passed basket item.
        /// </summary>
        /// <param name="id">The identifier of the item you want to modify.</param>
        /// <param name="basketItem">The new basket item.</param>
        /// <returns>ProductInjuryResult.</returns>
        public ProductInjuryResult ModifyCartItem(int id, BasketItem basketItem)
        {
            BasketItem existingItem = BasketProducts.FirstOrDefault(i => i.Id == id);

            if (existingItem == null)
            {
                return(ProductInjuryResult.NotFound);
            }
            var newQuantity = basketItem.Quantity - existingItem.Quantity;

            if (newQuantity > 0)
            {
                var result = CheckProduct(basketItem.ProductId, newQuantity);
                if (result != ProductInjuryResult.Ok)
                {
                    return(result);
                }
            }
            existingItem.Quantity = basketItem.Quantity;
            UpdateProductStockQuantity(basketItem, newQuantity);
            SaveChanges();
            return(ProductInjuryResult.Ok);
        }
Example #10
0
    void Update()
    {
        RaycastHit hit;

        float theDistance = -1.0f;

        Vector3 forward = transform.TransformDirection(Vector3.forward) * 10000;

        Debug.DrawRay(transform.position, forward, Color.red);


        if (Physics.Raycast(transform.position, (forward), out hit))
        {
            theDistance = hit.distance;
            print(theDistance + " " + hit.collider.gameObject.name);

            if (hit.collider.gameObject.name == "ProductsBtn")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    Initiate.Fade("Product Scene", Color.black, 2.0f);
                }
            }
            if (hit.collider.gameObject.name == "BasketButton")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    Initiate.Fade("Basket Scene", Color.black, 2.0f);
                }
            }

            if (hit.collider.gameObject.name == "OrdersBtn")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    Initiate.Fade("OrdersScene", Color.black, 2.0f);
                }
            }

            if (hit.collider.gameObject.name == "BasketButton")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    Initiate.Fade("Basket Scene", Color.black, 2.0f);
                }
            }

            if (hit.collider.gameObject.name == "HomeButton")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    Initiate.Fade("Home Scene", Color.black, 2.0f);
                }
            }

            if (hit.collider.gameObject.name == "view3Dbtn")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    Initiate.Fade("3DObjectScene", Color.black, 2.0f);
                }
            }

            if (hit.collider.gameObject.name == "ProdButtonHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    Initiate.Fade("Product Description", Color.black, 2.0f);
                }
            }

            if (hit.collider.gameObject.name == "backBtnHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    Initiate.Fade("Basket Scene", Color.black, 2.0f);
                }
            }

            if (hit.collider.gameObject.name == "view3dBtnHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    Initiate.Fade("3DObjectScene", Color.black, 2.0f);
                }
            }

            if (hit.collider.gameObject.name == "addToBasketBtnHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    ProductDescription.addToBasket();
                }
            }

            if (hit.collider.gameObject.name == "CheckOutBtnHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    checkOutPanel.gameObject.SetActive(true);
                }
            }

            if (hit.collider.gameObject.name == "cancelBtnHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    checkOutPanel.gameObject.SetActive(false);
                }
            }
            if (hit.collider.gameObject.name == "purchaseBtnHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    confirmationPopUp.gameObject.SetActive(true);
                }
            }

            if (hit.collider.gameObject.name == "cnclBtnHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    confirmationPopUp.gameObject.SetActive(false);
                }
            }

            if (hit.collider.gameObject.name == "continueBtnHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    BasketProducts.proceedWithOrder();
                }
            }

            if (hit.collider.gameObject.name == "removeBtnHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    ProductDescription.removeFromBasket();
                    itemPanelOnBasket.gameObject.SetActive(false);
                }
            }

            if (hit.collider.gameObject.name == "GoBtnHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    filterPrint.text = FilteringResults.test();
                }
            }

            if (hit.collider.gameObject.name == "openSizeDrpHelper")
            {
                if (Input.GetKeyDown(KeyCode.P))
                {
                    FetchSizesFromDb.sizeDropdown();
                    sizeDropdown.gameObject.SetActive(true);
                    sizeDropdownTemplate.gameObject.SetActive(true);
                }
            }
        }
    }