public async Task <ActionResult <Comment> > PostComment(CreateCommentVM commentVM) { // get registered user ClaimsPrincipal loggedUser = HttpContext.User; string userName = loggedUser.FindFirst(ClaimTypes.Name).Value; User user = _context.Users.Where(u => u.UserName == userName).FirstOrDefault(); // get related ticket Ticket ticket = _context.Tickets.Where(t => t.Id == commentVM.TicketID).FirstOrDefault(); // create new comment Comment comment = new() { CreatedBy = user, CreatedDate = DateTime.Now.AddHours(serverTimeShift), Text = commentVM.Text, Ticket = ticket }; // add comment to database _context.Comments.Add(comment); await _context.SaveChangesAsync(); // return created comment return(CreatedAtAction("GetComment", new { id = comment.Id }, comment)); } }
public ActionResult CreateComment(CreateCommentVM model) { if (ModelState.IsValid) { this.repos.CreateComments(model.ArticleID, this.repos.GetUserId(User.Identity.Name), model.Content, model.Parent); } return(RedirectToAction("Index", "Article", new { id = model.ArticleID })); }
public async Task <ActionResult <Comment> > PostComment(CreateCommentVM commentVM) { // get registered user ClaimsPrincipal loggedUser = HttpContext.User; string userName = loggedUser.FindFirst(ClaimTypes.Name).Value; User user = _context.Users.Where(u => u.UserName == userName).FirstOrDefault(); // get related ticket Ticket ticket = _context.Tickets.Where(t => t.Id == commentVM.TicketID).FirstOrDefault(); // create new comment Comment comment = new() { CreatedBy = user, CreatedDate = DateTime.Now, Text = commentVM.Text, Ticket = ticket }; // add comment to database _context.Comments.Add(comment); await _context.SaveChangesAsync(); // return created comment return(CreatedAtAction("GetComment", new { id = comment.Id }, comment)); } //// DELETE: api/Comments/5 //[HttpDelete("{id}")] //public async Task<IActionResult> DeleteComment(int id) //{ // var comment = await _context.Comments.FindAsync(id); // if (comment == null) // { // return NotFound(); // } // _context.Comments.Remove(comment); // await _context.SaveChangesAsync(); // return NoContent(); //} /// <summary> /// Returns true if comment with send ID exist /// </summary> /// <param name="id">CommentId</param> /// <returns></returns> //private bool CommentExists(int id) //{ // return _context.Comments.Any(e => e.Id == id); //} }
public IActionResult Create(CreateCommentVM model) { if (ModelState.IsValid) { var entity = _mapper.Map <Comment>(model); entity.CreatedDate = DateTimeOffset.Now; _commentRepository.Add(entity); _unitOfWork.Commit(); } return(RedirectToAction("Index")); }
public IActionResult OnPost(CreateCommentVM command, string slug) { command.Type = CommentOwnerType.ProductType; if (!ModelState.IsValid) { return(RedirectToPage("Product", new { id = slug, message = "همه اطلاعات را وارد نمائید!", messageColor = "danger" })); } var result = _commentApplication.CreateComment(command); return(RedirectToPage("Product", new { id = slug, message = "نظر شما با موفقیت ثبت شد!", messageColor = "success" })); }
public ActionResult CreateComment(int id) { TaskRepo repo = new TaskRepo(); Task task = repo.GetById(id); CreateCommentVM create = new CreateCommentVM(); create.TaskId = task.Id; if (task.assignetId == AuthenticationManager.LoggedUser.Id || task.creatorId == AuthenticationManager.LoggedUser.Id) { return(View(create)); } else { return(RedirectToAction("Index", "TaskManagement")); } }
public ActionResult CreateComment(CreateCommentVM create) { if (!this.ModelState.IsValid) { return(View(create)); } CommentRepo commentRepo = new CommentRepo(); Comment newComment = new Comment(); newComment.commentTittle = create.Tittle; newComment.commentContent = create.Content; newComment.Date = DateTime.Now; newComment.commentCreatorId = AuthenticationManager.LoggedUser.Id; newComment.taskId = create.TaskId; commentRepo.Create(newComment); return(RedirectToAction("Details", "TaskManagement", new { id = create.TaskId })); }
public PartialViewResult Comment(CreateCommentVM model) { return(PartialView("CreateComment", model)); }