Пример #1
0
        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));
        }
Пример #2
0
 public Recipe[] ReadRecipes(Guid[] recipeIds, ReadRecipeOptions options)
 {
     this.RRCalledTimes++;
     this.options = options;
     return(new Recipe[0]);
 }
Пример #3
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(Adapter.ReadRecipes(Identity, recipeIds, options));
 }
Пример #4
0
 public Recipe[] ReadRecipes(Guid[] recipeIds, ReadRecipeOptions options)
 {
     throw new NotImplementedException();
 }
Пример #5
0
        public Recipe[] ReadRecipes(AuthIdentity identity, Guid[] recipeIds, ReadRecipeOptions options)
        {
            using (var session = this.GetSession())
            {
                var recipes = session.QueryOver<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 (!recipes.Any())
                {
                    throw new RecipeNotFoundException();
                }

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

                    if (options.ReturnMethod)
                    {
                        recipe.Method = recipie.Steps;
                    }

                    if (options.ReturnUserRating)
                    {
                        var id = recipie.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 = recipie.Ingredients.Select(i => new IngredientUsage
                    {
                        Amount = i.Qty.HasValue ? new Amount(i.Qty.Value, i.Unit) : null,
                        PreparationNote = 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 = recipie.RecipeMetadata.Tags;
                    ret.Add(recipe);
                }

                return ret.ToArray();
            }
        }
Пример #6
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());
            }
        }