示例#1
0
        private async Task <bool> NotContradictAllergenAndDietaryPref(CookEntryDto cookEntry, CancellationToken token)
        {
            if (!cookEntry.Allergens.Any() && !cookEntry.DietaryPreferences.Any())
            {
                return(true);
            }

            var systemSettings = await _systemSettingIntercom.GetAllSystemSettings();

            foreach (var dietPref in cookEntry.DietaryPreferences)
            {
                var allergenBlackList = systemSettings.DietaryPreferences.First(x => x.Name == dietPref).ContradictiveAllergen.ToList();

                if (cookEntry.Allergens.Any(allergen => allergenBlackList.Contains(allergen)))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        private async Task <bool> BeValidCategories(ICollection <string> categories, CancellationToken token)
        {
            var systemSettings = await _systemSettingIntercom.GetAllSystemSettings();

            if (categories == null)
            {
                return(true);
            }

            if (categories.Distinct(StringComparer.OrdinalIgnoreCase).Count() != categories.Count)
            {
                return(false);
            }

            var invalidAllergens = categories.Except(systemSettings.CookCategories, StringComparer.OrdinalIgnoreCase);

            return(!invalidAllergens.Any());
        }