public ActionResult CreateComment(CommentViewModel model) { if (ModelState.IsValid && model.Id != 0) { CommentDataModel commentDataModel = new CommentDataModel(); string user = GetUserDetail(); model.UserName = user.Split('|')[0]; model.UserId = Convert.ToInt32(user.Split('|')[1]); model.EventId = model.Id; model.Date = DateTime.Now; commentDataModel.UserName = model.UserName; commentDataModel.UserId = model.UserId; commentDataModel.Comment = model.Comment; commentDataModel.Date = model.Date; commentDataModel.EventId = model.EventId; CommentService commentService = new CommentService(); var result = commentService.CreateComments(commentDataModel); if (result == null) { ModelState.AddModelError("", "Something went wrong..."); return(View()); } } ModelState.Clear(); return(View()); }
public IHttpActionResult CraateCommentOnArticle(int articleId, CommentDataModel comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var article = this.Data.Articles .All() .FirstOrDefault(a => a.Id == articleId); if (article == null) { return(NotFound()); } var userId = this.User.Identity.GetUserId(); var commentToAdd = new Comment { Content = comment.Content, DateCreated = DateTime.Now, ArticleId = article.Id, AuthorId = userId }; article.Comments.Add(commentToAdd); this.Data.SaveChanges(); comment.Id = commentToAdd.Id; return(Ok(comment)); }
public ActionResult Comment(CommentDataModel model) { _ilog.Info(string.Format("方法名:{0};参数:{1}", "Comment", Serializer.ToJson(model))); var result = new StandardJsonResult(); result.Try(() => { if (!ModelState.IsValid) { throw new KnownException(ModelState.GetFirstError()); } ItemStatus status = (ItemStatus)model.Status; var user = GetSession(); var examine = new Examine() { UserID = user.User.UserID, UserName = user.User.UserName, ExamineStatus = status }; var SN = GetSession(); service.AddCommentItem(model.MessageID, new Comment() { CommentGuid = model.Guid, Content = model.Content, Time = model.Time, UserID = SN.User.UserID, UserName = SN.User.UserName }, examine); }); _ilog.Info(string.Format("方法名:{0};执行结果:{1}", "Comment", Serializer.ToJson(result))); return(result); }
public ActionResult GetComments(CommentViewModel model) { CommentDataModel commentDataModel = new CommentDataModel(); commentDataModel.EventId = model.Id; CommentService commentService = new CommentService(); var result = commentService.GetComments(commentDataModel); List <CommentViewModel> commentModel = null; if (result != null) { commentModel = new List <CommentViewModel>(); foreach (CommentDataModel lcomment in result) { CommentViewModel commentViewModel = new CommentViewModel(); commentViewModel.Date = lcomment.Date; commentViewModel.UserId = lcomment.UserId; commentViewModel.UserName = lcomment.UserName; commentViewModel.Comment = lcomment.Comment; commentModel.Add(commentViewModel); } return(View(commentModel)); } return(View()); }
public IHttpActionResult Add(int feedbackId, CommentDataModel commentModel) { var feedback = this.Data.Feedbacks.Find(feedbackId); if (feedback == null) { return NotFound(); } var comment = new Comment { PostDate = commentModel.PostDate, Text = commentModel.Text, FeedbackId = feedbackId, UserId = User.Identity.GetUserId() }; feedback.Comments.Add(comment); this.Data.SaveChanges(); commentModel.Id = comment.Id; commentModel.FeedbackId = comment.FeedbackId; commentModel.UserId = comment.UserId; commentModel.UserName = comment.User.UserName; return Ok(commentModel); }
public List <CommentDataModel> GetComments(CommentDataModel commentData) { using (var context = new BookReadingEventsDBEntities()) { context.Database.Log = Logger.Log; List <CommentDataModel> listOfComments = null; var commentsEntityList = context.Comments.Where(c => c.EventId == commentData.EventId).ToList(); if (commentsEntityList != null) { listOfComments = new List <CommentDataModel>(); foreach (var comment in commentsEntityList) { CommentDataModel commentDataModel = new CommentDataModel(); commentDataModel.Date = (DateTime)comment.Date; commentDataModel.UserName = comment.UserName; commentDataModel.UserId = comment.UserId; commentDataModel.EventId = comment.EventId; commentDataModel.Comment = comment.Comment1; listOfComments.Add(commentDataModel); } } return(listOfComments); } }
public async Task <IActionResult> New(int id, string CommentText) { if (string.IsNullOrWhiteSpace(CommentText)) { ModelState.AddModelError("", "Text field is required!"); return(RedirectToAction("Details", "Post", new { id })); } PostDataModel postDataModel = this.applicationContext.Posts.FirstOrDefault(c => c.PostId == id); ApplicationUser currentUser = this.applicationContext.Users.FirstOrDefault(u => u.Id == this.User.FindFirstValue(ClaimTypes.NameIdentifier)); if (postDataModel.Archieved == true) { return(RedirectToAction("Details", "Post", new { id })); } CommentDataModel comment = new CommentDataModel { Content = CommentText, UploadDate = DateTime.Now, Author = currentUser, Post = postDataModel }; this.applicationContext.Comments.Add(comment); await this.applicationContext.SaveChangesAsync(); return(RedirectToAction("Details", "Post", new { id })); }
public async Task <IActionResult> DeleteComment(int id) { CommentDataModel commentDataModel = this.applicationDbContext.Comments.FirstOrDefault(c => c.Id == id); if (!(this.User.FindFirstValue(ClaimTypes.NameIdentifier).Equals(commentDataModel.CreatorId) || this.User.IsInRole("Administrator"))) { return(RedirectToAction("NoAccess", "Home")); } BlogPostDataModel blogPostDataModel = this.applicationDbContext.BlogPosts.FirstOrDefault(c => c.Id == commentDataModel.BlogPostId); blogPostDataModel.Comments -= 1; this.applicationDbContext.BlogPosts.Update(blogPostDataModel); this.applicationDbContext.Remove(commentDataModel); await this.applicationDbContext.SaveChangesAsync(); BigViewModel bigViewModel = new BigViewModel(); bigViewModel.BlogPostDataModel = blogPostDataModel; return(RedirectToAction("DetailsBlogPost", "Blog", new { bigViewModel.BlogPostDataModel.Id, bigViewModel })); }
public void AddNewComment(string content, int gameId, int?parentCommentId, string name = "testName") { if (string.IsNullOrEmpty(content) || string.IsNullOrEmpty(name) || _unitOfWork.GameRepository.GetById(gameId) == null) { return; } //check if we can find comment with commentId == parentCommentId if (parentCommentId != null && _unitOfWork.CommentRepository.GetById(parentCommentId) == null) { parentCommentId = null; } //ToDo do it by using Mapper var commentToAdd = new CommentDataModel() { Body = content, CreationDate = DateTime.Now, GameId = gameId, Name = name, ParentCommentId = parentCommentId }; _unitOfWork.CommentRepository.Create(commentToAdd); _unitOfWork.Save(); }
public void Delete(string value) { var dataQuery = new CommentDataModel(); dataQuery.CommentId = int.Parse(value); CommentDataManager.Delete(dataQuery, SessionVariables.RequestProfile); }
public IHttpActionResult Add(int feedbackId, CommentDataModel commentModel) { var feedback = this.Data.Feedbacks.Find(feedbackId); if (feedback == null) { return(NotFound()); } var comment = new Comment { PostDate = commentModel.PostDate, Text = commentModel.Text, FeedbackId = feedbackId, UserId = User.Identity.GetUserId() }; feedback.Comments.Add(comment); this.Data.SaveChanges(); commentModel.Id = comment.Id; commentModel.FeedbackId = comment.FeedbackId; commentModel.UserId = comment.UserId; commentModel.UserName = comment.User.UserName; return(Ok(commentModel)); }
public static string Save(CommentDataModel data, string action, RequestProfile requestProfile) { var sql = "EXEC "; switch (action) { case "Create": sql += "dbo.CommentInsert " + " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId) + ", " + ToSQLParameter(BaseDataModel.BaseDataColumns.ApplicationId, requestProfile.ApplicationId); break; case "Update": sql += "dbo.CommentUpdate " + " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId); break; default: break; } sql = sql + ", " + ToSQLParameter(data, CommentDataModel.DataColumns.CommentId); sql = sql + ", " + ToSQLParameter(data, CommentDataModel.DataColumns.Name); sql = sql + ", " + ToSQLParameter(data, CommentDataModel.DataColumns.Description); sql = sql + ", " + ToSQLParameter(data, CommentDataModel.DataColumns.SortOrder); return(sql); }
public static int Create(CommentDataModel data, RequestProfile requestProfile) { var sql = Save(data, "Create", requestProfile); var newId = DBDML.RunScalarSQL("Comment.Insert", sql, DataStoreKey); return(Convert.ToInt32(newId)); }
public void Create(CommentDataModel commentDataModel) { commentDataModel.Created = DateTime.Now; var newComment = Mapper.Map <CommentDataModel, Comment>(commentDataModel); UnitOfWork.Comments.Create(newComment); UnitOfWork.Save(); }
public Comment(CommentDataModel commentData) { CommentId = commentData.CommentId; CommentComment = commentData.CommentComment; Date = commentData.Date; PhotoId = commentData.PhotoId; CommentByUserId = commentData.CommentByUserId; }
public Comment(CommentDataModel commentDataModel) { CommentId = commentDataModel.CommentId; photoId = commentDataModel.PhotoId; comment = commentDataModel.Comment; CommentDate = commentDataModel.CommentDate; commentedById = commentDataModel.CommentedById; }
public static string ToSQLParameter(CommentDataModel data, string dataColumnName) { var returnValue = "NULL"; switch (dataColumnName) { case CommentDataModel.DataColumns.CommentId: if (data.CommentId != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, CommentDataModel.DataColumns.CommentId, data.CommentId); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CommentDataModel.DataColumns.CommentId); } break; case CommentDataModel.DataColumns.Name: if (!string.IsNullOrEmpty(data.Name)) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, CommentDataModel.DataColumns.Name, data.Name); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CommentDataModel.DataColumns.Name); } break; case CommentDataModel.DataColumns.Description: if (!string.IsNullOrEmpty(data.Description)) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, CommentDataModel.DataColumns.Description, data.Description); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CommentDataModel.DataColumns.Description); } break; case CommentDataModel.DataColumns.SortOrder: if (data.SortOrder != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, CommentDataModel.DataColumns.SortOrder, data.SortOrder); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CommentDataModel.DataColumns.SortOrder); } break; default: returnValue = BaseDataManager.ToSQLParameter(data, dataColumnName); break; } return(returnValue); }
public ActionResult Create(int id) { StudentDataModel currentStudent = SessionCurrentStudent(); var commentDataModel = new CommentDataModel(); commentDataModel.AuthorId = currentStudent.Id; commentDataModel.PostId = id; return(View(commentDataModel)); }
public CommentDataModel GetById(string value) { var dataQuery = new CommentDataModel(); dataQuery.CommentId = int.Parse(value); var result = CommentDataManager.GetEntityDetails(dataQuery, SessionVariables.RequestProfile, 1); return(result[0]); }
public static bool DoesExist(CommentDataModel data, RequestProfile requestProfile) { var doesExistRequest = new CommentDataModel(); doesExistRequest.ApplicationId = data.ApplicationId; doesExistRequest.Name = data.Name; var list = GetEntityDetails(doesExistRequest, requestProfile, 0); return(list.Count > 0); }
public IActionResult Edit(int id) { CommentDataModel comment = AutoInclude.IncludeAll <CommentDataModel>(this.applicationContext.Comments).FirstOrDefault(c => c.CommentId == id); if (!(this.User.FindFirstValue(ClaimTypes.NameIdentifier).Equals(comment.Author.Id) || this.User.IsInRole("Administrator"))) { return(RedirectToAction("NoAccess", "Home")); } return(View(comment)); }
public IActionResult EditComment(int id) { CommentDataModel commentDataModel = this.applicationDbContext.Comments.FirstOrDefault(c => c.Id == id); if (!(this.User.FindFirstValue(ClaimTypes.NameIdentifier).Equals(commentDataModel.CreatorId) || this.User.IsInRole("Administrator"))) { return(RedirectToAction("NoAccess", "Home")); } return(View(new CommentViewModel { Content = commentDataModel.Content })); }
public CommentDataModel Transform() { var datamodel = new CommentDataModel { CommentId = this.CommentId, PhotoId = this.photoId, Comment = this.comment, CommentDate = this.CommentDate, CommentedById = this.commentedById }; return(datamodel); }
public CommentDataModel Transform() { var dataModel = new CommentDataModel { CommentId = this.CommentId, CommentComment = this.CommentComment, Date = this.Date, PhotoId = this.PhotoId, CommentByUserId = this.CommentByUserId }; return(dataModel); }
public async Task <IActionResult> EditComment(int id, CommentViewModel editViewModel) { if (ModelState.IsValid) { CommentDataModel commentDataModel = this.applicationDbContext.Comments.FirstOrDefault(c => c.Id == id); commentDataModel.Content = editViewModel.Content; this.applicationDbContext.Update(commentDataModel); await this.applicationDbContext.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } return(View(editViewModel)); }
public async Task <IActionResult> Delete(int id) { CommentDataModel commentDataModel = AutoInclude.IncludeAll <CommentDataModel>(this.applicationContext.Comments).FirstOrDefault(c => c.CommentId == id); if (!(this.User.FindFirstValue(ClaimTypes.NameIdentifier).Equals(commentDataModel.Author.Id) || this.User.IsInRole("Administrator"))) { return(RedirectToAction("NoAccess", "Home")); } this.applicationContext.Comments.Remove(commentDataModel); await this.applicationContext.SaveChangesAsync(); return(RedirectToAction("Details", "Post", new { id = commentDataModel.Post.PostId })); }
public IHttpActionResult Add(CommentDataModel commentData) { if (commentData == null || commentData.AuthorId == null || string.IsNullOrWhiteSpace(commentData.Content)) { return(this.BadRequest("You must provide comment content and author.")); } var newComment = CommentDataModel.ToComment(commentData); this.data.Comments.Add(newComment); this.data.SaveChanges(); return(this.Ok(newComment.Id)); }
public async Task <IActionResult> Edit(int id, CommentDataModel comment) { if (ModelState.IsValid) { CommentDataModel commentDataModel = AutoInclude.IncludeAll <CommentDataModel>(this.applicationContext.Comments).FirstOrDefault(c => c.CommentId == id); commentDataModel.Content = comment.Content; this.applicationContext.Update(commentDataModel); await this.applicationContext.SaveChangesAsync(); return(RedirectToAction("Details", "Post", new { id = commentDataModel.PostId })); } return(View(comment)); }
public async Task <IActionResult> Edit(Guid id, CommentDataModel comment) { if (ModelState.IsValid) { var targetComment = await this.commentRepository.GetById(id); targetComment.Content = targetComment.Content; await this.commentRepository.Update(targetComment); return(this.RedirectToAsync <PostController>(x => x.Details(comment.PostId.Value))); } return(View(comment)); }
public async Task <IActionResult> Edit(Guid id, CommentDataModel comment) { if (ModelState.IsValid) { var targetComment = await this.commentRepository.GetById(id); targetComment.Content = targetComment.Content; await this.commentRepository.Update(targetComment); return(RedirectToAction("Details", "Post", new { id = comment.PostId })); } return(View(comment)); }
public static void Delete(CommentDataModel data, RequestProfile requestProfile) { const string sql = @"dbo.CommentDelete "; var parameters = new { AuditId = requestProfile.AuditId , CommentId = data.CommentId }; using (var dataAccess = new DataAccessBase(DataStoreKey)) { dataAccess.Connection.Execute(sql, parameters, commandType: CommandType.StoredProcedure); } }
public IHttpActionResult Update(int id, CommentDataModel model) { var comment = this.Data.Comments.Find(id); if (comment == null) { return NotFound(); } comment.PostDate = model.PostDate; comment.Text = model.Text; this.Data.SaveChanges(); model.Id = comment.Id; return Ok(model); }
public IHttpActionResult Create(int postId, CommentDataModel model) { var userID = this.User.Identity.GetUserId(); var comment = new Comment { PostId = postId, UserId = userID, Content = model.Content, CommentDate = DateTime.Now }; this.data.Comments.Add(comment); try { this.data.SaveChanges(); } catch { return this.BadRequest(); } return Ok(model); }
public IHttpActionResult Deletе(int id) { var existingComment = this.Data.Comments .All() .FirstOrDefault(a => a.Id == id); if (existingComment == null) { return BadRequest("Comment does not exists!"); } var model = new CommentDataModel(existingComment); this.Data.Comments.Delete(existingComment); this.Data.SaveChanges(); return Ok(model); }