Beispiel #1
0
        public async Task <List <AdminConfigResponse> > GetAll()
        {
            var configs = await _storage.GetAll <AdminConfiguration>(TableStorageEntityType.AdminConfiguration, PartitionKey.AdminConfiguration);

            var response = new List <AdminConfigResponse>();

            foreach (var config in configs)
            {
                var configuration = new AdminConfigResponse
                {
                    ConfigId        = new Guid(config.ConfigId),
                    FlagName        = config.FlagName,
                    FlagDescription = config.FlagDescription,
                    FlagValue       = (Allow)Enum.Parse(typeof(Allow), config.FlagValue, true),
                };

                if ((Allow)Enum.Parse(typeof(Allow), config.FlagValue, true) == Allow.AllOff)
                {
                    var allowdedUsers = await _storage.GetAll <AllowExtenedUser>(TableStorageEntityType.AllowExtenedUser, configuration.ConfigId.ToString());

                    var user = allowdedUsers?.SelectMany(e => e.UserId.Split(',')).Select(s => s).ToList() ?? new List <string>();
                    configuration.UserId = user;
                }
                response.Add(configuration);
            }
            return(response);
        }
Beispiel #2
0
        public async Task <AdminConfigResponse> Insert(AdminConfigResponse entity)
        {
            string Id          = Guid.NewGuid().ToString();
            var    adminConfig = new AdminConfiguration
            {
                RowKey          = Id,
                PartitionKey    = PartitionKey.AdminConfiguration,
                ConfigId        = Id,
                FlagName        = entity.FlagName,
                FlagDescription = entity.FlagDescription,
                FlagValue       = entity.FlagValue.ToString(),
            };

            await _storage.Insert <AdminConfiguration>(TableStorageEntityType.AdminConfiguration, adminConfig);

            if (entity.FlagValue == Allow.AllOff && entity.UserId != null)
            {
                var chunkedList = this.ChunkBy(entity.UserId, 100).Select(e => string.Join(",", e)).ToList();

                foreach (var chunk in chunkedList)
                {
                    var user = new AllowExtenedUser
                    {
                        RowKey       = Guid.NewGuid().ToString(),
                        PartitionKey = Id,
                        UserId       = chunk
                    };
                    await _storage.Insert <AllowExtenedUser>(TableStorageEntityType.AllowExtenedUser, user);
                }
            }
            entity.ConfigId = new Guid(Id);
            return(entity);
        }
Beispiel #3
0
        public async Task <AdminConfigResponse> Upsert(AdminConfigResponse entity)
        {
            var adminConfig = new AdminConfiguration
            {
                RowKey          = entity.ConfigId.ToString(),
                PartitionKey    = PartitionKey.AdminConfiguration,
                ConfigId        = entity.ConfigId.ToString(),
                FlagName        = entity.FlagName,
                FlagDescription = entity.FlagDescription,
                FlagValue       = entity.FlagValue.ToString(),
            };

            await _storage.Upsert <AdminConfiguration>(TableStorageEntityType.AdminConfiguration, adminConfig);

            var existingData = await _storage.GetAll <AllowExtenedUser>(TableStorageEntityType.AllowExtenedUser, entity.ConfigId.ToString());

            foreach (var data in existingData)
            {
                await _storage.Delete <AllowExtenedUser>(TableStorageEntityType.AllowExtenedUser, data);
            }

            if (entity.FlagValue == Allow.AllOff && entity.UserId != null)
            {
                var chunkedList = this.ChunkBy(entity.UserId, 100).Select(e => string.Join(",", e)).ToList();

                foreach (var chunk in chunkedList)
                {
                    var user = new AllowExtenedUser
                    {
                        RowKey       = Guid.NewGuid().ToString(),
                        PartitionKey = entity.ConfigId.ToString(),
                        UserId       = chunk
                    };
                    await _storage.Upsert <AllowExtenedUser>(TableStorageEntityType.AllowExtenedUser, user);
                }
            }
            return(entity);
        }