public void TestDeleteCommentAsync() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfDeletableEntityRepository <Comment>(new ApplicationDbContext(options.Options)); var service = new CommentsServices(repository); var comment = new CommentsInputModel { GameId = 1, Content = "test", UserId = "2", }; service.CreateAsync(comment).GetAwaiter().GetResult(); var firstCounter = repository.All().Count(); service.DeleteCommentAsync("test", "2", 1).GetAwaiter().GetResult(); var secondCounter = repository.All().Count(); Assert.True(firstCounter == 1 && secondCounter == 0); }
public async Task <IActionResult> Create(CommentsInputModel model) { try { var user = await this.userManager.GetUserAsync(this.User); if (user == null) { // Identity/Account/Login return(this.Redirect("/Identity/Account/Login")); } await this.commentService.CreateComment(model.PostId, user.Id, model.Content, model.Title); return(this.RedirectToAction("ById", "Post", new { id = model.PostId })); } catch (Exception ex) { if (ex.Message == "Content must be at least 5 symbols") { this.TempData["error"] = "Content is required"; return(this.RedirectToAction("ById", "Post", new { id = model.PostId })); } else if (ex.Message == "Content must be under 15000 symbols") { this.TempData["error"] = ex.Message; return(this.RedirectToAction("ById", "Post", new { id = model.PostId })); } // To Do send message to my email for example return(this.RedirectToAction("HandleError", "Home")); } }
public async Task <IActionResult> CreateComment(CommentsInputModel input) { if (!this.ModelState.IsValid) { return(this.Redirect("/Games/ById/" + input.GameId)); } await this.commentsServices.CreateAsync(input); return(this.Redirect("/Games/ById/" + input.GameId)); }
public async Task CreateAsync(CommentsInputModel input) { var comment = new Comment { GameId = input.GameId, Content = input.Content, UserId = input.UserId, }; await this.commentsRepository.AddAsync(comment); await this.commentsRepository.SaveChangesAsync(); }
/// <summary> /// Gets comments view /// </summary> /// <returns></returns> public ActionResult Index(CommentsInputModel commentsInputModel) { if (commentsInputModel == null || !commentsInputModel.AllowComments.HasValue || commentsInputModel.AllowComments.Value) { var model = this.Model.GetCommentsListViewModel(commentsInputModel, false); if (model != null) { return(this.View(this.templateNamePrefix + this.TemplateName, model)); } } return(new EmptyResult()); }
/// <summary> /// Gets comments view /// </summary> /// <returns></returns> public ActionResult Index(CommentsInputModel commentsInputModel) { if (commentsInputModel == null || !commentsInputModel.AllowComments.HasValue || commentsInputModel.AllowComments.Value) { var model = this.Model.GetCommentsListViewModel(commentsInputModel, true); this.AddCacheDependencies(this.GetKeysOfDependentObjects()); if (model != null) { return(this.View(this.templateNamePrefix + this.TemplateName, model)); } } return(new EmptyResult()); }
public ActionResult AddComment(CommentsInputModel model) { var user = this.CurrentUser; if (model != null && ModelState.IsValid) { var comment = Mapper.Map<Comment>(model); comment.AuthorId = user.Id; comment = this.comments.AddComment(comment); var viewModel = Mapper.Map<CommentsViewModel>(comment); viewModel.Avatar = user.Avatar; viewModel.Author = user.UserName; return this.PartialView("~/Areas/Private/Views/Comment/_SingleCommentPartial.cshtml", viewModel); } throw new HttpException(400, "Invalid comment"); }
public CommentsModel GetComments(CommentsInputModel commentsInputModel) { return(Post <CommentsModel, CommentsInputModel>("core_comment_get_comments", commentsInputModel)); }