Example #1
0
        /// <summary>
        ///     Updates the type of the links to person.
        /// </summary>
        /// <param name="personQualityId">The person quality id.</param>
        /// <param name="personQualityName">Name of the person quality.</param>
        /// <returns>Task{OperationResult}.</returns>
        public async Task <OperationResult> UpdateLinksToPersonQuality(string personQualityId, string personQualityName)
        {
            var users = await _azureManager.GetEntitiesAsync(new TableQuery <UserAzure>());

            var entitiesToUpdate =
                users.Where(m => m.IsPersonQualityLink && string.Equals(m.PersonQualityId, personQualityId)).ToIList();

            foreach (var userAzure in entitiesToUpdate)
            {
                userAzure.PersonQualityName = personQualityName;
            }

            var groups = entitiesToUpdate.GroupBy(e => e.PartitionKey);
            var error  = new StringBuilder();

            foreach (var group in groups)
            {
                var updateResult = await _azureManager.UpdateEntityBatchAsync(group.ToIList());

                if (updateResult.Status != OperationResultStatus.Success)
                {
                    var message = $"{group.Key} update error: {updateResult.Description}. ";
                    error.AppendLine(message);
                }
            }

            return(error.Capacity <= 0
                ? new OperationResult(OperationResultStatus.Success)
                : new OperationResult(OperationResultStatus.Error, error.ToString()));
        }
        /// <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));
        }