Exemplo n.º 1
0
        /// <summary>
        /// Get possible stock existence as per database's records.
        /// </summary>
        /// <param name="shelterId"></param>
        /// <returns></returns>
        public ActionResult PossibleShelterStock(int shelterId)
        {
            var stockList = new List <float>();
            var items     = ShelterRepository.GetShelterItemsByKey(shelterId);

            foreach (var item in items)
            {
                var itemQuantity       = item.ItemQuantity;
                var totalItemsQuantity = ItemRepository.GetItemTotalQuantity(item.ItemId);

                if (itemQuantity.Equals(0) || totalItemsQuantity < itemQuantity)
                {
                    stockList.Add(0);
                    break;
                }

                var possComb = totalItemsQuantity / itemQuantity;
                stockList.Add(possComb);
            }

            if (stockList.Count <= 0)
            {
                return(Content(Convert.ToString(0)));
            }
            var stock = Math.Floor((decimal)stockList.Min());

            return(Content(stockList.Count > 0 ? Convert.ToString(stock) : Convert.ToString(0)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get model for ShelterItems.
        /// </summary>
        /// <param name="shelterId">shelterId for which items to be shown.</param>
        /// <param name="qtyMultiple">Number of shelter user is requesting.</param>
        /// <returns></returns>
        private static ShelterItemsModel GetShelterItems(int shelterId, int qtyMultiple)
        {
            var items = ShelterRepository.GetShelterItemsByKey(shelterId, qtyMultiple);

            return(new ShelterItemsModel {
                ShelterKey = shelterId, ShelterItems = items
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get possible product stock by existing items.
        /// </summary>
        private static string PossibleRequestStock(int productId)
        {
            var items = ShelterRepository.GetShelterItemsByKey(productId);

            var stockList = (from item in items let itemQuantity = item.ItemQuantity let totalItemsQuantity = ItemRepository.GetItemTotalQuantity(item.ItemId) where totalItemsQuantity > itemQuantity select totalItemsQuantity / itemQuantity).ToList();

            return(stockList.Count > 0 ? string.Format("{0:N2}", stockList.Min()) : Convert.ToString(0));
        }