public async Task <TicketLog> AddCustomerReply(int ticketId, string reply) { var user = GetCurrentUser(); //Add record to the TicketsLog table var log = _ticketLogRepository.Insert(ticketId, (int)LogEntryTypeId.ReplyAddedByCustomer, $"Customer replied: {reply}", user.Name + $" replied: {reply}", user.Id); //Change ticket ststus to waiting for staff reply _ticketRepository.SetTicketStatus(ticketId, TicketStatusId.WaitingForStaffReply); _ticketRepository.UpdateTicketDate(ticketId); //Find and Complile email template (replace all %field% with values) var emailTemplates = _emailTemplateRepository.GetEmailTemplatesByAction(EmailActionId.CustomerReplyAdded); var substitutions = _ticketFieldRepository.GetTicketFieldsSubstitutions(ticketId, GetTicketUrl(ticketId), HttpUtility.HtmlDecode(reply)); await SendEmails(ticketId, emailTemplates, substitutions); return(log); }