Exemple #1
0
 private static UserProfile ToProfile(ProfileTableEntity profileTableEntity)
 {
     return(new UserProfile
     {
         Username = profileTableEntity.RowKey,
         FirstName = profileTableEntity.FirstName,
         LastName = profileTableEntity.LastName,
         ProfilePictureId = profileTableEntity.ProfilePictureId
     });
 }
Exemple #2
0
 private static Profile ToProfile(ProfileTableEntity entity)
 {
     return(new Profile
     {
         Username = entity.RowKey,
         Firstname = entity.Firstname,
         Lastname = entity.Lastname,
         ProfilePictureId = entity.ProfilePictureId
     });
 }
Exemple #3
0
        public async Task DeleteProfile(string username)
        {
            try
            {
                ProfileTableEntity entity = await RetrieveProfileEntity(username);

                var deleteOperation = TableOperation.Delete(entity);
                await _profileTable.ExecuteAsync(deleteOperation);
            }
            catch (StorageException e)
            {
                throw new StorageErrorException("Could not delete from azure table", e);
            }
        }
Exemple #4
0
        public async Task <Profile> GetProfile(string username)
        {
            try
            {
                ProfileTableEntity entity = await RetrieveProfileEntity(username);

                return(ToProfile(entity));
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 404) // not found
                {
                    throw new ProfileNotFoundException($"Profile {username} not found");
                }

                throw new StorageErrorException("Could not read from Azure Table", e);
            }
        }
Exemple #5
0
        public async Task AddProfile(Profile profile)
        {
            ProfileTableEntity entity = ToEntity(profile);
            var insertOperation       = TableOperation.Insert(entity);

            try
            {
                await _table.ExecuteAsync(insertOperation);
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 409) // conflict
                {
                    throw new ProfileAlreadyExistsException($"Profile {profile.Username} already exists");
                }
                throw new StorageErrorException("Could not write to Azure Table", e);
            }
        }