Ejemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Recipe = await _context.Recipe
                     .Include(c => c.RecipeIngredients)
                     .ThenInclude(c => c.RecipeIngredientName)
                     .Include(c => c.RecipeIngredients)
                     .ThenInclude(c => c.Unit)
                     .Include(c => c.Instruction)
                     .Include(c => c.Course)
                     .Include(c => c.Cuisine)

                     .FirstOrDefaultAsync(m => m.Id == id)
            ;

            //makes Insturction list in order, had to change from ilist to ienumerable, should read up on those.
            Recipe.Instruction = Recipe.Instruction.OrderBy(c => c.Order);


            if (Recipe == null)
            {
                return(NotFound());
            }


            return(Page());
        }
Ejemplo n.º 2
0
        public void Import(IEnumerable <Data.DTO.Recipes> data)
        {
            using (var transaction = session.BeginTransaction())
            {
                var d = data.ToArray();
                foreach (var row in d)
                {
                    var dbRow = new Models.Recipes
                    {
                        RecipeId    = row.RecipeId,
                        CookTime    = row.CookTime,
                        Steps       = row.Steps,
                        PrepTime    = row.PrepTime,
                        Rating      = row.Rating,
                        Description = row.Description,
                        Title       = row.Title,
                        Hidden      = row.Hidden,
                        Credit      = row.Credit,
                        CreditUrl   = row.CreditUrl,
                        DateEntered = row.DateEntered,
                        ServingSize = row.ServingSize,
                        ImageUrl    = row.ImageUrl,
                        Ingredients = new List <Models.RecipeIngredients>()
                    };

                    session.Save(dbRow, row.RecipeId);
                }

                Log.DebugFormat("Created {0} row(s) in Recipes", d.Count());
                transaction.Commit();
                session.Flush();
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Recipe = await _context.Recipe.FirstOrDefaultAsync(m => m.Id == id);

            if (Recipe == null)
            {
                return(NotFound());
            }
            return(Page());
        }
 public ActionResult Edit(Models.Recipes recipe, HttpPostedFileBase image1)
 {
     if (ModelState.IsValid)
     {
         recipe.recipe_date = DateTime.Now;
         if (image1 != null)
         {
             recipe.picture = new byte[image1.ContentLength];
             image1.InputStream.Read(recipe.picture, 0, image1.ContentLength);
         }
         db.Entry(recipe).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("YourRecView"));
     }
     return(View("YourRecView"));
 }
Ejemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Recipe = await _context.Recipe.FindAsync(id);

            if (Recipe != null)
            {
                _context.Recipe.Remove(Recipe);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Recipe = await _context.Recipe
                     .Include(c => c.RecipeIngredients)
                     .ThenInclude(c => c.RecipeIngredientName)
                     .FirstOrDefaultAsync(m => m.Id == id)
            ;

            if (Recipe == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public ActionResult AddRecView(Models.Recipes recipe, HttpPostedFileBase image1)
        {
            if (ModelState.IsValid)
            {
                recipe.user_ID     = User.Identity.GetUserId();
                recipe.recipe_date = DateTime.Now;
                if (image1 != null)
                {
                    recipe.picture = new byte[image1.ContentLength];
                    image1.InputStream.Read(recipe.picture, 0, image1.ContentLength);
                }
                else
                {
                    recipe.picture = Encoding.ASCII.GetBytes("0000");
                }
                db.Recipes.Add(recipe);
                db.SaveChanges();
            }

            return(RedirectToAction("RecipesView", "Home"));
        }
        public void Import(IEnumerable<Recipes> data)
        {
            using (var transaction = this.session.BeginTransaction())
            {
                var recipes = data.ToArray();
                foreach (var recipe in recipes)
                {
                    var databaseRecipe = new Models.Recipes
                                       {
                                           RecipeId = recipe.RecipeId,
                                           CookTime = recipe.CookTime,
                                           Steps = recipe.Steps,
                                           PrepTime = recipe.PrepTime,
                                           Rating = recipe.Rating,
                                           Description = recipe.Description,
                                           Title = recipe.Title,
                                           Hidden = recipe.Hidden,
                                           Credit = recipe.Credit,
                                           CreditUrl = recipe.CreditUrl,
                                           DateEntered = recipe.DateEntered,
                                           ServingSize = recipe.ServingSize,
                                           ImageUrl = recipe.ImageUrl,
                                           Ingredients = new List<Models.RecipeIngredients>()
                                       };

                    this.session.Save(databaseRecipe, recipe.RecipeId);
                }

                this.Log.DebugFormat("Created {0} row(s) in Recipes", recipes.Count());
                transaction.Commit();
                this.session.Flush();
            }
        }
Ejemplo n.º 9
0
        public SearchResults Search(AuthIdentity identity, RecipeQuery query)
        {
            using (var session = adapter.GetSession())
            {
                Models.Recipes recipe = null;

                var q = session.QueryOver <Models.Recipes>(() => recipe)
                        .Where(p => !p.Hidden);

                if (!String.IsNullOrWhiteSpace(query.Keywords)) // Add keyword search
                {
                    q = q.Where(
                        Expression.Or(
                            Expression.InsensitiveLike("Title", String.Format("%{0}%", query.Keywords.Trim())),
                            Expression.InsensitiveLike("Description", String.Format("%{0}%", query.Keywords.Trim()))
                            ));
                }

                if (query.Time.MaxPrep.HasValue)
                {
                    q = q.Where(p => p.PrepTime <= query.Time.MaxPrep.Value);
                }

                if (query.Time.MaxCook.HasValue)
                {
                    q = q.Where(p => p.CookTime <= query.Time.MaxCook.Value);
                }

                if (query.Rating > 0)
                {
                    q = q.Where(p => p.Rating >= (int)query.Rating.Value);
                }

                if (query.Include != null && query.Include.Length > 0) // Add ingredients to include
                {
                    // Create a sub-query for ingredients to include
                    q = q.WithSubquery
                        .WhereExists(QueryOver.Of <RecipeIngredients>()
                                     .Where(item => item.Recipe.RecipeId == recipe.RecipeId)
                                     .Where(Restrictions.InG("Ingredient", query.Include.Select(Models.Ingredients.FromId).ToArray()))
                                     .Select(i => i.RecipeIngredientId).Take(1));
                }

                if (query.Exclude != null && query.Exclude.Length > 0) // Add ingredients to exclude
                {
                    // Create a sub-query for ingredients to exclude
                    q = q.WithSubquery
                        .WhereNotExists(QueryOver.Of <RecipeIngredients>()
                                        .Where(item => item.Recipe.RecipeId == recipe.RecipeId)
                                        .Where(Restrictions.InG("Ingredient", query.Exclude.Select(Models.Ingredients.FromId).ToArray()))
                                        .Select(i => i.RecipeIngredientId).Take(1));
                }

                if (query.Photos == RecipeQuery.PhotoFilter.Photo || query.Photos == RecipeQuery.PhotoFilter.HighRes)
                {
                    q = q.Where(Restrictions.IsNotNull("ImageUrl"));
                }

                if (query.Diet || query.Nutrition || query.Skill || query.Taste || (query.Meal != MealFilter.All) || (query.Photos == RecipeQuery.PhotoFilter.HighRes)) //Need to search in metadata
                {
                    RecipeMetadata metadata = null;
                    q = q.JoinAlias(r => r.RecipeMetadata, () => metadata);

                    //Meal
                    if (query.Meal != MealFilter.All)
                    {
                        if (query.Meal == MealFilter.Breakfast)
                        {
                            q = q.Where(() => metadata.MealBreakfast);
                        }
                        if (query.Meal == MealFilter.Dessert)
                        {
                            q = q.Where(() => metadata.MealDessert);
                        }
                        if (query.Meal == MealFilter.Dinner)
                        {
                            q = q.Where(() => metadata.MealDinner);
                        }
                        if (query.Meal == MealFilter.Lunch)
                        {
                            q = q.Where(() => metadata.MealLunch);
                        }
                    }

                    //High-res photos
                    if (query.Photos == RecipeQuery.PhotoFilter.HighRes)
                    {
                        q = q.Where(() => metadata.PhotoRes >= 1024 * 768);
                    }

                    //Diet
                    if (query.Diet.GlutenFree)
                    {
                        q = q.Where(() => metadata.DietGlutenFree);
                    }
                    if (query.Diet.NoAnimals)
                    {
                        q = q.Where(() => metadata.DietNoAnimals);
                    }
                    if (query.Diet.NoMeat)
                    {
                        q = q.Where(() => metadata.DietNomeat);
                    }
                    if (query.Diet.NoPork)
                    {
                        q = q.Where(() => metadata.DietNoPork);
                    }
                    if (query.Diet.NoRedMeat)
                    {
                        q = q.Where(() => metadata.DietNoRedMeat);
                    }

                    //Nutrition
                    if (query.Nutrition.LowCalorie)
                    {
                        q = q.Where(() => metadata.NutritionLowCalorie);
                    }
                    if (query.Nutrition.LowCarb)
                    {
                        q = q.Where(() => metadata.NutritionLowCarb);
                    }
                    if (query.Nutrition.LowFat)
                    {
                        q = q.Where(() => metadata.NutritionLowFat);
                    }
                    if (query.Nutrition.LowSodium)
                    {
                        q = q.Where(() => metadata.NutritionLowSodium);
                    }
                    if (query.Nutrition.LowSugar)
                    {
                        q = q.Where(() => metadata.NutritionLowSugar);
                    }

                    //Skill
                    if (query.Skill.Common)
                    {
                        q = q.Where(() => metadata.SkillCommon).OrderBy(() => metadata.Commonality).Desc();
                    }
                    if (query.Skill.Easy)
                    {
                        q = q.Where(() => metadata.SkillEasy);
                    }
                    if (query.Skill.Quick)
                    {
                        q = q.Where(() => metadata.SkillQuick);
                    }

                    //Taste
                    if (query.Taste.MildToSpicy != RecipeQuery.SpicinessLevel.Medium)
                    {
                        q = query.Taste.MildToSpicy < RecipeQuery.SpicinessLevel.Medium
                     ? q.Where(() => metadata.TasteMildToSpicy <= query.Taste.Spiciness).OrderBy(() => metadata.TasteMildToSpicy).Asc()
                     : q.Where(() => metadata.TasteMildToSpicy >= query.Taste.Spiciness).OrderBy(() => metadata.TasteMildToSpicy).Desc();
                    }

                    if (query.Taste.SavoryToSweet != RecipeQuery.SweetnessLevel.Medium)
                    {
                        q = query.Taste.SavoryToSweet < RecipeQuery.SweetnessLevel.Medium
                     ? q.Where(() => metadata.TasteSavoryToSweet <= query.Taste.Sweetness).OrderBy(() => metadata.TasteSavoryToSweet).Asc()
                     : q.Where(() => metadata.TasteSavoryToSweet >= query.Taste.Sweetness).OrderBy(() => metadata.TasteSavoryToSweet).Desc();
                    }
                }

                IQueryOverOrderBuilder <Models.Recipes, Models.Recipes> orderBy;
                switch (query.Sort)
                {
                case RecipeQuery.SortOrder.Title:
                    orderBy = q.OrderBy(p => p.Title);
                    break;

                case RecipeQuery.SortOrder.PrepTime:
                    orderBy = q.OrderBy(p => p.PrepTime);
                    break;

                case RecipeQuery.SortOrder.CookTime:
                    orderBy = q.OrderBy(p => p.CookTime);
                    break;

                case RecipeQuery.SortOrder.Image:
                    orderBy = q.OrderBy(p => p.ImageUrl);
                    break;

                default:
                    orderBy = q.OrderBy(p => p.Rating);
                    break;
                }

                var results = (query.Direction == RecipeQuery.SortDirection.Descending ? orderBy.Desc() : orderBy.Asc())
                              .Skip(query.Offset)
                              .Take(100)
                              .List();

                return(new SearchResults
                {
                    Briefs = results.Select(r => r.AsRecipeBrief()).ToArray(),
                    TotalCount = results.Count // TODO: This needs to be the total matches, not the returned matches
                });
            }
        }
Ejemplo n.º 10
0
        public void Import(IEnumerable<Data.DTO.Recipes> data)
        {
            using (var transaction = session.BeginTransaction())
             {
            var d = data.ToArray();
            foreach (var row in d)
            {
               var dbRow = new Models.Recipes
               {
                  RecipeId = row.RecipeId,
                  CookTime = row.CookTime,
                  Steps = row.Steps,
                  PrepTime = row.PrepTime,
                  Rating = row.Rating,
                  Description = row.Description,
                  Title = row.Title,
                  Hidden = row.Hidden,
                  Credit = row.Credit,
                  CreditUrl = row.CreditUrl,
                  DateEntered = row.DateEntered,
                  ServingSize = row.ServingSize,
                  ImageUrl = row.ImageUrl,
                  Ingredients = new List<Models.RecipeIngredients>()
               };

               session.Save(dbRow, row.RecipeId);
            }

            Log.DebugFormat("Created {0} row(s) in Recipes", d.Count());
            transaction.Commit();
            session.Flush();
             }
        }