Esempio n. 1
0
 public ActionResult AddNewRecipe(RecipeAndPictureModel newRecipe)
 {
     Bits_and_Bites.Models.Image im = new Bits_and_Bites.Models.Image();
     if (newRecipe.CombImage != null)
     {
         im.StoredImage = im.ReturnArray(newRecipe.CombImage);
         im.ContentType = newRecipe.CombImage.ContentType;
         im.ImageName   = newRecipe.CombRecipe.RecipieName;
         im.ImageAlt    = newRecipe.CombRecipe.RecipieName;
         db.ImageDB.Add(im);
         db.SaveChanges();
         newRecipe.CombRecipe.ImageID = im.Id;
     }
     else
     {
         newRecipe.CombRecipe.ImageID = 2;
     }
     newRecipe.CombRecipe.LikeCounter     = 0;
     newRecipe.CombRecipe.SubmittedByID   = User.Identity.GetUserId();
     newRecipe.CombRecipe.DateSubmitted   = DateTime.Parse(DateTime.Today.Date.ToString("MM/dd/yy"));
     newRecipe.CombRecipe.SubmittedByName = User.Identity.GetUserName();
     db.RecipieDB.Add(newRecipe.CombRecipe);
     db.SaveChanges();
     return(RedirectToAction("UserHome", "Home", null));
 }
Esempio n. 2
0
 public ActionResult ReturnPicture(int id = 0)
 {
     Bits_and_Bites.Models.Image im = db.ImageDB.Where(m => m.Id == id).SingleOrDefault();
     return(File(im.StoredImage, im.ContentType));
 }
Esempio n. 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));
        }
Esempio n. 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));
        }