public IList<Recipe> List()
        {
            var options = new ReadRecipeOptions
            {
                ReturnCommentCount = this.WithCommentCount,
                ReturnCookbookStatus = this.WithCookbookStatus,
                ReturnMethod = this.WithMethod,
                ReturnPermalink = this.WithPermalink,
                ReturnUserRating = this.WithUserRating
            };

            return this.context.ReadRecipes(this.recipesToLoad.Select(r => r.Id).ToArray(), options);
        }
Exemple #2
0
 public Recipe[] ReadRecipes(Guid[] recipeIds, ReadRecipeOptions options)
 {
     throw new NotImplementedException();
 }
 public Recipe[] ReadRecipes(Guid[] recipeIds, ReadRecipeOptions options)
 {
     this.RRCalledTimes++;
     this.options = options;
     return new Recipe[0];
 }
 /// <summary>
 /// Reads full information for one or more recipes in the database.
 /// </summary>
 /// <param name="recipeIds">An array containing recipe IDs to load.</param>
 /// <param name="options">Indicates which properties to load.  Use ReadRecipeOptions.None to only load base recipe data.</param>
 /// <returns></returns>
 public virtual Recipe[] ReadRecipes(Guid[] recipeIds, ReadRecipeOptions options)
 {
     return this.Adapter.ReadRecipes(this.Identity, recipeIds, options);
 }
Exemple #5
0
        public Recipe[] ReadRecipes(AuthIdentity identity, Guid[] recipeIds, ReadRecipeOptions options)
        {
            using (var session = GetSession())
             {
            var dbRecipes = session.QueryOver<Models.Recipes>()
               .Fetch(prop => prop.RecipeMetadata).Eager
               .Fetch(prop => prop.Ingredients).Eager
               .Fetch(prop => prop.Ingredients[0].Ingredient).Eager
               .Fetch(prop => prop.Ingredients[0].IngredientForm).Eager
               .AndRestrictionOn(p => p.RecipeId).IsInG(recipeIds)
               .TransformUsing(Transformers.DistinctRootEntity)
               .List();

            if (!dbRecipes.Any())
               throw new RecipeNotFoundException();

            var ret = new List<Recipe>();
            foreach (var dbRecipe in dbRecipes)
            {
               var recipe = new Recipe
               {
                  Id = dbRecipe.RecipeId,
                  Title = dbRecipe.Title,
                  Description = dbRecipe.Description,
                  DateEntered = dbRecipe.DateEntered,
                  ImageUrl = dbRecipe.ImageUrl,
                  ServingSize = dbRecipe.ServingSize,
                  PrepTime = dbRecipe.PrepTime,
                  CookTime = dbRecipe.CookTime,
                  Credit = dbRecipe.Credit,
                  CreditUrl = dbRecipe.CreditUrl,
                  AvgRating = dbRecipe.Rating
               };

               if (options.ReturnMethod)
                  recipe.Method = dbRecipe.Steps;

               if (options.ReturnUserRating) // TODO: We should JOIN this on the dbRecipes for faster loading
               {
                  var id = dbRecipe.RecipeId;
                  var rating = session.QueryOver<RecipeRatings>()
                     .Where(p => p.Recipe.RecipeId == id)
                     .Where(p => p.UserId == identity.UserId)
                     .SingleOrDefault();

                  recipe.UserRating = (rating == null ? Rating.None : (Rating) rating.Rating);
               }

               recipe.Ingredients = dbRecipe.Ingredients.Select(i => new IngredientUsage
               {
                  Amount = i.Qty.HasValue ? new Amount(i.Qty.Value, i.Unit) : null,
                  PrepNote = i.PrepNote,
                  Section = i.Section,
                  Form = i.IngredientForm != null ? i.IngredientForm.AsIngredientForm() : null, // Note: Form will be null when usage has no amount
                  Ingredient = i.Ingredient.AsIngredient()
               }).ToArray();

               recipe.Tags = dbRecipe.RecipeMetadata.Tags;
               ret.Add(recipe);
            }

            return ret.ToArray();
             }
        }
        /// <summary>
        /// Reads full information for one or more recipes in the database.
        /// </summary>
        /// <param name="recipeIds">An array containing recipe IDs to load.</param>
        /// <param name="options">Indicates which properties to load.  Use ReadRecipeOptions.None to only load base recipe data.</param>
        /// <returns></returns>
        public Recipe[] ReadRecipes(Guid[] recipeIds, ReadRecipeOptions options)
        {
            var recipes = store.Recipes.Where(r => recipeIds.Contains(r.RecipeId)).ToList();

             if (!recipes.Any())
            throw new RecipeNotFoundException();

             var riIndex = store.GetIndexedRecipeIngredients();
             var ingIndex = store.GetIndexedIngredients();
             var formIndex = store.GetIndexedIngredientForms();
             var rmetaIndex = store.GetIndexedRecipeMetadata();
             var imetaIndex = store.GetIndexedIngredientMetadata();

             var ret = new List<Recipe>();
             foreach (var r in recipes)
             {
            var recipe = new Recipe
            {
               Id = r.RecipeId,
               Title = r.Title,
               Description = r.Description,
               DateEntered = r.DateEntered,
               ImageUrl = r.ImageUrl,
               ServingSize = r.ServingSize,
               PrepTime = r.PrepTime,
               CookTime = r.CookTime,
               Credit = r.Credit,
               CreditUrl = r.CreditUrl,
               AvgRating = r.Rating
            };

            if (options.ReturnMethod)
               recipe.Method = r.Steps;

            if (options.ReturnUserRating)
            {
               var userRating = store.RecipeRatings.SingleOrDefault(ur => (ur.RecipeId == r.RecipeId && ur.UserId == Identity.UserId));
               recipe.UserRating = userRating != null ? (Rating) userRating.Rating : Rating.None;
            }

            recipe.Ingredients = riIndex[r.RecipeId].Select(i => new IngredientUsage
            {
               Amount = i.Qty.HasValue ? new Amount(i.Qty.Value, i.Unit) : null,
               PrepNote = i.PrepNote,
               Section = i.Section,
               Form = i.IngredientFormId.HasValue ? IngredientForms.ToIngredientForm(formIndex[i.IngredientFormId.Value]) : null,
               Ingredient = Data.DTO.Ingredients.ToIngredient(ingIndex[i.IngredientId], imetaIndex[i.IngredientId])
            }).ToArray();

            recipe.Tags = RecipeMetadata.ToRecipeTags(rmetaIndex[r.RecipeId]);
            ret.Add(recipe);
             }

             return ret.ToArray();
        }