/// <summary> /// Decreases the kind action scales for all users. /// </summary> /// <returns></returns> public Task <OperationResult> DecreaseKindActionScales() { return (_azureManager.UpdateEntitiesAsync( new TableQuery <UserAzure>().Where( TableQuery.GenerateFilterConditionForInt("KindScale", QueryComparisons.GreaterThan, 0)) .Select(new[] { "KindScale", "KindScaleHighCurrentDays", "KindScaleHighMaxDays" }), async users => { foreach (var user in users) { if (user.KindScale < GameConstants.KindScale.DailyRegression) { user.KindScale = 0; user.KindScaleHighCurrentDays = 0; } else { if (user.KindScale > GameConstants.KindScale.AchievementLimit) { user.KindScaleHighCurrentDays = (user.KindScaleHighCurrentDays ?? 0) + 1; if (!user.KindScaleHighMaxDays.HasValue || user.KindScaleHighCurrentDays > user.KindScaleHighMaxDays) { user.KindScaleHighMaxDays = user.KindScaleHighCurrentDays; } } user.KindScale -= GameConstants.KindScale.DailyRegression; } await _azureManager.UpdateEntityAsync(user, replace: false); } })); }
/// <summary> /// Updates the user identity. /// </summary> /// <param name="userIdentity">The user identity.</param> /// <returns>Task{OperationResult}.</returns> public async Task <OperationResult> UpdateUserIdentity(UserIdentity userIdentity) { var result = await _azureManager.GetEntitiesAsync( new TableQuery <UserIdentityAzure>().Where(GetFilterByPartitionKey(userIdentity.Id))); var userIdentityAzure = result.FirstOrDefault(i => i.RowKey == AzureTableConstants.UserIdentityRowKey); if (userIdentityAzure == null) { return(new IdResult(OperationResultStatus.Error, "Can't find user identity for update")); } //stub to check vk existance, because we can't check with simple filter for vk in current realization if (userIdentityAzure.Vk_Id == 0 && userIdentity.VkIdentity != null && userIdentity.VkIdentity.Id > 0) { var checkExistanceResult = await CheckIdentityExist(new UserIdentity { VkIdentity = userIdentity.VkIdentity }); if (!String.IsNullOrEmpty(checkExistanceResult.Id)) { return(new OperationResult(OperationResultStatus.Error, "Vk account is already in use")); } } var updatedIdentity = userIdentity.ToAzureModel(); updatedIdentity.CopyToTableEntity(userIdentityAzure); return(await _azureManager.UpdateEntityAsync(userIdentityAzure)); }
/// <summary> /// Updates the missionRequest. /// </summary> /// <param name="missionRequest"> /// The missionRequest. /// </param> /// <returns> /// Task{OperationResult}. /// </returns> public async Task <OperationResult> UpdateMissionRequest(MissionRequest missionRequest) { var missionRequestsAzure = await _azureManager.GetEntitiesAsync( new TableQuery <MissionRequestAzure>().Where(GetFilterByPartitionKey(missionRequest.Id))); var missionRequestAzure = missionRequestsAzure.FirstOrDefault(); if (missionRequestAzure == null) { return(new OperationResult(OperationResultStatus.Error, "Can't find missionRequest for update")); } var updatedMissionRequest = missionRequest.ToAzureModel(); var oldUrls = missionRequestAzure.ProofImageUrls.SplitStringByDelimiter(); var newUrls = missionRequest.Proof.ImageUrls; await _imagesProvider.SaveImagesToProductionBlobOnUpdate(oldUrls, newUrls, BlobContainer.MissionRequestImages); updatedMissionRequest.ProofImageUrls = newUrls.JoinToString(); updatedMissionRequest.CopyToTableEntity(missionRequestAzure); return(await _azureManager.UpdateEntityAsync(missionRequestAzure)); }
/// <summary> /// Clears the links to mission set. /// </summary> /// <param name="missionIds">The mission ids.</param> /// <param name="missionSetId">The mission set id.</param> /// <returns>Task{OperationResult}.</returns> public async Task <OperationResult> SetMissionSetForMissions(List <string> missionIds, string missionSetId) { if (!missionIds.AnyValues()) { return(new OperationResult(OperationResultStatus.Success)); } var missions = (await _azureManager.GetEntitiesAsync(new TableQuery <MissionAzure>())).Where( m => m.IsMissionEntity && missionIds.Contains(m.Id)); var failedMissions = new List <string>(); foreach (var missionAzure in missions) { missionAzure.MissionSetId = missionSetId; var updateResult = await _azureManager.UpdateEntityAsync(missionAzure); if (updateResult.Status != 0) { failedMissions.Add($"Update failed for mission: {missionAzure.Id}: {updateResult.Description}"); } } if (failedMissions.Any()) { return(new OperationResult(OperationResultStatus.Error, failedMissions.JoinToString())); } return(new OperationResult(OperationResultStatus.Success)); }
/// <summary> /// Updates the name of the aliase. /// </summary> /// <param name="alias">The alias.</param> /// <returns>Task{OperationResult}.</returns> public async Task <OperationResult> UpdateAliaseName(CommonPlaceAlias alias) { var updatedAlias = alias.ToAzureModel(); var aliasAzure = await _azureManager.GetEntityByIdAndRowKeyAsync <CommonPlaceAliasAzure>( AzureTableConstants.CommonPlacesAliasesPartitionKey, updatedAlias.ShortName); if (aliasAzure == null) { return(new OperationResult(OperationResultStatus.Error, "No aliase for update")); } updatedAlias.CopyToTableEntity(aliasAzure); var updateResult = await _azureManager.UpdateEntityAsync(aliasAzure); return(updateResult); }
/// <summary> /// Updates the type of the person. /// </summary> /// <param name="personQuality">The mission.</param> /// <returns>Task{OperationResult}.</returns> public async Task <OperationResult> UpdatePersonQuality(PersonQuality personQuality) { var updatedPersonQuality = personQuality.ToAzureModel(); var personQualityAzure = await _azureManager.GetEntityByIdAndRowKeyAsync <PersonQualityAzure>( updatedPersonQuality.PartitionKey, updatedPersonQuality.RowKey); if (personQualityAzure == null) { return(new OperationResult(OperationResultStatus.Error, "No person quality for update")); } updatedPersonQuality.CopyToTableEntity(personQualityAzure); var updateResult = await _azureManager.UpdateEntityAsync(personQualityAzure); if (updateResult.Status == OperationResultStatus.Success) { var warnings = new StringBuilder(); foreach (var personQualityDependent in RepositoriesDependentOnPersonQuality) { var refreshMissionDraftsResult = await personQualityDependent.UpdateLinksToPersonQuality(personQualityAzure.Id, personQualityAzure.Name); if (refreshMissionDraftsResult.Status != OperationResultStatus.Success) { var warning = $"Links to updated person quality are not refreshed in {personQualityDependent.GetType().Name}! "; warnings.AppendLine(warning); } } if (warnings.Length > 0) { return(new OperationResult(OperationResultStatus.Warning, warnings.ToString())); } } return(updateResult); }