示例#1
0
 public JsonResult AddComment(AddComments comment)
 {
     if (comment.NewsId <= 0)
     {
         return(Json(new ResponseModel {
             code = 0, result = "新闻不存在"
         }));
     }
     if (string.IsNullOrEmpty(comment.Contents))
     {
         return(Json(new ResponseModel {
             code = 0, result = "新闻不存在"
         }));
     }
     return(Json(_commentService.AddComments(comment)));
 }
示例#2
0
        public async Task <IActionResult> Details(Guid id, TicketDetailsBindingModel input, string task)
        {
            var ticket = _ticketService.GetTicket(id);

            if (ticket == null)
            {
                return(View("Error404"));
            }

            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                var viewModel = _ticketService.DetailsTicketViewModel(ticket, allErrors);
                return(View(viewModel));
            }

            if (task == "create")
            {
                if (input.NewCommentThreadContent != null)
                {
                    await _commentService.AddCommentThread(ticket, input, HttpContext);
                }
                if (input.NewComments != null)
                {
                    await _commentService.AddComments(input, HttpContext);
                }
            }
            else
            {
                if (input.EditCommentThreads != null)
                {
                    _commentService.EditCommentThread(input);
                }

                if (input.EditComments != null)
                {
                    _commentService.EditComments(input);
                }
            }

            ticket.UpdatedDate = DateTime.Now;
            _context.SaveChanges(true);

            return(RedirectToAction("Details", new { id }));
        }