Exemplo n.º 1
0
        public async Task <IClientAccount> GetByIdAsync(string id)
        {
            var partitionKey = ClientAccountEntity.GeneratePartitionKey();
            var rowKey       = ClientAccountEntity.GenerateRowKey(id);

            return(await _clientsTablestorage.GetDataAsync(partitionKey, rowKey));
        }
Exemplo n.º 2
0
        public Task SetPin(string clientId, string newPin)
        {
            var partitionKey = ClientAccountEntity.GeneratePartitionKey();
            var rowKey       = ClientAccountEntity.GenerateRowKey(clientId);

            return(_clientsTablestorage.ReplaceAsync(partitionKey, rowKey, itm =>
            {
                itm.Pin = newPin;
                return itm;
            }));
        }
Exemplo n.º 3
0
        public Task ChangePassword(string clientId, string newPassword)
        {
            var partitionKey = ClientAccountEntity.GeneratePartitionKey();
            var rowKey       = ClientAccountEntity.GenerateRowKey(clientId);

            return(_clientsTablestorage.ReplaceAsync(partitionKey, rowKey, itm =>
            {
                itm.SetPassword(newPassword);
                return itm;
            }));
        }
Exemplo n.º 4
0
        public Task ChangePhoneAsync(string clientId, string phoneNumber)
        {
            var partitionKey = ClientAccountEntity.GeneratePartitionKey();
            var rowKey       = ClientAccountEntity.GenerateRowKey(clientId);

            return(_clientsTablestorage.ReplaceAsync(partitionKey, rowKey, itm =>
            {
                itm.Phone = phoneNumber;
                return itm;
            }));
        }
Exemplo n.º 5
0
        public async Task <string> GenerateNotificationsId(string clientId)
        {
            var partitionKey = ClientAccountEntity.GeneratePartitionKey();
            var rowKey       = ClientAccountEntity.GenerateRowKey(clientId);

            var updated = await _clientsTablestorage.ReplaceAsync(partitionKey, rowKey, itm =>
            {
                itm.NotificationsId = Guid.NewGuid().ToString("N");
                return(itm);
            });

            return(updated.NotificationsId);
        }
Exemplo n.º 6
0
        public async Task <bool> IsPasswordCorrect(string clientId, string password)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                return(false);
            }

            var entity = await _clientsTablestorage.GetDataAsync(ClientAccountEntity.GeneratePartitionKey(), ClientAccountEntity.GenerateRowKey(clientId));

            if (entity != null)
            {
                return(entity.CheckPassword(password));
            }

            return(false);
        }
Exemplo n.º 7
0
        public static ClientAccountEntity CreateNew(IClientAccount clientAccount, string password)
        {
            var result = new ClientAccountEntity
            {
                PartitionKey    = GeneratePartitionKey(),
                RowKey          = Guid.NewGuid().ToString(),
                NotificationsId = Guid.NewGuid().ToString("N"),
                Email           = clientAccount.Email.ToLower(),
                Phone           = clientAccount.Phone,
                Registered      = clientAccount.Registered,
                PartnerId       = clientAccount.PartnerId
            };

            result.SetPassword(password);

            return(result);
        }
Exemplo n.º 8
0
        public async Task <IEnumerable <IClientAccount> > GetByEmailAsync(string email)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(null);
            }

            IEnumerable <ClientPartnerRelationEntity> relations =
                await _clientPartnerTablestorage.GetDataAsync(ClientPartnerRelationEntity.GeneratePartitionKey(email));

            IEnumerable <string> rowKeys = relations.Select(x => x.ClientId);

            return((await _clientsTablestorage.GetDataAsync(ClientAccountEntity.GeneratePartitionKey(), rowKeys))
                   .Append(await _clientsTablestorage.GetDataAsync(_emailIndices, IndexEmail, GetEmailPartnerIndexRowKey(email, null)))
                   .Except(new ClientAccountEntity[] { null }, ClientAccountEntity.ComparerById)
                   .Distinct(ClientAccountEntity.ComparerById).ToArray());
        }
Exemplo n.º 9
0
        public async Task <IClientAccount> RegisterAsync(IClientAccount clientAccount, string password)
        {
            var    newEntity   = ClientAccountEntity.CreateNew(clientAccount, password);
            string partnerId   = clientAccount.PartnerId;
            string indexRowKey = GetEmailPartnerIndexRowKey(newEntity);
            var    indexEntity = AzureIndex.Create(IndexEmail, indexRowKey, newEntity);
            ClientPartnerRelationEntity clientPartner =
                ClientPartnerRelationEntity.CreateNew(clientAccount.Email, newEntity.Id, newEntity.PartnerId);

            await _emailIndices.InsertAsync(indexEntity);

            await _clientsTablestorage.InsertAsync(newEntity);

            await _clientPartnerTablestorage.InsertAsync(clientPartner);

            return(newEntity);
        }
Exemplo n.º 10
0
        public async Task GetClientsByChunkAsync(Func <IEnumerable <IClientAccount>, Task> chunkCallback)
        {
            await _clientsTablestorage.GetDataByChunksAsync(async chunk =>
            {
                var yieldResult = new List <IClientAccount>();

                var partitionKey = ClientAccountEntity.GeneratePartitionKey();

                foreach (var clientAccount in chunk.Where(item => item.PartitionKey == partitionKey))
                {
                    yieldResult.Add(clientAccount);
                }

                if (yieldResult.Count > 0)
                {
                    await chunkCallback(yieldResult);
                    yieldResult.Clear();
                }
            });
        }
Exemplo n.º 11
0
 private string GetEmailPartnerIndexRowKey(ClientAccountEntity clientAccount)
 {
     return(GetEmailPartnerIndexRowKey(clientAccount.Email, clientAccount.PartnerId));
 }
Exemplo n.º 12
0
        public async Task <IEnumerable <IClientAccount> > GetByIdAsync(string[] ids)
        {
            var partitionKey = ClientAccountEntity.GeneratePartitionKey();

            return(await _clientsTablestorage.GetDataAsync(partitionKey, ids));
        }