public async Task <ActionResult> AddComment(CreateCommentsViewModel model) { IArticleManager articleManager = new ArticleManager(); var userId = Guid.Parse(Session["userId"].ToString()); await articleManager.CreateComment(model.Id, userId, model.Comment); return(Json(new { result = "OK" })); }
public async Task <IActionResult> Create(CreateCommentsViewModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } model.UserId = this.userManager.GetUserId(this.User); await this.service.CreateCommentAsync(model); return(this.RedirectToAction("Details", "Products", new { id = model.ProductId })); }
public async Task CreateCommentAsync(CreateCommentsViewModel model) { var comment = new Comment { Content = model.Content, ProductId = model.ProductId, UserId = model.UserId, }; await this.repository.AddAsync(comment); await this.repository.SaveChangesAsync(); }
// GET: Comment/AddComment/ActivityId public ActionResult AddComment(int id) { if (id <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var model = new CreateCommentsViewModel { ActivityId = id }; return(View(model)); }
public async Task CreateCommentTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var repository = new EfDeletableEntityRepository <Comment>(dbContext); var service = new CommentsService(repository); var createCommentViewModel = new CreateCommentsViewModel { Content = "ssss", ProductId = 1, UserId = Guid.NewGuid().ToString(), }; await service.CreateCommentAsync(createCommentViewModel); Assert.Equal(1, service.GetCommentsCount()); }
public async Task <ActionResult> AddComment(CreateCommentsViewModel model) { if (ModelState.IsValid) { string userId = User.Identity.Name;//.GetUserId(); var activity = await db.Activities.FindAsync(model.ActivityId); var newComment = new Comment() { Description = model.Description, // CommentOwner = await db.Users.FirstAsync(u => u.Id == userId), CreationDate = DateTime.Now }; activity.Comments.Add(newComment); db.SaveChanges(); } return(RedirectToAction("Details", new { id = model.ActivityId })); }