public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                _logger.LogDebug("Ticket not found");
                return(NotFound());
            }
            var user = await GetCurrentUserAsync();

            var ticket = await _context.Tickets
                         .Include(c => c.Owner)
                         .Include(e => e.Employee)
                         .Include(p => p.Product)
                         .Include(c => c.Comments)
                         .Include(f => f.FileDetails)
                         .Include(s => s.Status)
                         .Include(pr => pr.Priority)
                         .SingleOrDefaultAsync(m => m.TicketId == id);

            var model = new TicketCommentViewModel()
            {
                Ticket = ticket, Comment = new Comment()
            };

            if (ticket == null)
            {
                _logger.LogDebug("Ticket not found");
                return(NotFound());
            }

            return(View(model));
        }
 public IActionResult PostComment([FromBody] TicketCommentViewModel ticketComment)
 {
     _logger.LogInformation($"PostComment Ticket id: {ticketComment.TicketId}, comment: {ticketComment.Comment}");
     if (string.IsNullOrWhiteSpace(ticketComment.Comment))
     {
         return(new AcceptedResult());
     }
     _ticketService.AddComment(ticketComment.TicketId, ticketComment.Comment, User.Identity.Name);
     return(new AcceptedResult());
 }
        public async Task <IActionResult> PatchComment([FromBody] TicketCommentViewModel ticketComment)
        {
            if (!(await _authService.AuthorizeProjectRoleByComment(eProjectRoles.Manager, ticketComment.CommentId)))
            {
                return(RedirectToAction("AccessDenied", "Account"));
            }

            _logger.LogInformation($"PatchComment Comment id: {ticketComment.CommentId}, comment: {ticketComment.Comment}");
            _ticketService.EditComment(ticketComment.CommentId, ticketComment.Comment);
            return(new AcceptedResult());
        }
        public async Task <IActionResult> Details(int id, TicketCommentViewModel model)
        {
            var ticket = await _context.Tickets
                         .SingleOrDefaultAsync(m => m.TicketId == id);

            if (ticket == null)
            {
                return(NotFound());
            }
            var user = await GetCurrentUserAsync();

            var comment = new Comment()
            {
                Content  = model.Comment.Content,
                SendTime = DateTime.Now,
                TicketID = ticket.TicketId,
                Ticket   = ticket,
                UserId   = user.Id,
                User     = user,
            };

            ticket.Comments = new List <Comment>()
            {
                comment
            };
            ticket.UpdateDate = DateTime.Now;

            if (ModelState.IsValid)
            {
                try
                {
                    await _context.Comments.AddAsync(comment);

                    _context.Update(ticket);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TicketExists(ticket.TicketId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Details), new { id = ticket.TicketId.ToString() }));
            }
            return(View(model));
        }
Example #5
0
        /// <summary>
        /// Initial Mapping ticket comment to viewmodel.
        /// </summary>
        /// <param name="ticketComments">The ticket comment.</param>
        /// <returns></returns>
        private IEnumerable <TicketCommentViewModel> InitialTicketCommentViewModel(IEnumerable <TicketComment> ticketComments)
        {
            var result   = new List <TicketCommentViewModel>();
            var customer = _unitOfWork.GetRepository <Customer>().GetCache();

            foreach (var item in ticketComments)
            {
                var temp        = customer.FirstOrDefault(x => x.Email == item.CommentBy);
                var commentItem = new TicketCommentViewModel
                {
                    Id            = item.Id,
                    TicketId      = item.TicketId.Value,
                    Comment       = item.Comment,
                    CommentBy     = item.CommentBy,
                    CommentByName = string.Format(ConstantValue.EmpTemplate, temp?.FirstNameEn, temp?.LastNameEn),
                    CommentDate   = item.CommentDate.Value.ToString("yyyy-MM-dd HH:mm:ss")
                };
                result.Add(commentItem);
            }
            return(result);
        }