Beispiel #1
0
        /// <summary>
        /// Gets a food item by a given data providers foreign key.
        /// </summary>
        /// <param name="dataProvider">Data provider.</param>
        /// <param name="foreignKeyValue">Foreign key value.</param>
        /// <returns>Food item.</returns>
        public virtual IFoodItem FoodItemGetByForeignKey(IDataProvider dataProvider, string foreignKeyValue)
        {
            ArgumentNullGuard.NotNull(dataProvider, nameof(dataProvider))
            .NotNullOrWhiteSpace(foreignKeyValue, nameof(foreignKeyValue));

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

                MySqlCommand command = FoodItemProxy.BuildSystemDataCommandForSelecting(
                    "INNER JOIN ForeignKeys AS fk ON fk.ForeignKeyForIdentifier=fi.FoodItemIdentifier WHERE fk.DataProviderIdentifier=@dataProviderIdentifier AND fk.ForeignKeyForTypes LIKE @foreignKeyForTypes AND fk.ForeignKeyValue=@foreignKeyValue",
                    systemCommandBuilder => systemCommandBuilder
                    .AddDataProviderIdentifierParameter(dataProvider.Identifier)
                    .AddForeignKeyForTypesLikeParameter(typeof(IFoodItem))
                    .AddForeignKeyValueParameter(foreignKeyValue));
                return(DataProvider.GetCollection <FoodItemProxy>(command).FirstOrDefault());
            }
            catch (IntranetRepositoryException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new IntranetRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, MethodBase.GetCurrentMethod().Name, ex.Message), ex);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Gets all the food items.
 /// </summary>
 /// <returns>All food items.</returns>
 public virtual IEnumerable <IFoodItem> FoodItemGetAll()
 {
     try
     {
         MySqlCommand command = FoodItemProxy.BuildSystemDataCommandForSelecting();
         return(DataProvider.GetCollection <FoodItemProxy>(command));
     }
     catch (IntranetRepositoryException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new IntranetRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, MethodBase.GetCurrentMethod().Name, ex.Message), ex);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Gets all the food items which belongs to a given food group.
        /// </summary>
        /// <param name="foodGroup">Food group which the food items should belong to.</param>
        /// <returns>All food items which belongs to the given food group.</returns>
        public virtual IEnumerable <IFoodItem> FoodItemGetAllForFoodGroup(IFoodGroup foodGroup)
        {
            ArgumentNullGuard.NotNull(foodGroup, nameof(foodGroup));

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

                MySqlCommand command = FoodItemProxy.BuildSystemDataCommandForSelecting("INNER JOIN FoodItemGroups AS fig ON fig.FoodItemIdentifier=fi.FoodItemIdentifier WHERE fig.FoodGroupIdentifier=@foodGroupIdentifier", systemCommandBuilder => systemCommandBuilder.AddFoodGroupIdentifierParameter(foodGroup.Identifier));
                return(DataProvider.GetCollection <FoodItemProxy>(command));
            }
            catch (IntranetRepositoryException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new IntranetRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, MethodBase.GetCurrentMethod().Name, ex.Message), ex);
            }
        }