Ejemplo n.º 1
0
        public ActionResult RecipesAddPost(IEnumerable <HttpPostedFileBase> UserFiles)
        {
            ViewBag.menu = "recipes";
            using (LifitDBContext dc = new LifitDBContext())
            {
                var name = Request.Form["name"];
                var text = Request.Form["text"];

                var recip = new Recip()
                {
                    Name = name,
                    Text = text
                };

                if (UserFiles != null)
                {
                    if (UserFiles != null && UserFiles.First().ContentLength > 0)
                    {
                        var file  = UserFiles.First();
                        var fname = file.FileName;
                        file.SaveAs(Server.MapPath("~/files/picture/" + fname));
                        recip.PictureUrl = "/files/picture/" + fname;
                    }
                }
                dc.Recipes.Add(recip);
                dc.SaveChanges();
                var model = dc.Recipes.ToList();
                return(View("RecipesList", model));
            }
        }
Ejemplo n.º 2
0
        public ActionResult RecipDetail(int id)
        {
            ViewBag.menu = "recipes";
            using (LifitDBContext dc = new LifitDBContext())
            {
                var model = dc.Recipes.Where(r => r.RecipId == id).SingleOrDefault();
                model.Visits++;
                dc.SaveChanges();

                return(View("ReceipDetail", model));
            }
        }