Esempio n. 1
0
        public IQueryable <Recipe> SortRecipes(string sortOrder, RecipeDataContext dbContextTemp)
        {
            var recipestemp = from s in dbContextTemp.Recipes
                              select s;

            switch (sortOrder)
            {
            case "Name":
                recipestemp = recipestemp.OrderByDescending(s => s.Title);
                break;

            case "Date":
                recipestemp = recipestemp.OrderBy(s => s.TimeStamp);
                break;

            case "CookingTime":
                recipestemp = recipestemp.OrderByDescending(s => s.CookingTime);
                break;

            default:      // Name ascending
                recipestemp = recipestemp.OrderBy(s => s.FinalRate);
                break;
            }
            return(recipestemp);
        }
Esempio n. 2
0
        public ActionResult Search()
        {
            var initgroupsize = 6;

            var groupnumberlist = new SelectList(new[] { "6", "12", "24" });

            ViewBag.GroupNumberList = groupnumberlist;

            var searchlist = new SelectList(new[] { "Title", "Food Rate", "people number" });

            ViewBag.SearchList = searchlist;
            var       db          = new RecipeDataContext();
            SearchCal searchCal   = new SearchCal(db);
            var       groupnumber = searchCal.SearchGropNumber(initgroupsize);
            //  IQueryable<Recipe> recipelist = db.Recipes;
            var recipelist1 = new List <Recipe>();

            if (db.Recipes.Count() != 0)
            {
                if (db.Recipes.Count() <= initgroupsize)
                {
                    recipelist1 = db.Recipes.ToList();
                }
                else
                {
                    //  var idtemp = searchCal.IdStartPoint(groupnumber,initgroupsize);

                    //recipelist = recipelist1.Where(a => a.Id > (idtemp));
                    recipelist1 = searchCal.RecipesResultList(1, initgroupsize);
                }
            }
            ViewData["resultlist"]  = recipelist1;
            ViewData["groupnumber"] = groupnumber;
            return(View());
        }
Esempio n. 3
0
        public ActionResult Rate(Rate rate)
        {
            var db         = new RecipeDataContext();
            var i          = rate.ReId;
            var tempRecipe = db.Recipes.Find(rate.ReId);

            if (rate.RateValue > 10 || rate.RateValue < 0)
            {
                ModelState.AddModelError("comm", "out of range");
            }
            else if (tempRecipe == null)
            {
                ModelState.AddModelError("ReId", "not found");
            }
            else
            {
                tempRecipe.Rates.Add(rate);
                tempRecipe.RatingPeople = tempRecipe.RatingPeople + 1;
                tempRecipe.FinalRate    = (double)Math.Round(((tempRecipe.FinalRate * (tempRecipe.RatingPeople - 1) + rate.RateValue) / (tempRecipe.RatingPeople)), 2);

                db.SaveChanges();
            }
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToAction("RecipeDetails", new { id = rate.ReId }));
            }


            return(Json(new
            {
                FRate1 = tempRecipe.FinalRate,
                NNum = tempRecipe.RatingPeople
            }));
        }
Esempio n. 4
0
        public ActionResult Edit(long?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            var db         = new RecipeDataContext();
            var tempRecipe = db.Recipes.Find(id);

            // var tempRecipe = db.Recipes.FirstOrDefault();
            if (tempRecipe == null)
            {
                return(RedirectToAction("Index"));
            }
            var context  = new UsersContext();
            var username = User.Identity.Name;
            var user     = context.UserProfiles.SingleOrDefault(u => u.UserName == username);


            if (user.UserId == tempRecipe.UserId)
            {
                return(RedirectToAction("RecipeDetails", new { id = id }));
            }

            return(View(tempRecipe));
        }
Esempio n. 5
0
        public ActionResult RecipeDetails(long?id)
        {
            Debug.WriteLine(WebSecurity.CurrentUserId);
            var db = new RecipeDataContext();

            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }



            var recipe = db.Recipes.Find(id);



            if (recipe == null)
            {
                return(View(db.Recipes.FirstOrDefault()));
            }
            var context = new UsersContext();
            var user    = context.UserProfiles.SingleOrDefault(u => u.UserId == recipe.UserId);

            ViewBag.userName = user.NickName;
            return(View(recipe));
        }
Esempio n. 6
0
        public IQueryable <Recipe> CookingTimeLess(int x, RecipeDataContext dbContextTemp)
        {
            var cookinglist = (from item in dbContextTemp.Recipes
                               where item.CookingTime <= x
                               select item);

            return(cookinglist);
        }
Esempio n. 7
0
        public ActionResult UploadnewPage(string groupnumber, int groupsize)
        {
            var       db        = new RecipeDataContext();
            SearchCal searchCal = new SearchCal(db);

            var idtemp      = searchCal.IdStartPoint(int.Parse(groupnumber), groupsize);
            var recipelist1 = searchCal.RecipesResultList(idtemp, groupsize);

            return(PartialView("_SearchView", recipelist1));
        }
