public async Task SendAlertToAll(SandBoxMessage sandBoxMessage)
        {
            var totalUserAmount = await sandBoxDataAccessor.Count <UserAccountEntry>();

            var length = Math.Round(totalUserAmount / 100.0) + 1;

            for (int step = 0; step < length; step++)
            {
                var msgBoxList = new List <SandBoxMessage>();
                var userList   = await sandBoxDataAccessor.ListAsync <UserAccountEntry>(x => x.Id != sandBoxMessage.FromUserAccountId, step * 100, 100);

                foreach (var user in userList)
                {
                    msgBoxList.Add(new SandBoxMessage
                    {
                        Id                = Guid.NewGuid(),
                        CreateTime        = DateTime.Now,
                        Content           = sandBoxMessage.Content,
                        FromUserAccountId = sandBoxMessage.FromUserAccountId,
                        MessageType       = sandBoxMessage.MessageType,
                        TimeStamp         = TimeStamp.Get(),
                        ToUserAccountId   = user.Id
                    });
                }
                await sandBoxDataAccessor.AddRange(msgBoxList);
            }
        }
 public async Task SendAlertTo(SandBoxMessage sandBoxMessage)
 {
     await sandBoxDataAccessor.Add(sandBoxMessage);
 }
Exemple #3
0
        public async Task CreateCategoryCommentExtPostEntry(CategoryComment comment)
        {
            var categoryModel = await ContentAccessor.OneAsync <Categories>(x => x.Status != ContentStatus.Close && x.Id == comment.CategoryId);

            //设置话题为漫画名
            var topic = new PostEntryTopic()
            {
                CreateTime = DateTime.Now,
                Id         = Guid.NewGuid(),
                Text       = categoryModel.Name,
                PosterId   = comment.UserAccountId
            };
            var topicExt = new ContentExtPostEntryTopic()
            {
                Id        = Guid.NewGuid(),
                TopicText = categoryModel.Name,
                LinkId    = categoryModel.Id,
                LinkType  = "category"
            };
            //评论
            var postentryModel = new PostEntry()
            {
                Id             = Guid.NewGuid(),
                CreateTime     = DateTime.Now,
                PostEntryTopic = categoryModel.Name,
                UserId         = comment.UserAccountId,
                TimeStamp      = TimeStamp.Get(),
                TextContent    = comment.Content,
            };

            //目前是一条漫画评论对应一个话题, 为防止以后出现多话题, 保留此表
            var categoryPostentryMapping = new CategoryPostEntryMapping()
            {
                Id          = Guid.NewGuid(),
                CategoryId  = categoryModel.Id,
                PostEntryId = postentryModel.Id,
                CreateTime  = DateTime.Now
            };

            await ContentAccessor.Add(topic);

            await ContentAccessor.Add(topicExt);

            await ContentAccessor.Add(postentryModel);

            await ContentAccessor.Add(categoryPostentryMapping);

            var sandBoxMsg = new SandBoxMessage()
            {
                Content           = $"您在漫画{topic}的回复,收到了新的评论.",
                CreateTime        = DateTime.Now,
                FromUserAccountId = comment.UserAccountId,
                ToUserAccountId   = postentryModel.UserId,
                Id           = Guid.NewGuid(),
                IsRead       = false,
                MessageType  = SandBoxMessageType.PostEntryComment,
                TimeStamp    = TimeStamp.Get(),
                RecieveToken = ""
            };
            await sandBoxBusiness.SendAlertTo(sandBoxMsg);
        }