Beispiel #1
0
        public CommentListItemViewModel GetComment(int id)
        {
            var comment = _context.PostComments
                          .Where(b => b.Id == id)
                          .FirstOrDefault();

            var vm = new CommentListItemViewModel
            {
                Id            = comment.Id,
                Title         = comment.Title,
                Content       = comment.Content,
                CommentAuthor = comment.CommentAuthor
            };

            return(vm);
        }
 public ActionResult Tracks_Destroy([DataSourceRequest] DataSourceRequest request, CommentListItemViewModel model)
 {
     this.comments.Delete(model.Id);
     return(this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState)));
 }
        public ActionResult Tracks_Update([DataSourceRequest] DataSourceRequest request, CommentListItemViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var trackEntity = this.comments.GetById(model.Id);
                this.Mapper.Map(model, trackEntity);
                this.comments.Save();
                var responseModel = this.Mapper.Map <CommentListItemViewModel>(trackEntity);
                return(this.Json(new[] { responseModel }.ToDataSourceResult(request, this.ModelState)));
            }

            return(this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState)));
        }
        public ActionResult Tracks_Create([DataSourceRequest] DataSourceRequest request, CommentListItemViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var entity = this.Mapper.Map <Comment>(model);
                this.comments.Add(entity);
                var responseModel = this.Mapper.Map <CommentListItemViewModel>(entity);
                return(this.Json(new[] { responseModel }.ToDataSourceResult(request, this.ModelState)));
            }

            return(this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState)));
        }