Esempio n. 8
0
        public ActionResult CalculatePeopleNumber(double newPeopleNumber, int newId, string viewtime)
        {
            var           tempbool   = false;
            var           db         = new RecipeDataContext();
            var           tempRecipe = db.Recipes.Find(newId);
            List <double> newAmount  = new List <double>();

            if (tempRecipe == null)
            {
                ModelState.AddModelError("newId", "not found");
            }
            else
            {
                var correctionRatio = newPeopleNumber / (double)tempRecipe.PeopoleNumber;
                if (tempRecipe.TimeStamp.ToString().Contains(viewtime))
                {
                    tempbool = true;
                }
                else
                {
                    tempbool = false;
                }

                foreach (var item in tempRecipe.Ingredients)
                {
                    if (tempbool)
                    {
                        newAmount.Add((double)Math.Round(double.Parse(item.Amount) * correctionRatio, 2));
                    }
                    else
                    {
                        item.Amount = "" + Math.Round(double.Parse(item.Amount) * correctionRatio, 2);
                    }
                }
            }
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToAction("RecipeDetails", new { id = newId }));
            }
            if (!tempbool)
            {
                var Pview = PartialView("_RecipePart", tempRecipe);
                return(Pview);
            }
            else
            {
                return(Json(new
                {
                    newamountlist = newAmount,
                    //  tempRecipe,
                }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 9
0
        public ActionResult AddComment(Comment comment, long newcommentId)
        {
            var db = new RecipeDataContext();

            var tempRecipe = db.Recipes.Find(newcommentId);

            if (tempRecipe == null)
            {
                ModelState.AddModelError("newcommentId", "not found");
            }
            else
            {
                tempRecipe.Comments.Add(comment);
                db.SaveChanges();
            }
            return(PartialView("CommentPart", comment));
        }
Esempio n. 10
0
        public IQueryable <Recipe> PeopleNumberBoL(int x, bool incOdec, RecipeDataContext dbContextTemp)
        {
            if (incOdec)
            {
                var data = (from item in dbContextTemp.Recipes

                            where item.PeopoleNumber <= x
                            select item);
                return(data);
            }
            else
            {
                var data = (from item in dbContextTemp.Recipes
                            where item.PeopoleNumber >= x
                            select item);
                return(data);
            }
        }
Esempio n. 11
0
        public ActionResult Create(Models.Recipe tempRecipe, HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0 && file.ContentType.StartsWith("image/"))
            {
                try
                {
                    string temppath = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Images/siteimg"), temppath);
                    int    i;
                    file.SaveAs(path);
                    ViewBag.Message    = "File uploaded successfully";
                    tempRecipe.ImgPath = Path.Combine("~/Images/siteimg", temppath);
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            else
            {
                ModelState.AddModelError("file", "You have not specified a file // wrong file type");
            }
            var context  = new UsersContext();
            var username = User.Identity.Name;
            var user     = context.UserProfiles.SingleOrDefault(u => u.UserName == username);

            tempRecipe.UserId       = user.UserId;
            tempRecipe.TimeStamp    = DateTime.Now;
            tempRecipe.FinalRate    = 0;
            tempRecipe.RatingPeople = 0;
            if (ModelState.IsValid)
            {
                var db = new RecipeDataContext();

                db.Recipes.Add(tempRecipe);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(tempRecipe));
        }
Esempio n. 12
0
        public ActionResult Edit(Models.Recipe tempRecipe, HttpPostedFileBase file)
        {
            var db            = new RecipeDataContext();
            var tempRecipeold = db.Recipes.Find(tempRecipe.Id);

            if (file != null && file.ContentLength > 0 && file.ContentType.StartsWith("image/"))
            {
                try
                {
                    string temppath = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Images/siteimg"), temppath);
                    int    i;
                    file.SaveAs(path);
                    ViewBag.Message    = "File uploaded successfully";
                    tempRecipe.ImgPath = Path.Combine("~/Images/siteimg", temppath);
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }


            tempRecipeold.TimeStamp = DateTime.Now;
            for (int i = 0; i < tempRecipe.Ingredients.Count; i++)
            {
                tempRecipeold.Ingredients[i].Name   = tempRecipeold.Ingredients[i].Name;
                tempRecipeold.Ingredients[i].Amount = tempRecipeold.Ingredients[i].Amount;
                tempRecipeold.Ingredients[i].Unit   = tempRecipeold.Ingredients[i].Unit;
            }
            tempRecipeold.Ingredients = tempRecipe.Ingredients;

            tempRecipe.RatingPeople = tempRecipeold.RatingPeople;
            if (ModelState.IsValid)
            {
                db.SaveChanges();
            }
            return(RedirectToAction("RecipeDetails", new { id = tempRecipeold.Id }));
        }
Esempio n. 13
0
        public ActionResult Search(string category, string searchPattern)
        {
            var groupnumberlist = new SelectList(new[] { "6", "12", "24" });

            ViewBag.GroupNumberList = groupnumberlist;
            var searchlist = new SelectList(new[] { "Title", "Food Rate", "people number" });

            ViewBag.SearchList = searchlist;
            if (searchPattern.IsEmpty())
            {
                ModelState.AddModelError("searchPattern", "Shouldn't be empty");
            }
            if (ModelState.IsValid)
            {
                var db = new RecipeDataContext();
                IQueryable <Recipe> results = db.Recipes;

                if (category == "Food Rate")
                {
                    results = results.Where(a => a.FinalRate >= double.Parse(searchPattern));
                }
                else if (category == "People Number")
                {
                    int i = int.Parse(searchPattern);
                    results = results.Where(recipe => recipe.PeopoleNumber == i);
                }
                else
                {
                    results = results.Where(recipe => recipe.Title.Contains(searchPattern));
                }

                //return View("Search", results);
                ViewData["resultlist"] = results;
            }
            return(View());
        }
Esempio n. 14
0
 public List <Recipe> HeighestNCommentsNumber(int x, RecipeDataContext dbContextTemp)
 {
     return(dbContextTemp.Recipes.OrderBy(s => s.Comments.Count).Take(x).ToList());
 }
Esempio n. 15
0
 public StaticInfo(RecipeDataContext dbContext)
 {
     this.dbContext = dbContext;
 }
Esempio n. 16
0
 public SearchCal(RecipeDataContext dbContext)
 {
     this.dbContext = dbContext;
 }