Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ReviewID,Name,Rating,ReviewText,RecipeID,ReviewDate")] RecipeReview recipeReview)
        {
            if (id != recipeReview.ReviewID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(recipeReview);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RecipeReviewExists(recipeReview.ReviewID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipeReview));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            RecipeReview recipeReview = db.RecipeReview.Find(id);

            db.RecipeReview.Remove(recipeReview);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public async void TestReviewGetByRecipeEager()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test11DB")
                          .Options;

            //Act
            List <RecipeReview> testResultsRecipeReviews;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testUser = new User
                {
                    Username = "******",
                    Password = "******",
                    Email    = "*****@*****.**"
                };

                var testRecipe = new Recipe
                {
                    RecipeCookTime = 5
                };

                var testReview = new RecipeReview
                {
                    Recipe = testRecipe,
                    User   = testUser
                };

                var testReview2 = new RecipeReview
                {
                    Recipe = testRecipe,
                    User   = testUser
                };

                await _unitOfWork.RecipeReviews.Add(testReview);

                await _unitOfWork.RecipeReviews.Add(testReview2);

                await _unitOfWork.Complete();

                var tempTestRecipeReviews = await _unitOfWork.RecipeReviews.GetByRecipeEager(1);

                testResultsRecipeReviews = tempTestRecipeReviews.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Equal(1, testResultsRecipeReviews[0].Recipe.Id);
                Assert.Equal(5, testResultsRecipeReviews[0].Recipe.RecipeCookTime);
                Assert.Equal(1, testResultsRecipeReviews[1].Recipe.Id);
                Assert.Equal(5, testResultsRecipeReviews[1].Recipe.RecipeCookTime);
            }
        }
 public ActionResult Edit([Bind(Include = "ID,AverageRating,ReviewID")] RecipeReview recipeReview)
 {
     if (ModelState.IsValid)
     {
         db.Entry(recipeReview).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ReviewID = new SelectList(db.Review, "ID", "Comment", recipeReview.ReviewID);
     return(View(recipeReview));
 }
Exemple #5
0
 public ActionResult Edit([Bind(Include = "Id,Rating,Title,Body,ReviewerName,RecipeId")] RecipeReview recipeReview)
 {
     if (ModelState.IsValid)
     {
         db.Entry(recipeReview).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RecipeId = new SelectList(db.Recipes, "Id", "Name", recipeReview.RecipeId);
     return(View(recipeReview));
 }
Exemple #6
0
        public async Task <IActionResult> Create([Bind("ReviewID,Name,Rating,ReviewText,RecipeID,ReviewDate")] RecipeReview recipeReview)
        {
            if (ModelState.IsValid)
            {
                _context.Add(recipeReview);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipeReview));
        }
        public ActionResult Create([Bind(Include = "ID,AverageRating,review")] RecipeReview recipeReview)
        {
            if (ModelState.IsValid)
            {
                db.RecipeReview.Add(recipeReview);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ReviewID = new SelectList(db.Review, "ID", "Comment", recipeReview.ReviewID);
            return(View(recipeReview));
        }
Exemple #8
0
        public ActionResult Create(RecipeReview recipeReview)
        {
            if (ModelState.IsValid)
            {
                recipeReview.ReviewerName = User.Identity.Name;
                db.RecipeReviews.Add(recipeReview);
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = recipeReview.RecipeId }));
            }

            return(View(recipeReview));
        }
 public ActionResult Edit(RecipeReview review)
 {
     if (ModelState.IsValid)
     {
         _db.Entry(review).State = EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index", new
         {
             id = review.RecipeId
         }));
     }
     return(View(review));
 }
        // GET: RecipeReviews/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RecipeReview recipeReview = db.RecipeReview.Find(id);

            if (recipeReview == null)
            {
                return(HttpNotFound());
            }
            return(View(recipeReview));
        }
Exemple #11
0
        public async void TestReviewGetEager()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test10DB")
                          .Options;

            //Act
            RecipeReview testResultReview;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testUser = new User
                {
                    Username = "******",
                    Password = "******",
                    Email    = "*****@*****.**"
                };

                var testRecipe = new Recipe
                {
                    RecipeCookTime    = 5,
                    RecipeInstruction = "Do the thing"
                };

                var testReview = new RecipeReview
                {
                    Recipe = testRecipe,
                    User   = testUser
                };

                //await _unitOfWork.Recipes.Add(testRecipe);
                await _unitOfWork.RecipeReviews.Add(testReview);

                await _unitOfWork.Complete();

                var tempTestReview = await _unitOfWork.RecipeReviews.GetEager(1);

                testResultReview = tempTestReview;
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Equal(5, testResultReview.Recipe.RecipeCookTime);
            }
        }
        // GET: RecipeReviews/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RecipeReview recipeReview = db.RecipeReview.Find(id);

            if (recipeReview == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ReviewID = new SelectList(db.Review, "ID", "Comment", recipeReview.ReviewID);
            return(View(recipeReview));
        }
Exemple #13
0
        public async Task <RecipeReview> convertReviewPost(RecipeReviewVM recipeReview)
        {
            var user = await _unitOfWork.Users.Get(recipeReview.UserId);

            var recipe = await _unitOfWork.Recipes.GetEager(recipeReview.RecipeId);

            var edittedReview = new RecipeReview()
            {
                User                = user,
                Recipe              = recipe,
                RecipeReviewRating  = recipeReview.RecipeReviewRating,
                RecipeReviewComment = recipeReview.RecipeReviewComment
            };

            return(edittedReview);
        }
Exemple #14
0
        public async Task <RecipeReview> functionForReview(RecipeReviewVM recipeReview)
        {
            var user = await _unitOfWork.Users.Get(recipeReview.UserId);

            var recipe = await _unitOfWork.Recipes.Get(recipeReview.RecipeId);

            var edittedReview = new RecipeReview()
            {
                User                = user,
                Recipe              = recipe,
                Id                  = recipeReview.RecipeReviewId.Value,
                RecipeReviewRating  = recipeReview.RecipeReviewRating,
                RecipeReviewComment = recipeReview.RecipeReviewComment
            };

            return(edittedReview);
        }
Exemple #15
0
        public async void TestReviewDelete()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test9DB")
                          .Options;

            //Act
            List <RecipeReview> reviewElements;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testReview = new RecipeReview
                {
                };

                await _unitOfWork.RecipeReviews.Add(testReview);

                await _unitOfWork.Complete();

                await _unitOfWork.RecipeReviews.Delete(1);

                await _unitOfWork.Complete();

                var tempTestReviews = await _unitOfWork.RecipeReviews.GetAll();

                reviewElements = tempTestReviews.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Empty(reviewElements);
            }
        }