Example #1
0
        /// <summary>
        /// Returns an ItemResult and calculates the exact quantity of itens stacked
        /// The logic looks the unformated item name and check if the quantity is displayed
        /// If not, do a operation using item weight and base item weight (weight of only one item)
        /// </summary>
        /// <param name="item">The item entity</param>
        /// <param name="unformatedItemName">Item string before to be formatted. It allow us to obtain the quantity</param>
        /// <returns>Item result with the specified quantity and value</returns>
        private static ItemResultDTO GetItemResult(Item item, string unformatedItemName)
        {
            var itemResult = new ItemResultDTO(item);

            // Items that does NOT need to check the weight to calculate
            if (!item.NeedWeightInCalc)
            {
                try
                {
                    itemResult.Quantity = Convert.ToInt32(Regex.Match(unformatedItemName.Substring(0, 5), @"[0-9]+").Value.Trim());
                }
                catch
                {
                    itemResult.Quantity = 1;
                }
            }
            // Items that NEED to check the weight to calculate
            else
            {
                var totalWeight   = Convert.ToDouble(Regex.Match(unformatedItemName, @"[0-9].+").Value.TrimEnd(), CultureInfo.InvariantCulture);
                var weightPerItem = item.Weight.HasValue ? item.Weight.Value : totalWeight;

                itemResult.Quantity = Convert.ToInt32(totalWeight / weightPerItem);
            }

            return(itemResult);
        }
Example #2
0
 public string GetItemImagePath(ItemResultDTO item)
 {
     return(GetItemImagePath(item.Item));
 }