Exemplo n.º 1
0
        /// <summary>
        /// Gets all the storages for a given household.
        /// </summary>
        /// <param name="dataProvider">Implementation of the data provider used to access data.</param>
        /// <param name="householdIdentifier">The identifier for the household on which to get the storages.</param>
        /// <returns>All the storages for the given household.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataProvider"/> is null.</exception>
        internal static IEnumerable <StorageProxy> GetStorages(IDataProviderBase <MySqlDataReader, MySqlCommand> dataProvider, Guid householdIdentifier)
        {
            ArgumentNullGuard.NotNull(dataProvider, nameof(dataProvider));

            using (IFoodWasteDataProvider subDataProvider = (IFoodWasteDataProvider)dataProvider.Clone())
            {
                MySqlCommand command = BuildHouseholdDataCommandForSelecting("WHERE s.HouseholdIdentifier=@householdIdentifier", householdDataCommandBuilder => householdDataCommandBuilder.AddHouseholdIdentifierParameter(householdIdentifier));
                return(subDataProvider.GetCollection <StorageProxy>(command));
            }
        }
        /// <summary>
        /// Gets foods groups which has this a given food group as a parent.
        /// </summary>
        /// <param name="dataProvider">Implementation of the data provider used to access data.</param>
        /// <param name="foodGroupIdentifier">Identifier for the food group which is the parent.</param>
        /// <returns>Foods groups which has this a given food group as a parent.</returns>
        private static IEnumerable <FoodGroupProxy> GetFoodGroupChildren(IDataProviderBase <MySqlDataReader, MySqlCommand> dataProvider, Guid foodGroupIdentifier)
        {
            ArgumentNullGuard.NotNull(dataProvider, nameof(dataProvider));

            using (IFoodWasteDataProvider subDataProvider = (IFoodWasteDataProvider)dataProvider.Clone())
            {
                MySqlCommand command = BuildSystemDataCommandForSelecting("WHERE fg.ParentIdentifier=@parentIdentifier", systemDataCommandBuilder => systemDataCommandBuilder.AddFoodGroupParentIdentifierParameter(foodGroupIdentifier));
                return(subDataProvider.GetCollection <FoodGroupProxy>(command));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the bindings which bind a given household to all the household members who has membership.
        /// </summary>
        /// <param name="dataProvider">Implementation of the data provider used to access data.</param>
        /// <param name="householdProxy">Data proxy for the household on which to get the bindings.</param>
        /// <returns>Bindings which bind a given household to all the household members who has membership.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dataProvider"/> or <paramref name="householdProxy"/> is null.</exception>
        internal static IEnumerable <MemberOfHouseholdProxy> GetMemberOfHouseholds(IDataProviderBase <MySqlDataReader, MySqlCommand> dataProvider, IHouseholdProxy householdProxy)
        {
            ArgumentNullGuard.NotNull(dataProvider, nameof(dataProvider))
            .NotNull(householdProxy, nameof(householdProxy));

            if (householdProxy.Identifier.HasValue == false)
            {
                throw new IntranetRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, householdProxy.Identifier, "Identifier"));
            }

            using (IFoodWasteDataProvider subDataProvider = (IFoodWasteDataProvider)dataProvider.Clone())
            {
                MySqlCommand command = BuildHouseholdDataCommandForSelecting("WHERE moh.HouseholdIdentifier=@householdIdentifier", householdDataCommandBuilder => householdDataCommandBuilder.AddHouseholdIdentifierParameter(householdProxy.Identifier.Value));
                return(subDataProvider.GetCollection <MemberOfHouseholdProxy>(command));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets foreign keys for a domain object in the food waste domain.
        /// </summary>
        /// <param name="dataProvider">Implementation of the data provider used to access data.</param>
        /// <param name="foreignKeyForIdentifier">Identifier for the given domain object on which to get the foreign keys.</param>
        /// <returns>Foreign keys for a domain object in the food waste domain.</returns>
        internal static IEnumerable <ForeignKeyProxy> GetDomainObjectForeignKeys(IDataProviderBase <MySqlDataReader, MySqlCommand> dataProvider, Guid foreignKeyForIdentifier)
        {
            ArgumentNullGuard.NotNull(dataProvider, nameof(dataProvider));

            HashSet <ForeignKeyProxy> cache = DataProxyCache.GetCachedDataProxyCollection <ForeignKeyProxy>(CacheName);

            if (cache.Any(foreignKeyProxy => foreignKeyProxy.ForeignKeyForIdentifier == foreignKeyForIdentifier))
            {
                return(cache.Where(foreignKeyProxy => foreignKeyProxy.ForeignKeyForIdentifier == foreignKeyForIdentifier).ToList());
            }

            using (IFoodWasteDataProvider subDataProvider = (IFoodWasteDataProvider)dataProvider.Clone())
            {
                List <ForeignKeyProxy> result = new List <ForeignKeyProxy>(subDataProvider.GetCollection <ForeignKeyProxy>(BuildSystemDataCommandForSelecting("WHERE fk.ForeignKeyForIdentifier=@foreignKeyForIdentifier", systemDataCommandBuilder => systemDataCommandBuilder.AddForeignKeyForIdentifierParameter(foreignKeyForIdentifier))));
                DataProxyCache.AddDataProxyCollectionToCache(CacheName, result, foreignKeyProxy => foreignKeyProxy.ForeignKeyForIdentifier == foreignKeyForIdentifier);
                return(result);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the translations for a given translatable domain object in the food waste domain.
        /// </summary>
        /// <param name="dataProvider">Implementation of the data provider used to access data.</param>
        /// <param name="translationOfIdentifier">Identifier for the given domain object on which to get the translations.</param>
        /// <returns>Translations for a given translatable domain object in the food waste domain.</returns>
        internal static IEnumerable <TranslationProxy> GetDomainObjectTranslations(IDataProviderBase <MySqlDataReader, MySqlCommand> dataProvider, Guid translationOfIdentifier)
        {
            ArgumentNullGuard.NotNull(dataProvider, nameof(dataProvider));

            HashSet <TranslationProxy> cache = DataProxyCache.GetCachedDataProxyCollection <TranslationProxy>(CacheName);

            if (cache.Any(translationProxy => translationProxy.TranslationOfIdentifier == translationOfIdentifier))
            {
                return(cache.Where(translationProxy => translationProxy.TranslationOfIdentifier == translationOfIdentifier).ToList());
            }

            using (IFoodWasteDataProvider subDataProvider = (IFoodWasteDataProvider)dataProvider.Clone())
            {
                List <TranslationProxy> result = new List <TranslationProxy>(subDataProvider.GetCollection <TranslationProxy>(BuildSystemDataCommandForSelecting("WHERE t.OfIdentifier=@ofIdentifier ORDER BY ti.CultureName", systemDataCommandBuilder => systemDataCommandBuilder.AddTranslationOfIdentifierParameter(translationOfIdentifier))));
                DataProxyCache.AddDataProxyCollectionToCache(CacheName, result, translationProxy => translationProxy.TranslationOfIdentifier == translationOfIdentifier);
                return(result);
            }
        }