예제 #1
0
        private static Category FillFactors(List <Member> members, Category item)
        {
            if (item.DefaultCategory == null)
            {
                throw new ArgumentException("This metod was designed for items that contain the same type of default category. Do not use it in other cases");
            }

            var category = item.DefaultCategory.Value;
            var type     = DefaultCategoryUtils.GetCategoryType(category);

            switch (type)
            {
            case Enums.DefaultCategoryType.Calories:
                return(FillFactorsByCalories(members, item));

            case Enums.DefaultCategoryType.EqualDivision:
                return(FillFactorsByEqualDivision(members, item));

            default:
                throw new InvalidOperationException("The default category type cannot be merged");
            }
        }
예제 #2
0
 private static void MergeTwoListsOfCategories(List <Member> members, List <Category> merged, List <Category> list)
 {
     foreach (var item in list)
     {
         if (item.DefaultCategory.HasValue)
         {
             var itemInMergedList = merged.FirstOrDefault(x => x.DefaultCategory == item.DefaultCategory);
             var itemToUse        = itemInMergedList ?? item;
             var type             = DefaultCategoryUtils.GetCategoryType(itemToUse.DefaultCategory.Value);
             if (type == Enums.DefaultCategoryType.Calories ||
                 type == Enums.DefaultCategoryType.EqualDivision)
             {
                 var mergedItem = FillFactors(members, itemToUse);
                 if (itemInMergedList == null)
                 {
                     merged.Add(mergedItem);
                 }
                 continue;
             }
         }
         merged.Add(item);
     }
 }