public async Task <ActionResult> Comment(CommentAdminViewModel commentViewModel) { var comment = _commentMapper.ToComment(commentViewModel); await _commentProvider.ChangeCommentAsync(comment); return(RedirectToAction("listComments", "Home")); }
public ActionResult Comments_Update([DataSourceRequest]DataSourceRequest request, CommentAdminViewModel comment) { if (ModelState.IsValid) { this.commentsService.Update(comment.Content, comment.IsDeleted, comment.Id); } var commentById = this.commentsService.ById(comment.Id, true); var data = this.Mapper.Map<CommentAdminViewModel>(commentById); return this.Json(new[] { data }.ToDataSourceResult(request, this.ModelState)); }
public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, CommentAdminViewModel model) { var commentToDestroy = this.Data.Comments.All().FirstOrDefault(c => c.Id == model.Id); var results = new List <CategoryAdminViewModel>(); if (commentToDestroy != null && ModelState.IsValid) { this.Data.Comments.Delete(commentToDestroy); this.Data.SaveChanges(); } return(Content("")); }
public ActionResult Edit(CommentAdminViewModel model) { var commentToUpdate = this.Data.Comments.All().FirstOrDefault(c => c.Id == model.Id); if (commentToUpdate == null) { this.Error("No such comment!"); } if (ModelState.IsValid) { commentToUpdate.Content = model.Content; this.Data.SaveChanges(); this.Success("Comment has been removed."); } return(RedirectToAction("List")); }
public async Task <IActionResult> Edit(int id) { ViewBag.HeritageObjects = _manager.HeritageObjectRepository.GetAll(); ViewBag.Users = _userManager.Users.Where(u => true); Comment comment = _manager.CommentRepository.Get(id); if (comment == null) { return(NotFound()); } CommentAdminViewModel model = new CommentAdminViewModel { Id = comment.Id, Text = comment.Text, HeritageObjectId = comment.HeritageObjectId, UserId = comment.UserId }; return(View(model)); }
public async Task <IActionResult> Create(CommentAdminViewModel model) { ViewBag.HeritageObjects = _manager.HeritageObjectRepository.GetAll(); ViewBag.Users = _userManager.Users.Where(u => true); //DateTime time = DateTime.UtcNow; if (ModelState.IsValid) { Comment comment = new Comment { Text = model.Text, Time = DateTime.UtcNow, IsEdited = false, HeritageObjectId = model.HeritageObjectId, HeritageObject = _manager.HeritageObjectRepository.Get(model.HeritageObjectId), UserId = model.UserId, }; _manager.CommentRepository.Save(comment); return(Redirect("/admin/comment")); } return(View(model)); }
public JsonResult Update([DataSourceRequest] DataSourceRequest request, CommentAdminViewModel model) { var commentToUpdate = this.Data.Comments.All().FirstOrDefault(c => c.Id == model.Id); var results = new List <CommentAdminViewModel>(); if (commentToUpdate != null && ModelState.IsValid) { commentToUpdate.Content = model.Content; this.Data.SaveChanges(); results.Add(new CommentAdminViewModel { Id = commentToUpdate.Id, Content = commentToUpdate.Content }); } return(Json(results.ToDataSourceResult(request), JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Edit(CommentAdminViewModel model) { ViewBag.HeritageObjects = _manager.HeritageObjectRepository.GetAll(); ViewBag.Users = _userManager.Users.Where(u => true); if (ModelState.IsValid) { Comment comment = _manager.CommentRepository.Get(model.Id); if (comment != null) { comment.Text = model.Text; comment.Time = DateTime.UtcNow; comment.IsEdited = true; comment.HeritageObjectId = model.HeritageObjectId; comment.HeritageObject = _manager.HeritageObjectRepository.Get(model.HeritageObjectId); comment.UserId = model.UserId; _manager.CommentRepository.Update(comment); await _hubContext.Clients.User(comment.UserId.ToString()).SendAsync("Notify", "Ваш комментарий был изменён"); return(Redirect("/admin/comment/index")); } } return(View(model)); }
public ActionResult Comments_Destroy([DataSourceRequest]DataSourceRequest request, CommentAdminViewModel comment) { this.commentsService.Delete(comment.Id); return this.Json(new[] { comment }.ToDataSourceResult(request, this.ModelState)); }
public Comment ToComment(CommentAdminViewModel commentViewModel) { return(_mapper.Map <CommentAdminViewModel, Comment>(commentViewModel)); }