コード例 #1
0
        public async Task <ActionResult> Comment(CommentAdminViewModel commentViewModel)
        {
            var comment = _commentMapper.ToComment(commentViewModel);
            await _commentProvider.ChangeCommentAsync(comment);

            return(RedirectToAction("listComments", "Home"));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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(""));
        }
コード例 #4
0
        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"));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
 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));
 }
コード例 #7
0
        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));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        public ActionResult Comments_Destroy([DataSourceRequest]DataSourceRequest request, CommentAdminViewModel comment)
        {
            this.commentsService.Delete(comment.Id);

            return this.Json(new[] { comment }.ToDataSourceResult(request, this.ModelState));
        }
コード例 #10
0
 public Comment ToComment(CommentAdminViewModel commentViewModel)
 {
     return(_mapper.Map <CommentAdminViewModel, Comment>(commentViewModel));
 }