コード例 #1
0
        public ActionResult Save(RecipeWithReview recipeWithReview)
        {
            if (!ModelState.IsValid)
            {
                //return Content("");
            }
            var id = RecipesController.tempModel.recipe.ID;

            // recipeWithReview.review.ReviewId = recipeWithReview.recipe.ID;

            recipeWithReview.review.SetId(id);
            recipeWithReview.review.PublishDate = DateTime.Now;
            recipeWithReview.review.SetEmail(User.Identity.Name);
            _context.Reviews.Add(recipeWithReview.review);
            _context.SaveChanges();


            var model = new RecipeWithReview {
                recipe = _context.Recipes.SingleOrDefault(r => r.ID == id), reviews = _context.Reviews.Where(r => r.RecipeId == id).ToList(), types = _context.RecipesTypes.ToList()
            };


            // return RedirectToAction("List", "Recipes");
            //return Content("Pomyślne logowanie");
            return(RedirectToAction("Details",
                                    "Recipes", new { id = id }));
            // RedirectToAction("actionName", "controllerName", new {/* routeValues, for example: */ id = 5 });
        }
コード例 #2
0
        public ActionResult Details(int id)
        {
            var recipe      = _context.Recipes.SingleOrDefault(c => c.ID == id);
            var recipeTypes = _context.RecipesTypes.ToList();
            var reviews     = _context.Reviews.Where(r => r.RecipeId == id).ToList();

            var model = new RecipeWithReview {
                recipe = recipe, reviews = reviews, types = recipeTypes
            };

            if (recipe == null)
            {
                return(HttpNotFound());
            }

            tempModel = model;
            return(View(model));
        }
コード例 #3
0
        public ActionResult Random()
        {
            //var recipe1 = new Recipe() {RecipeId=1, Title = "Burger", Description = "Podgrzej go napatelni a pozniej pomieszaj"};
            //var User = new User();
            //var randomRecipeViewModel = new RandomRecipeViewModel(){ recipe=recipe1, users=new List<User>() };

            var random      = rnd.Next(0, _context.Recipes.Count());
            var recipe      = _context.Recipes.ToList().ElementAt(random);
            var recipeTypes = _context.RecipesTypes.ToList();
            var reviews     = _context.Reviews.Where(r => r.RecipeId == recipe.ID).ToList();

            var model = new RecipeWithReview {
                recipe = recipe, reviews = reviews, types = recipeTypes
            };

            tempModel = model;
            return(View("Details", model));
        }