Exemplo n.º 1
0
        public async Task DeleteSocialLoginAccountDataAsync(string account)
        {
            using (var ctx = new UserInfoEntities(this.connectionString))
            {
                var entities = await ctx.UserInfos.Where(f => f.Account == account).ToListAsync();

                if (entities == null || !entities.Any())
                {
                    return;
                }

                ctx.UserInfos.RemoveRange(entities);
                await ctx.SaveChangesAsync();
            }
        }
Exemplo n.º 2
0
        public async Task DeleteUserInfoAsync(string account, string channelName, string channelId)
        {
            using (var ctx = new UserInfoEntities(this.connectionString))
            {
                var entities = await ctx.UserInfos.Where(f => f.Account == account && f.ChannelId == channelId && f.ChannelName == channelName).ToListAsync();

                if (entities == null || !entities.Any())
                {
                    return;
                }

                // Remove profiles
                ctx.UserInfos.RemoveRange(entities);
                await ctx.SaveChangesAsync();
            }
        }
Exemplo n.º 3
0
        public async Task <UserInfoResult> CreateorUpdateUserInfoAsync(string account, string channelId, UserInfoRecordDescription description)
        {
            using (var ctx = new UserInfoEntities(this.connectionString))
            {
                UserInfoResult userInfoResult = new UserInfoResult();
                byte[]         serializedProfileDescription;
                using (MemoryStream stream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(stream, description);
                    serializedProfileDescription = stream.ToArray();
                }

                var profile = await ctx.UserInfos.SingleOrDefaultAsync(f => f.Account == account && f.ChannelId == channelId && f.ChannelName == description.Channel);

                var startTime = DateTime.UtcNow;
                if (profile == null)
                {
                    profile = new UserInfo
                    {
                        Account           = account,
                        ChannelName       = description.Channel,
                        ChannelId         = channelId,
                        ChannelProperties = serializedProfileDescription,
                        CreatedTime       = startTime,
                        ModifiedTime      = startTime
                    };

                    ctx.UserInfos.Add(profile);
                    userInfoResult.Action = ActionType.Create;
                }
                else
                {
                    profile.ChannelProperties = serializedProfileDescription;
                    profile.ModifiedTime      = startTime;
                    userInfoResult.Action     = ActionType.Update;
                }

                await ctx.SaveChangesAsync();

                userInfoResult.UserInfo = profile;
                return(userInfoResult);
            }
        }