コード例 #1
0
        /// <summary>
        /// Determines the amount of items to add to a AMountToAddViewModel using the parameter listed
        ///
        /// </summary>
        /// <param name="locationId"></param>
        /// <param name="inventoryId"></param>
        /// <param name="productName"></param>
        /// <param name="customerGuid"></param>
        /// <returns></returns>
        public AmountToAddViewModel AmountToAdd(int locationId, int inventoryId, string productName, Guid customerGuid)
        {
            // Cart currentCart = _repository.GetCart(customerGuid);
            Product product = new Product();

            product = _repository.GetProduct(productName);
            byte[] picture     = product.ByteArrayImage;
            int    amountTotal = _repository.GetInventoryStock(inventoryId);

            AmountToAddViewModel addToCartViewModel = new AmountToAddViewModel()
            {
                stock       = amountTotal,
                location    = locationId,
                CustomerId  = customerGuid,
                inventory   = inventoryId,
                Product     = productName,
                discription = product.Description
            };

            if (picture != null)
            {
                addToCartViewModel.JpgString = _mapper.ConvertByteArrayToString(picture);
            }
            return(addToCartViewModel);
        }
コード例 #2
0
        /// <summary>
        /// takes an AmountToAddViewModel and adds the properties to a cart
        /// in the DB
        /// </summary>
        /// <param name="amountToAddView"></param>
        public void AddToCart(AmountToAddViewModel amountToAddView)
        {
            Cart currentCart = new Cart();

            currentCart.location = amountToAddView.location;
            currentCart.Owner    = GetCustomerById(amountToAddView.CustomerId);
            currentCart.Product  = GetProduct(amountToAddView.Product);
            currentCart.amount   = amountToAddView.amount;
            cartSet.Add(currentCart);
            _dbcontext.SaveChanges();
        }
コード例 #3
0
        /// <summary>
        /// Checks to see if the user has selected enough or too many products
        /// from the list of available stock
        /// </summary>
        /// <param name="amountToAddView"></param>
        /// <returns></returns>
        public IActionResult CanBeAdded(AmountToAddViewModel amountToAddView)
        {
            if (amountToAddView.amount > amountToAddView.stock)
            {
                ModelState.AddModelError("Failure", "The amount you chose exceeded stock");
                return(View("AddToCart", amountToAddView));
            }

            if (amountToAddView.amount != 0)
            {
                ModelState.AddModelError("Success", "Item(s) added to cart");
                _businessLogicClass.AddToCart(amountToAddView);
                _businessLogicClass.SubtractFromInventory(amountToAddView.inventory, amountToAddView.amount);
            }
            List <InventoryViewModel> inventoryViewModels = _businessLogicClass.SearchInventoryList(amountToAddView.location, amountToAddView.CustomerId);

            return(View("InventoryList", inventoryViewModels));
        }
コード例 #4
0
        public IActionResult AddingToCart(int LocationId, int InventoryId, string productName, Guid customerGuid)//Gets all the necessary values from here
        {
            AmountToAddViewModel amountToAddViewModel = _businessLogicClass.AmountToAdd(LocationId, InventoryId, productName, customerGuid);

            return(View("AddToCart", amountToAddViewModel));
        }
コード例 #5
0
 /// <summary>
 /// Throws an AmountToAddViewModel to the repository
 /// </summary>
 /// <param name="amountToAddViewModel"></param>
 public void AddToCart(AmountToAddViewModel amountToAddViewModel)
 {
     _repository.AddToCart(amountToAddViewModel);
 }