public ActionResult DeleteComment(int id) { var a = new RecipeComment { Id = id, UpdatedById = CurrentUser.UserInfo.Id }; var feedback = _commentRepository.DeleteRecipeComment(a); return Json(feedback); }
public ActionResult SaveComments(RecipeComment comments) { if (!ModelState.IsValid) { // The form is not valid --> return same form to the user return(PartialView("_NewComments", comments)); } // 1. Save Recipe if (comments.Id == 0) { _context.Comments.Add(comments); } else { return(HttpNotFound()); } _context.SaveChanges(); comments = new RecipeComment(); return(PartialView("_NewComments", comments)); }
public async Task Get_Comment() { //Arrange var recipe = await AddRecipe(); var comment = new RecipeComment { Comment = "foarte gustoasa", IdRecipe = recipe.Id, IdUser = AuthenticatedUserId, Review = 5 }; recipe.RecipeComment.Add(comment); await ExecuteDatabaseAction(async (tastyBoutiqueContext) => { await tastyBoutiqueContext.AddAsync(comment); await tastyBoutiqueContext.SaveChangesAsync(); }); //Act var response = await HttpClient.GetAsync($"api/v1/recipe/{recipe.Id}/comments"); //Assert response.IsSuccessStatusCode.Should().BeTrue(); var recipes = await response.Content.ReadAsAsync <IList <RecipeCommentModel> >(); recipe.Should().NotBeNull(); recipe.Should().NotBeNull(); recipes.Count.Should().Be(1); }
public ActionResult AddComment(CommentAddViewModel commentAddViewModel) { if (!commentAddViewModel.Validate().IsValid) { return(this.Issue404()); } // Normalize the Line Breaks commentAddViewModel.CommentText = commentAddViewModel.CommentText.Replace("\n", Environment.NewLine); switch (commentAddViewModel.CommentType) { case CommentType.Recipe: RecipeComment recipeComment; using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork()) { recipeComment = new RecipeComment(); recipeComment.CommentText = commentAddViewModel.CommentText; recipeComment.RecipeId = commentAddViewModel.GenericId; this.RecipeService.AddRecipeComment(recipeComment); unitOfWork.Commit(); } // Queue Comment Notification this.NotificationService.QueueNotification(NotificationType.RecipeComment, recipeComment); break; case CommentType.Session: BrewSessionComment brewSessionComment; using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork()) { brewSessionComment = new BrewSessionComment(); brewSessionComment.CommentText = commentAddViewModel.CommentText; brewSessionComment.BrewSessionId = commentAddViewModel.GenericId; this.RecipeService.AddBrewSessionComment(brewSessionComment); unitOfWork.Commit(); } // Queue Comment Notification this.NotificationService.QueueNotification(NotificationType.BrewSessionComment, brewSessionComment); break; default: return(this.Issue404()); } var commentViewModel = new CommentViewModel(); commentViewModel.CommentText = commentAddViewModel.CommentText; commentViewModel.UserId = this.ActiveUser.UserId; commentViewModel.UserName = this.ActiveUser.Username; commentViewModel.UserAvatarUrl = UserAvatar.GetAvatar(59, this.ActiveUser.EmailAddress); commentViewModel.DateCreated = DateTime.Now; return(View("_Comment", commentViewModel)); }
public static RecipeCommentModel ConvertToRecipeCommentModel(RecipeComment recipeComment) { return(new RecipeCommentModel { Comment = recipeComment.Comment, DateCreated = recipeComment.DateCreated, Username = recipeComment.User.Username }); }
public void Add(string comment, int recipeId, int userId) { var recipeComment = new RecipeComment(); recipeComment.Comment = comment; recipeComment.RecipeId = recipeId; recipeComment.UserId = userId; recipeComment.DateCreated = DateTime.Now; RecipeCommentsRepository.Add(recipeComment); }
public ActionResult NewComments(int RecipeId, int ParentArticleId) { RecipeComment comments = new RecipeComment(); comments.Email = "*****@*****.**";//Membership.GetUser().UserName; comments.CreateDate = DateTime.Today; comments.ModifiedDate = DateTime.Today; comments.ParentArticleId = ParentArticleId; comments.RecipeId = RecipeId; return(PartialView("_NewComments", comments)); }
/// <summary> /// Adds a new RecipeComment /// </summary> public void AddRecipeComment(RecipeComment recipeComment) { if (recipeComment == null) { throw new ArgumentNullException("recipeComment"); } recipeComment.UserId = this.UserResolver.Resolve().UserId; recipeComment.DateCreated = DateTime.Now; recipeComment.IsActive = true; this.Repository.Add(recipeComment); }
public IActionResult SendComment(string recipeId, string userId, string comment) { if (comment != null && comment.Length > 0) { var user = userManager.Users.Where(x => x.Id == userId).FirstOrDefault(); RecipeComment recipeComment = new RecipeComment() { CommentText = comment, ReceipeId = int.Parse(recipeId), UserId = userId, UploadedOrModified = DateTime.Now }; dbContext.RecipeComment.Add(recipeComment); dbContext.SaveChanges(); } return(Ok()); }
public async Task <int> SubmitCommentAsync(CommentDTOin comment) { bool recipeExists = await recipeRepo.All().AnyAsync(x => x.Id == comment.RecipeId && !x.IsDeleted); if (!recipeExists) { throw new ArgumentOutOfRangeException("Recipe not found!"); } RecipeComment new_comment = mapper.Map <RecipeComment>(comment); await this.commentRepo.AddAssync(new_comment); await this.commentRepo.SaveChangesAsync(); return(new_comment.Id); }
public ActionResult Comment(RecipeComment pc) { var vm = new ListRecipeCommentViewModel { Comments = new List<RecipeComment>(), CurrentUserId = CurrentUser.UserInfo.Id }; if (ModelState.IsValid) { pc.PostedById = CurrentUser.UserInfo.Id; // Call Repository to perform insert var feedback = _commentRepository.InsertRecipeComment(pc); if (feedback.Success) { vm.Comments.Add(feedback.Data); return View(vm); } } return View(vm); }
public IActionResult DeleteRecipe(string id) { var el = dbContext.Recipe.Where(x => x.RecipeId == int.Parse(id)).FirstOrDefault(); if (el != null) { var todel = dbContext.ImageAndRecipeConnection.Where(x => x.RecipeId == el.RecipeId); var todel2 = dbContext.RecipeAndCategoryConnectionTable.Where(x => x.RecipeId == el.RecipeId); var todel3 = dbContext.RecipeComment.Where(x => x.ReceipeId == el.RecipeId); var todel4 = dbContext.RecipeRating.Where(x => x.ReceipeId == el.RecipeId); var todel5 = dbContext.UserAndRecipeAddedToFavouriteConnectionTable.Where(x => x.RecipeId == el.RecipeId); foreach (var item in todel) { ImageAndRecipeConnection m = item; dbContext.ImageAndRecipeConnection.Remove(m); } foreach (var item in todel2) { RecipeAndCategoryConnectionTable m = item; dbContext.RecipeAndCategoryConnectionTable.Remove(m); } foreach (var item in todel3) { RecipeComment m = item; dbContext.RecipeComment.Remove(m); } foreach (var item in todel4) { RecipeRating m = item; dbContext.RecipeRating.Remove(m); } foreach (var item in todel5) { UserAndRecipeAddedToFavouriteConnectionTable m = item; dbContext.UserAndRecipeAddedToFavouriteConnectionTable.Remove(m); } dbContext.Recipe.Remove(el); dbContext.SaveChanges(); } return(RedirectToAction("Browse")); }
public async Task Post_Comment() { //Arrange var recipe = await AddRecipe(); var comment = new CreateRecipeCommentModel() { Comment = "foarte gustoasa", IdUser = AuthenticatedUserId, Review = 5, }; //Act var response = await HttpClient.PostAsJsonAsync($"api/v1/recipe/{recipe.Id}/comments", comment); //Assert response.IsSuccessStatusCode.Should().BeTrue(); var body = await response.Content.ReadAsStringAsync(); var commentId = Extract_Guid(body); RecipeComment existingComment = null; await ExecuteDatabaseAction(async (tastyBoutiqueContext) => { existingComment = await tastyBoutiqueContext.RecipeComments .FirstOrDefaultAsync(c => c.Id == commentId); }); existingComment.Should().NotBeNull(); existingComment.IdRecipe.Should().Be(recipe.Id); await ExecuteDatabaseAction(async (tastyBoutiqueContext) => { recipe = await tastyBoutiqueContext.Recipes .FirstOrDefaultAsync(r => r.Id == recipe.Id); }); recipe.ReviewCount.Should().Be(1); recipe.AverageReview.Should().Be(comment.Review); }
public async Task Delete_Comment() { //Arrange var recipe = await AddRecipe(); var comment = new RecipeComment { Comment = "foarte gustoasa", IdRecipe = recipe.Id, IdUser = AuthenticatedUserId, Review = 5 }; recipe.RecipeComment.Add(comment); await ExecuteDatabaseAction(async (tastyBoutiqueContext) => { await tastyBoutiqueContext.AddAsync(comment); await tastyBoutiqueContext.SaveChangesAsync(); }); //Act var response = await HttpClient.DeleteAsync($"api/v1/recipe/comments/{comment.Id}"); var content = response.Content.ReadAsStringAsync(); //Assert response.IsSuccessStatusCode.Should().BeTrue(); RecipeComment existingComment = null; await ExecuteDatabaseAction(async (tastyBoutiqueContext) => { existingComment = await tastyBoutiqueContext.RecipeComments .FirstOrDefaultAsync(c => c.Id == comment.Id); }); existingComment.Should().BeNull(); }
public void Add(RecipeComment recipeComment) { context.RecipeComments.Add(recipeComment); context.SaveChanges(); }
public void Add(RecipeComment comment) { Context.RecipeComments.Add(comment); Context.SaveChanges(); }
public IActionResult AddRecipieComment([FromBody] RecipeComment recipeComment) { var response = _RecipeService.AddComment(recipeComment).Result; return(new OkObjectResult(response)); }
public async Task <RecipeComment> AddComment(RecipeComment comment) { return(await _recipeCommentRepository.AddAsync(comment)); }