Ejemplo n.º 1
0
        /// <summary>
        ///     Updates the mission draft.
        /// </summary>
        /// <param name="mission">
        ///     The mission.
        /// </param>
        /// <returns>
        ///     Task{OperationResult}.
        /// </returns>
        public async Task <OperationResult> UpdateMissionDraft(MissionDraft mission)
        {
            var draftRelatedEntities =
                await
                _azureManager.GetEntitiesAsync(
                    new TableQuery <MissionDraftAzure>().Where(mission.Id.GetFilterById()));

            var missionDraftAzure = draftRelatedEntities.FirstOrDefault(m => !m.IsPersonQualityLink);

            if (missionDraftAzure == null)
            {
                return(new OperationResult(OperationResultStatus.Error, "Can't find mission draft for update"));
            }

            var newMissionDraft = mission.ToAzureModel();

            newMissionDraft.PhotoUrl = await _imagesProvider.SaveImageToProductionBlobOnUpdate(missionDraftAzure.PhotoUrl, newMissionDraft.PhotoUrl, BlobContainer.MissionDraftImages);

            newMissionDraft.CopyToTableEntity(missionDraftAzure);
            var entitiesToDelete = draftRelatedEntities.Where(m => m.IsPersonQualityLink).ToList();
            var entitiesToAdd    = GeneratePersonQualityLinks(mission);
            var entitiesToUpdate = AzureTableExtensions.FilterUpdatableLinks(entitiesToAdd, entitiesToDelete);

            entitiesToUpdate.Add(missionDraftAzure);

            return(await _azureManager.UpdateEntityBatchAsync(entitiesToUpdate, entitiesToAdd, entitiesToDelete));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Updates the user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="replace">if set to <c>true</c> [replace].</param>
        /// <returns>Task{OperationResult}.</returns>
        public async Task <OperationResult> UpdateUser(User user, bool replace)
        {
            //replace should be set to false only for simple changes (nickname and image)
            if (!replace)
            {
                var updatingUser = user.ToAzureModel();
                return(await _azureManager.UpsertEntityAsync(updatingUser, false));
            }

            var userRelatedEntities =
                await _azureManager.GetEntitiesAsync(new TableQuery <UserAzure>().Where(user.Id.GetFilterById()));

            var userAzure = userRelatedEntities.FirstOrDefault(u => u.IsUserEntity);
            var newUser   = user.ToAzureModel();

            newUser.CopyToTableEntity(userAzure);

            var entitiesToDelete = userRelatedEntities.Where(m => m.IsPersonQualityLink).ToList();
            var entitiesToAdd    = GeneratePersonQualityLinks(user);
            var entitiesToUpdate = AzureTableExtensions.FilterUpdatableLinks(entitiesToAdd, entitiesToDelete);

            entitiesToUpdate.Add(userAzure);

            return
                (await _azureManager.UpdateEntityBatchAsync(entitiesToUpdate, entitiesToAdd, entitiesToDelete));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Updates the MissionSet.
        /// </summary>
        /// <param name="missionSet">
        ///     The MissionSet.
        /// </param>
        /// <returns>
        ///     Task{OperationResult}.
        /// </returns>
        public async Task <OperationResult> UpdateMissionSet(MissionSet missionSet)
        {
            var relatedEntities =
                await
                _azureManager.GetEntitiesAsync(new TableQuery <MissionSetAzure>().Where(missionSet.Id.GetFilterById()));

            var missionSetAzure = relatedEntities.FirstOrDefault(m => m.IsMissionSetEntity);

            if (missionSetAzure == null)
            {
                return(new OperationResult(OperationResultStatus.Error, "Can't find MissionSet for update"));
            }

            var updatedMissionSet = missionSet.ToAzureModel();

            updatedMissionSet.CopyToTableEntity(missionSetAzure);

            var entitiesToDelete = relatedEntities.Where(m => !m.IsMissionSetEntity).ToList();

            await ClearBackReferenceForMissionsExcludedFromMissionSet(entitiesToDelete, missionSet);

            var entitiesToAdd = await GenerateMissionDependentLinks(missionSet, missionSetAzure);

            var entitiesToUpdate = AzureTableExtensions.FilterUpdatableLinks(entitiesToAdd, entitiesToDelete);

            entitiesToUpdate.Add(missionSetAzure);

            return(await _azureManager.UpdateEntityBatchAsync(entitiesToUpdate, entitiesToAdd, entitiesToDelete));
        }
Ejemplo n.º 4
0
        public static async Task CreateAllTables(IConfiguration configuration)
        {
            var account    = AzureTableExtensions.GetStorageAccount(configuration);
            var client     = account.CreateCloudTableClient();
            var tableNames = new[] { "Feed", "Post" };

            foreach (var tableName in tableNames)
            {
                await client.GetTableReference(tableName).CreateIfNotExistsAsync();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Updates the mission.
        /// </summary>
        /// <param name="mission">
        ///     The mission.
        /// </param>
        /// <returns>
        ///     Task{OperationResult}.
        /// </returns>
        public async Task <OperationResult> UpdateMission(Mission mission)
        {
            var relatedEntities =
                await _azureManager.GetEntitiesAsync(new TableQuery <MissionAzure>().Where(mission.Id.GetFilterById()));

            var missionAzure = relatedEntities.FirstOrDefault(m => m.IsMissionEntity);

            if (missionAzure == null)
            {
                return(new OperationResult(OperationResultStatus.Error, "Can't find mission for update"));
            }

            var updatedMission = mission.ToAzureModel();

            updatedMission.PhotoUrl =
                await
                _imagesProvider.SaveImageToProductionBlobOnUpdate(
                    missionAzure.PhotoUrl,
                    updatedMission.PhotoUrl,
                    BlobContainer.MissionImages);

            updatedMission.CopyToTableEntity(missionAzure);

            var entitiesToDelete = relatedEntities.Where(m => m.IsPersonQualityLink).ToList();
            var entitiesToAdd    = GeneratePersonQualityLinks(mission);
            var entitiesToUpdate = AzureTableExtensions.FilterUpdatableLinks(entitiesToAdd, entitiesToDelete);

            entitiesToUpdate.Add(missionAzure);

            var hintsToDelete = relatedEntities.Where(m => m.IsHintLink).ToList();
            var hintsToAdd    = GenerateHintLinks(mission);
            var hintsToUpdate = AzureTableExtensions.FilterUpdatableLinks(hintsToAdd, hintsToDelete);

            entitiesToUpdate.AddRange(hintsToUpdate);
            entitiesToAdd.AddRange(hintsToAdd);
            entitiesToDelete.AddRange(hintsToDelete);

            var updateResult = await _azureManager.UpdateEntityBatchAsync(entitiesToUpdate, entitiesToAdd, entitiesToDelete);

            var refreshResult = await TryRefreshMissionSet(missionAzure.MissionSetId);

            if (refreshResult.Status != OperationResultStatus.Success)
            {
                Trace.TraceError(refreshResult.Description);
            }

            return(updateResult);
        }
Ejemplo n.º 6
0
        private bool CheckExpandGetFilter(IEnumerable <string> expand, out string expandFilter)
        {
            // if expand is not empty, related entites should be selected so we don't need additional filter
            if (expand != null &&
                expand.Any(e => string.Equals(e, "PersonQualities", StringComparison.InvariantCultureIgnoreCase) ||
                           string.Equals(e, "Hints", StringComparison.InvariantCultureIgnoreCase)))
            {
                expandFilter = string.Empty;
                return(true);
            }

            // if expand is empty, we need to add row filter to NOT select related entities, but we select related hints
            expandFilter = TableQuery.CombineFilters(
                AzureTableExtensions.GenerateStartsWithFilterCondition(AzureTableConstants.RowKey, AzureTableConstants.HintLinkRowKeyPrefix),
                TableOperators.Or,
                TableQuery.GenerateFilterCondition(
                    AzureTableConstants.RowKey,
                    QueryComparisons.Equal,
                    AzureTableConstants.MissionRowKey));
            return(false);
        }
Ejemplo n.º 7
0
 public Posts(IConfiguration configuration)
 {
     account = AzureTableExtensions.GetStorageAccount(configuration);
     client  = account.CreateCloudTableClient();
     table   = client.GetTableReference <Post>();
 }