public async Task <IWriterResult> CreateTicketReply(string userId, CreateSupportReplyModel model)
        {
            using (var context = DataContextFactory.CreateContext())
            {
                var ticket = await context.SupportTicket
                             .Include(t => t.User)
                             .FirstOrDefaultNoLockAsync(x => x.UserId == userId && x.Id == model.TicketId).ConfigureAwait(false);

                if (ticket == null)
                {
                    return(new WriterResult(false, $"Support ticket #{model.TicketId} not found."));
                }

                var reply = new Entity.Support.SupportTicketMessage
                {
                    Message    = model.Message,
                    SenderId   = ticket.UserId,
                    TicketId   = model.TicketId,
                    Created    = DateTime.UtcNow,
                    IsInternal = false,
                    LastUpdate = DateTime.UtcNow
                };
                context.SupportTicketMessage.Add(reply);
                ticket.Status = Enums.SupportTicketStatus.UserReply;
                await context.SaveChangesAsync().ConfigureAwait(false);

                model.Sender    = ticket.User.UserName;
                model.Timestamp = reply.Created.ToString("M/d/yyyy h:mm:ss tt");
                return(new WriterResult(true, $"Successfully added reply to ticket #{ticket.Id}, a Cryptopia staff member will be in touch shortly."));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> CreateReply(CreateSupportReplyModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("CreateReplyModal", model));
            }

            var result = await SupportWriter.CreateTicketReply(User.Identity.GetUserId(), model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View("CreateReplyModal", model));
            }

            return(CloseModal(new
            {
                Success = true,
                Message = result.Message,
                Data = model
            }));
        }