Ejemplo n.º 1
0
        /// <summary>
        ///     Deletes the mission.
        /// </summary>
        /// <param name="id">
        ///     The identifier.
        /// </param>
        /// <returns>
        ///     Task{OperationResult}.
        /// </returns>
        public async Task <OperationResult> DeleteMission(string id)
        {
            var entities = await _azureManager.GetEntitiesForCompleteDelete <MissionAzure>(id);

            var    missionAzure = entities.FirstOrDefault(m => m.IsMissionEntity);
            string missionSetId = null;

            if (missionAzure != null)
            {
                missionSetId = missionAzure.MissionSetId;
                await _imagesProvider.DeleteImage(missionAzure.PhotoUrl);
            }

            if (!entities.Any())
            {
                return(new OperationResult(OperationResultStatus.Warning, "No entities to delete"));
            }

            var result = await _azureManager.DeleteEntitiesBatchAsync(entities);

            var refreshResult = await TryRefreshMissionSet(missionSetId);

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

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Deletes the question.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>Task{OperationResult}.</returns>
        public async Task <OperationResult> DeleteQuestion(string id)
        {
            var entities = await _azureManager.GetEntitiesForCompleteDelete <QuestionAzure>(id);

            if (entities.Any())
            {
                var result = await _azureManager.DeleteEntitiesBatchAsync(entities);

                return(result);
            }

            return(new OperationResult(OperationResultStatus.Warning, "No entities to delete"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deletes the mission draft.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>Task{OperationResult}.</returns>
        public async Task <OperationResult> DeleteMissionDraft(string id)
        {
            var entities = await _azureManager.GetEntitiesForCompleteDelete <MissionDraftAzure>(id);

            var draftAzure = entities.FirstOrDefault(m => !m.IsPersonQualityLink);

            if (draftAzure != null)
            {
                await _imagesProvider.DeleteImage(draftAzure.PhotoUrl);
            }

            if (entities.Any())
            {
                var result = await _azureManager.DeleteEntitiesBatchAsync(entities);

                return(result);
            }

            return(new OperationResult(OperationResultStatus.Warning, "No entities to delete"));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Deletes the MissionSet.
        /// </summary>
        /// <param name="id">
        ///     The identifier.
        /// </param>
        /// <returns>
        ///     Task{OperationResult}.
        /// </returns>
        public async Task <OperationResult> DeleteMissionSet(string id)
        {
            var entities = await _azureManager.GetEntitiesForCompleteDelete <MissionSetAzure>(id);

            var missionIds = entities.Where(l => l.IsMissionLink).Select(l => l.MissionId).ToList();

            await ClearBackReference(missionIds);

            if (entities.Any())
            {
                var result = await _azureManager.DeleteEntitiesBatchAsync(entities);

                return(result);
            }

            return(new OperationResult(OperationResultStatus.Warning, "No entities to delete"));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Removes the type of the links to deleted person.
        /// </summary>
        /// <param name="personQualityId">The person quality id.</param>
        /// <returns>Task{OperationResult}.</returns>
        public async Task <OperationResult> RemoveLinksToDeletedPersonQuality(string personQualityId)
        {
            var users = await _azureManager.GetEntitiesAsync(new TableQuery <UserAzure>());

            var entitiesToDelete =
                users.Where(m => m.IsPersonQualityLink && string.Equals(m.PersonQualityId, personQualityId));
            var groups = entitiesToDelete.GroupBy(e => e.PartitionKey);
            var error  = new StringBuilder();

            foreach (var group in groups)
            {
                var deleteResult = await _azureManager.DeleteEntitiesBatchAsync(group);

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

            return(error.Capacity <= 0
                ? new OperationResult(OperationResultStatus.Success)
                : new OperationResult(OperationResultStatus.Error, error.ToString()));
        }