public async Task <TicketLog> CloseTicket(TicketModel ticket, string comment, int?statusId)
        {
            //Update ticket in the database
            if (statusId == null)
            {
                statusId = (int)TicketStatusId.ClosedByUser;
            }

            var prevStatus = _ticketRepository.GetTicketStatusName(ticket.Id);

            _ticketRepository.SetTicketStatus(ticket.Id, (TicketStatusId)statusId);

            var ticketStatus = _ticketStatusRepository.GetClosedTicketStatuses().FirstOrDefault(ts => ts.Id == statusId.Value);

            var ticketById = _ticketRepository.GetTicketById(ticket.Id);

            ticketById.PrevStatus = prevStatus;
            ticketById.NewStatus  = ticketStatus.Name;
            ticket.PrevAssignee   = ticket.NewAssignee;
            _ticketRepository.UpdateBasic(ticketById);

            var user = GetCurrentUser();
            //Add record to the TicketsLog table
            var log = _ticketLogRepository.Insert(ticket.Id, (int)LogEntryTypeId.StatusChanged, "Ticket status changed to: Closed", $"Ticket status changed to: Closed by {user.Name}. Reason: {ticketStatus.Name}. Comment: {comment}", user.Id);

            _ticketRepository.UpdateTicketDate(ticket.Id);

            //Find and Complile email template (replace all %field% with values
            var emailTemplates = _emailTemplateRepository.GetEmailTemplatesByAction(EmailActionId.StatusChanged);

            var substitutions = _ticketFieldRepository.GetTicketFieldsSubstitutions(ticket.Id, GetTicketUrl(ticket.Id), string.Empty, HttpUtility.HtmlDecode(comment));

            await SendEmails(ticket.Id, emailTemplates, substitutions);

            return(log);
        }
Ejemplo n.º 2
0
        public JsonResult ClosedTicketStatuses()
        {
            var list = _ticketStatusRepository.GetClosedTicketStatuses();

            return(Json(list, JsonRequestBehavior.AllowGet));
        }