Ejemplo n.º 1
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
            }));
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(long id)
        {
            Recipe recipe = db.Recipes.Find(id);

            db.Recipes.Remove(recipe);
            db.SaveChanges();
            return(RedirectToAction("SortView"));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
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 }));
        }