示例#1
0
        public static async Task<UserText> CreateTextAsync(
            ApplicationDbContext dbContext,
            string content)
        {
            var entity = new UserText
            {
                Content = content,
                CreatedUtc = DateTime.UtcNow
            };

            MatchCollection matches = _emailRefRe.Matches(content);
            if (matches.Count > 0)
            {
                entity.MentionsUser = new List<UserInfo>();

                // We typically have few enough users that it's easiest just to get
                // all of them.
                IDictionary<string, UserInfo> allUsers = (await dbContext.UserInfos
                    .ToListAsync())
                    .ToDictionary(u => u.Email);

                foreach (string match in matches.Cast<Match>().Select(m => m.Groups[1].Value).Distinct())
                {
                    UserInfo mentionedUser;
                    if (allUsers.TryGetValue(match, out mentionedUser))
                    {
                        entity.MentionsUser.Add(mentionedUser);
                    }
                }
            }

            return entity;
        }
示例#2
0
        public static async Task NotifyMentionsAsync(
            ApplicationDbContext dbContext,
            string mentionedIn,
            string mentioningUserId,
            UserText text)
        {
            await dbContext.Entry(text).Collection(t => t.MentionsUser).LoadAsync();

            if (text.MentionsUser != null && text.MentionsUser.Count > 0)
            {
                // TBD
            }
        }