public IEnumerable <IngredientBinding> LoadIngredientGraph() { using (var session = GetStatelessSession()) { IngredientForms joinForm = null; Models.Ingredients joinIng = null; var recIngs = session.QueryOver <RecipeIngredients>() .JoinAlias(r => r.IngredientForm, () => joinForm) .JoinAlias(r => r.Ingredient, () => joinIng) .Where(p => joinIng.IngredientId != ShoppingList.GUID_WATER) // Ignore any usage for water .Select( p => joinIng.IngredientId, p => p.Recipe.RecipeId, p => p.Qty, p => p.Unit, p => joinIng.ConversionType, p => joinIng.UnitWeight, p => joinForm.UnitType, p => joinForm.FormAmount, p => joinForm.FormUnit) .TransformUsing(IngredientGraphTransformer.Create()) .List <IngredientBinding>(); return(recIngs); } }
public Dictionary <Guid, IngredientForms> GetIndexedIngredientForms() { if (indexedIngredientForms == null) { indexedIngredientForms = IngredientForms.ToDictionary(i => i.IngredientFormId); } return(indexedIngredientForms); }
public RecipeResult CreateRecipe(AuthIdentity identity, Recipe recipe) { using (var session = GetSession()) { using (var transaction = session.BeginTransaction()) { // Create Recipe var dbRecipe = new Models.Recipes { Title = recipe.Title, Description = recipe.Description, CookTime = recipe.CookTime, PrepTime = recipe.PrepTime, Credit = recipe.Credit, CreditUrl = recipe.CreditUrl, DateEntered = recipe.DateEntered, ImageUrl = recipe.ImageUrl, Rating = recipe.AvgRating, ServingSize = recipe.ServingSize, Steps = recipe.Method }; session.Save(dbRecipe); // Create Ingredients short displayOrder = 0; recipe.Ingredients.ForEach(i => { var dbIngredient = new RecipeIngredients { Recipe = dbRecipe, Ingredient = Models.Ingredients.FromId(i.Ingredient.Id), IngredientForm = (i.Form != null ? IngredientForms.FromId(i.Form.FormId) : null), Qty = (i.Amount != null ? (float?)i.Amount.SizeHigh : null), QtyLow = (i.Amount != null ? (float?)i.Amount.SizeLow : null), Unit = (i.Amount != null ? i.Amount.Unit : Units.Unit), Section = i.Section, DisplayOrder = ++displayOrder }; session.Save(dbIngredient); }); // Create RecipeMetadata var dbMetadata = new RecipeMetadata { Recipe = dbRecipe, DietGlutenFree = recipe.Tags.HasTag(RecipeTag.GlutenFree), DietNoAnimals = recipe.Tags.HasTag(RecipeTag.NoAnimals), DietNomeat = recipe.Tags.HasTag(RecipeTag.NoMeat), DietNoPork = recipe.Tags.HasTag(RecipeTag.NoPork), DietNoRedMeat = recipe.Tags.HasTag(RecipeTag.NoRedMeat), MealBreakfast = recipe.Tags.HasTag(RecipeTag.Breakfast), MealDessert = recipe.Tags.HasTag(RecipeTag.Dessert), MealDinner = recipe.Tags.HasTag(RecipeTag.Dinner), MealLunch = recipe.Tags.HasTag(RecipeTag.Lunch), NutritionLowCalorie = recipe.Tags.HasTag(RecipeTag.LowCalorie), NutritionLowCarb = recipe.Tags.HasTag(RecipeTag.LowCarb), NutritionLowFat = recipe.Tags.HasTag(RecipeTag.LowFat), NutritionLowSodium = recipe.Tags.HasTag(RecipeTag.LowSodium), NutritionLowSugar = recipe.Tags.HasTag(RecipeTag.LowSugar), SkillCommon = recipe.Tags.HasTag(RecipeTag.Common), SkillEasy = recipe.Tags.HasTag(RecipeTag.Easy), SkillQuick = recipe.Tags.HasTag(RecipeTag.Quick) }; session.Save(dbMetadata); transaction.Commit(); return(new RecipeResult { RecipeCreated = true, NewRecipeId = dbRecipe.RecipeId }); } } }