コード例 #1
0
        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));
        }
    }
コード例 #2
0
 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 }));
 }
コード例 #3
0
        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);
        //}
    }
コード例 #4
0
        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"));
        }
コード例 #5
0
        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" }));
        }
コード例 #6
0
        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"));
            }
        }
コード例 #7
0
        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 }));
        }
コード例 #8
0
 public PartialViewResult Comment(CreateCommentVM model)
 {
     return(PartialView("CreateComment", model));
 }