Beispiel #1
0
        public ActionResult Index()
        {
            List <RecipeWhole> scrollBarList = new List <RecipeWhole>();
            List <RecipeWhole> indexList     = new List <RecipeWhole>();
            IndexRecs          newInd        = new IndexRecs();

            if (db.RecipieDB.Count() > 6)
            {
                List <Recipie> tmpRe = db.RecipieDB.SqlQuery("SELECT TOP 6 * FROM Recipies").ToList();
                foreach (Recipie rec in tmpRe)
                {
                    RecipeWhole tmpWhole = new RecipeWhole();
                    tmpWhole.CombRecipe = rec;
                    tmpWhole.CombImage  = db.ImageDB.Where(x => x.Id == rec.ImageID).FirstOrDefault();
                    scrollBarList.Add(tmpWhole);
                }
            }
            else
            {
                List <Recipie> tmpRe = db.RecipieDB.SqlQuery("SELECT * FROM Recipies").ToList();
                foreach (Recipie rec in tmpRe)
                {
                    RecipeWhole tmpWhole = new RecipeWhole();
                    tmpWhole.CombRecipe = rec;
                    tmpWhole.CombImage  = db.ImageDB.Where(x => x.Id == rec.ImageID).FirstOrDefault();
                    scrollBarList.Add(tmpWhole);
                }
            }

            if (db.RecipieDB.Count() > 6)
            {
                List <Recipie> tmpRe = db.RecipieDB.OrderByDescending(x => x.DateSubmitted).Take(5).ToList();
                foreach (Recipie rec in tmpRe)
                {
                    RecipeWhole tmpWhole = new RecipeWhole();
                    tmpWhole.CombRecipe = rec;
                    tmpWhole.CombImage  = db.ImageDB.Where(x => x.Id == rec.ImageID).FirstOrDefault();
                    indexList.Add(tmpWhole);
                }
            }
            else
            {
                List <Recipie> tmpRe = db.RecipieDB.OrderByDescending(x => x.DateSubmitted).ToList();
                foreach (Recipie rec in tmpRe)
                {
                    RecipeWhole tmpWhole = new RecipeWhole();
                    tmpWhole.CombRecipe = rec;
                    tmpWhole.CombImage  = db.ImageDB.Where(x => x.Id == rec.ImageID).FirstOrDefault();
                    indexList.Add(tmpWhole);
                }
            }

            newInd.ListForIndexScrollBar = scrollBarList;
            newInd.MostRecentRecs        = indexList;

            return(View(newInd));
        }
Beispiel #2
0
        public ActionResult ViewSingleRecipie(int id = -1)
        {
            if (id == -1 || db.RecipieDB.Where <Recipie>(x => x.Id == id).FirstOrDefault() == null)
            {
                id = db.RecipieDB.FirstOrDefault().Id;
            }
            RecipeWhole rec = new RecipeWhole();

            rec.CombRecipe = db.RecipieDB.Where <Recipie>(x => x.Id == id).Single();
            if (rec.CombRecipe.ImageID != 0)
            {
                rec.CombImage = db.ImageDB.Where <Bits_and_Bites.Models.Image>(x => x.Id == rec.CombRecipe.ImageID).Single();
            }
            return(View(rec));
        }
Beispiel #3
0
        public ActionResult UserLike(int id = 1)
        {
            List <Recipie> recList  = new List <Recipie>();
            List <Recipie> newList  = new List <Recipie>();
            List <Like>    likeList = new List <Like>();
            string         y        = User.Identity.GetUserId();

            //Returns a list of likes that the user has chosen.
            likeList = db.LikeDB.Where <Like>(x => x.UserId == y).ToList();

            foreach (Like lk in likeList)
            {
                recList.Add(db.RecipieDB.Where(x => x.Id == lk.RecipeId).Single());
            }
            //this should find the total number of pages, using the decimal to keep decimals until after rounding.
            int totalPages = (int)Math.Ceiling(((decimal)recList.Count) / (decimal)(12));


            //Checks to see if the id is a valid number
            if (id < 1)
            {
                id = 1;
            }

            //Checks to see if the id is within number of archive pages.
            else if (id > totalPages)
            {
                //TODO should add an error page for out of range ids
                id = totalPages;
            }

            //this should return the beginning record of a page.
            int counter = ((id - 1) * 12);

            if (recList.Count > 12)
            {
                for (int i = 0; i < 12; i++)
                {
                    newList.Add(recList[counter]);
                    counter++;
                }
            }
            else
            {
                for (int i = 0; i < recList.Count; i++)
                {
                    newList.Add(recList[counter]);
                    counter++;
                }
            }
            List <Bits_and_Bites.Models.Image> imList = new List <Bits_and_Bites.Models.Image>();
            List <RecipeWhole> wholeRec = new List <RecipeWhole>();

            foreach (Recipie i in newList)
            {
                Bits_and_Bites.Models.Image result = db.ImageDB.SingleOrDefault(tempIm => tempIm.Id == i.ImageID);
                imList.Add(result);
            }

            for (int i = 0; i < newList.Count; i++)
            {
                RecipeWhole x = new RecipeWhole
                {
                    CombRecipe = newList[i],
                    CombImage  = imList[i]
                };
                var     temp = User.Identity.GetUserId();
                Recipie tr   = db.RecipieDB.Where(m => m.Id == id).SingleOrDefault();
                Like    tl   = db.LikeDB.Where(m => m.RecipeId == id && m.UserId == temp).SingleOrDefault();
                wholeRec.Add(x);
            }

            ViewBag.Total    = totalPages;
            ViewBag.ThisPage = id;
            return(View(wholeRec));
        }
Beispiel #4
0
        public ActionResult ViewAllRecipes(int id = 1)
        {
            List <Recipie> recList = new List <Recipie>();
            List <Recipie> newList = new List <Recipie>();

            recList = db.RecipieDB.ToList();
            //this should find the total number of pages, using the decimal to keep decimals until after rounding.
            int totalPages = (int)Math.Ceiling(((decimal)recList.Count) / (decimal)(12));


            //Checks to see if the id is a valid number
            if (id < 1)
            {
                id = 1;
            }

            //Checks to see if the id is within number of archive pages.
            else if (id > totalPages)
            {
                //TODO should add an error page for out of range ids
                id = totalPages;
            }

            //this should return the beginning record of a page.
            int counter = ((id - 1) * 12);

            if (recList.Count > 12)
            {
                for (int i = 0; i < 12; i++)
                {
                    newList.Add(recList[counter]);
                    counter++;
                }
            }
            else
            {
                for (int i = 0; i < recList.Count; i++)
                {
                    newList.Add(recList[counter]);
                    counter++;
                }
            }
            List <Bits_and_Bites.Models.Image> imList = new List <Bits_and_Bites.Models.Image>();
            List <RecipeWhole> wholeRec = new List <RecipeWhole>();

            foreach (Recipie i in newList)
            {
                Bits_and_Bites.Models.Image result = db.ImageDB.SingleOrDefault(tempIm => tempIm.Id == i.ImageID);
                imList.Add(result);
            }

            for (int i = 0; i < newList.Count; i++)
            {
                RecipeWhole x = new RecipeWhole
                {
                    CombRecipe = newList[i],
                    CombImage  = imList[i]
                };
                wholeRec.Add(x);
            }

            ViewBag.Total    = totalPages;
            ViewBag.ThisPage = id;

            return(View(wholeRec));
        }