/// <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)); }
/// <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)); }
/// <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)); }
/// <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); }