示例#1
0
        public void TestThatFoodGroupGetAllOnRootGetsFoodGroupsAtRootLevel()
        {
            var foodGroupAtRoot = _systemDataRepository.Insert(new FoodGroup {
                Parent = null, IsActive = true
            });

            try
            {
                var foodGroupWithParent = _systemDataRepository.Insert(new FoodGroup {
                    Parent = foodGroupAtRoot, IsActive = true
                });
                try
                {
                    var result = _systemDataRepository.FoodGroupGetAllOnRoot().ToList();
                    Assert.That(result, Is.Not.Null);
                    Assert.That(result, Is.Not.Empty);
                    Assert.That(result.Any(m => m.Identifier.HasValue && m.Identifier.Equals(foodGroupAtRoot.Identifier)), Is.True);
                    Assert.That(result.Any(m => m.Identifier.HasValue && m.Identifier.Equals(foodGroupWithParent.Identifier)), Is.False);
                }
                finally
                {
                    _systemDataRepository.Delete(foodGroupWithParent);
                }
            }
            finally
            {
                _systemDataRepository.Delete(foodGroupAtRoot);
            }
        }
示例#2
0
        /// <summary>
        /// Functionality which handles a query for getting the tree of food groups.
        /// </summary>
        /// <param name="query">Query for getting the tree of food groups.</param>
        /// <returns>Tree of food groups.</returns>
        public virtual TFoodGroupTreeView Query(FoodGroupTreeGetQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var translationInfo = _systemDataRepository.Get <ITranslationInfo>(query.TranslationInfoIdentifier);
            var dataProvider    = _systemDataRepository.DataProviderForFoodGroupsGet();
            var foodGroups      = _systemDataRepository.FoodGroupGetAllOnRoot()
                                  .Where(foodGroup => foodGroup.ForeignKeys != null && foodGroup.ForeignKeys.Any(foreignKey => foreignKey.DataProvider != null && foreignKey.DataProvider.Identifier == dataProvider.Identifier))
                                  .ToList();

            dataProvider.Translate(translationInfo.CultureInfo);

            var foodGroupCollection = new FoodGroupCollection(foodGroups, dataProvider);

            if (OnlyActive)
            {
                foodGroupCollection.RemoveInactiveFoodGroups();
            }

            return(_foodWasteObjectMapper.Map <IFoodGroupCollection, TFoodGroupTreeView>(foodGroupCollection, translationInfo.CultureInfo));
        }