/// <summary> /// Functionality which handles a query for getting the collection of food items. /// </summary> /// <param name="query">Query for getting the collection of food items.</param> /// <returns>Collection of food items.</returns> public virtual TFoodItemCollectionView Query(FoodItemCollectionGetQuery query) { if (query == null) { throw new ArgumentNullException("query"); } var translationInfo = _systemDataRepository.Get <ITranslationInfo>(query.TranslationInfoIdentifier); var dataProvider = _systemDataRepository.DataProviderForFoodItemsGet(); IFoodGroup foodGroup = null; if (query.FoodGroupIdentifier.HasValue) { foodGroup = _systemDataRepository.Get <IFoodGroup>(query.FoodGroupIdentifier.Value); } dataProvider.Translate(translationInfo.CultureInfo); var foodItemCollection = foodGroup == null ? GetFoodItemsForDataProvider(_systemDataRepository.FoodItemGetAll(), dataProvider) : GetFoodItemsForDataProvider(_systemDataRepository.FoodItemGetAllForFoodGroup(foodGroup), dataProvider); if (OnlyActive) { foodItemCollection.RemoveInactiveFoodItems(); } return(_foodWasteObjectMapper.Map <IFoodItemCollection, TFoodItemCollectionView>(foodItemCollection, translationInfo.CultureInfo)); }
/// <summary> /// Functionality which handles the query for getting a collection of data providers who handles payments. /// </summary> /// <param name="query">Query for getting a collection of data providers who handles payments.</param> /// <returns>Collection of data providers who handles payments.</returns> public virtual IEnumerable <DataProviderView> Query(DataProviderWhoHandlesPaymentsCollectionGetQuery query) { if (query == null) { throw new ArgumentNullException("query"); } var translationInfo = _systemDataRepository.Get <ITranslationInfo>(query.TranslationInfoIdentifier); var dataProviders = _systemDataRepository.DataProviderWhoHandlesPaymentsGetAll(); return(_foodWasteObjectMapper.Map <IEnumerable <IDataProvider>, IEnumerable <DataProviderView> >(dataProviders, translationInfo.CultureInfo)); }
/// <summary> /// Functionality which handles the query for getting a collection of static texts. /// </summary> /// <param name="query">Query for getting a collection of static texts.</param> /// <returns>Collection of static texts.</returns> public virtual IEnumerable <StaticTextSystemView> Query(StaticTextCollectionGetQuery query) { if (query == null) { throw new ArgumentNullException("query"); } var translationInfo = _systemDataRepository.Get <ITranslationInfo>(query.TranslationInfoIdentifier); var staticTexts = _systemDataRepository.StaticTextGetAll(); return(_foodWasteObjectMapper.Map <IEnumerable <IStaticText>, IEnumerable <StaticTextSystemView> >(staticTexts, translationInfo.CultureInfo)); }
/// <summary> /// Functionality which handles a query for getting a specific static text. /// </summary> /// <param name="query">Query for getting the specific static text.</param> /// <returns>Static text.</returns> public virtual StaticTextView Query(TQuery query) { if (query == null) { throw new ArgumentNullException("query"); } var translationInfo = _systemDataRepository.Get <ITranslationInfo>(query.TranslationInfoIdentifier); var staticText = _systemDataRepository.StaticTextGetByStaticTextType(StaticTextType); return(_foodWasteObjectMapper.Map <IStaticText, StaticTextView>(staticText, translationInfo.CultureInfo)); }
/// <summary> /// Functionality which handles a query for getting a collection of storage types. /// </summary> /// <param name="query">Query for getting a collection of storage types.</param> /// <returns>Collection of the storages types.</returns> public virtual IEnumerable <TView> Query(TQuery query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } ITranslationInfo translationInfo = _systemDataRepository.Get <ITranslationInfo>(query.TranslationInfoIdentifier); IEnumerable <IStorageType> storageTypeCollection = _systemDataRepository.StorageTypeGetAll(); return(_objectMapper.Map <IEnumerable <IStorageType>, IEnumerable <TView> >(storageTypeCollection, translationInfo.CultureInfo)); }
public void TestThatGetGetsFoodItem() { var primaryFoodGroup = _systemDataRepository.Insert(new FoodGroup { Parent = null, IsActive = true }); try { var foodItem = _systemDataRepository.Insert(new FoodItem(primaryFoodGroup) { IsActive = true }); try { // ReSharper disable PossibleInvalidOperationException var result = _systemDataRepository.Get <IFoodItem>(foodItem.Identifier.Value); // ReSharper restore PossibleInvalidOperationException Assert.That(result, Is.Not.Null); Assert.That(result.PrimaryFoodGroup, Is.Not.Null); Assert.That(result.PrimaryFoodGroup.Identifier, Is.Not.Null); // ReSharper disable ConditionIsAlwaysTrueOrFalse Assert.That(result.PrimaryFoodGroup.Identifier.HasValue, Is.True); // ReSharper restore ConditionIsAlwaysTrueOrFalse // ReSharper disable PossibleInvalidOperationException Assert.That(result.PrimaryFoodGroup.Identifier.Value, Is.EqualTo(primaryFoodGroup.Identifier.Value)); // ReSharper restore PossibleInvalidOperationException Assert.That(result.IsActive, Is.True); Assert.That(result.FoodGroups, Is.Not.Null); Assert.That(result.FoodGroups, Is.Not.Empty); Assert.That(result.FoodGroups.Count(), Is.EqualTo(1)); Assert.That(result.FoodGroups.SingleOrDefault(fg => fg.Identifier.HasValue && fg.Identifier.Equals(primaryFoodGroup.Identifier)), Is.Not.Null); } finally { _systemDataRepository.Delete(foodItem); } } finally { _systemDataRepository.Delete(primaryFoodGroup); } }
/// <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)); }