public JsonResult Edit(VMComment model) { JsonResult result = new JsonResult(); if (model==null) { result.Data = new {message = "No data?"}; return result; } Comment comment = this.serviceComment.GetById(model.Id); if (!this.serviceSecurity.HasRight(SecureActivity.CommentEdit, CurrentUser, comment)) { result.Data = new { message = "No, I don't want to :)" }; return result; } comment.Body = model.Body; bool bflag = this.serviceComment.Edit(comment); result.Data = new { data = bflag }; return result; }
public JsonResult Create(int fileId, string body) { Comment newComment = new Comment(); newComment.Body = body; newComment.Creator = CurrentUser; newComment.CreatedOn = DateTime.Now; newComment.FileId = fileId; newComment = serviceComment.Create(newComment); var model = new VMComment() { Body = newComment.Body, CreatedOn = newComment.CreatedOn, Creator = newComment.Creator, CreatorName = newComment.CreatorName, DeleteUrl = Url.Action("Delete",new {id = newComment.Id}), Id = newComment.Id }; var result = new JsonResult() { Data = model, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return result; }
public JsonResult GetComments(int id = 1) { var comments = serviceFile.GetFileComments(id); List<VMComment> model = new List<VMComment>(); foreach (var comment in comments) {//todo : use automapper VMComment vm = new VMComment() { Body = comment.Body, CreatedOn = comment.CreatedOn, ModifiedOn = comment.ModifiedOn, CreatorName = comment.CreatorName, Creator = comment.Creator, Id = comment.Id, DeleteUrl = (comment.Creator.Id == CurrentUser.Id ? Url.Action("Delete", "Comment", new { id = comment.Id }) : null) }; model.Add(vm); } var result = new JsonResult() { Data = model, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return result; }