Beispiel #1
0
        public async Task <QuickChatReplyViewModel> AddQuickChatReply(ApplicationUser currentUser, string quickReplyText)
        {
            var sanitizedContent = new HtmlSanitizer().Sanitize(quickReplyText);

            var targetReply = await this.db.QuickChatReplies
                              .FirstOrDefaultAsync(x => x.ApplicationUserId == currentUser.Id &&
                                                   x.Reply.Trim().ToUpper() == sanitizedContent.Trim().ToUpper());

            if (targetReply == null)
            {
                targetReply = new QuickChatReply
                {
                    ApplicationUserId = currentUser.Id,
                    Reply             = sanitizedContent,
                    CreatedOn         = DateTime.UtcNow,
                };

                this.db.QuickChatReplies.Add(targetReply);
                await this.db.SaveChangesAsync();
            }

            return(new QuickChatReplyViewModel
            {
                Id = targetReply.Id,
                Reply = targetReply.Reply,
            });
        }