/// <summary> /// Gets the MissionSet. /// </summary> /// <param name="id"> /// The identifier. /// </param> /// <returns> /// Task{MissionSet}. /// </returns> public async Task <MissionSet> GetMissionSet(string id) { var relatedEntities = await _azureManager.GetEntitiesAsync(new TableQuery <MissionSetAzure>().Where(id.GetFilterById())); return(await ConvertToMissionSet(relatedEntities, true)); }
/// <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> /// Gets the question. /// </summary> /// <param name="id">The identifier.</param> /// <returns>Task{Question}.</returns> public async Task <Question> GetQuestion(string id) { var relatedEntities = await _azureManager.GetEntitiesAsync(new TableQuery <QuestionAzure>().Where(GetFilterByPartitionKey(id))); return(ConvertToQuestion(relatedEntities, true)); }
/// <summary> /// Gets the aliases. /// </summary> /// <param name="options">The options.</param> /// <returns>Task{IEnumerable{CommonPlaceAlias}}.</returns> public async Task <IEnumerable <CommonPlaceAlias> > GetAliases(QueryOptions <CommonPlaceAlias> options) { var tableQuery = options.GenerateTableQuery <CommonPlaceAlias, CommonPlaceAliasAzure>(); var azureAliases = await _azureManager.GetEntitiesAsync(tableQuery); var aliases = azureAliases.Select(a => a.FromAzureModel()).ToList(); return(aliases.FilterCollectionPostFactum(options)); }
private static async Task FillMissions(List <MissionRequest> missionRequests) { var missionIds = missionRequests.GroupBy(mr => mr.MissionId).Select(group => group.Key).ToArray(); var expressions = new List <Expression <Func <Mission, bool> > >(); for (int index = 0; index < missionIds.Length; index++) { var missionId = missionIds[index]; if (index > 0) { var lastCriteria = expressions[index - 1]; expressions.Add(mission => lastCriteria.Invoke(mission) || mission.Id == missionId); } else { expressions.Add(mission => mission.Id == missionId); } } var queryOptions = new QueryOptions <Mission> { Filter = expressions.Last().Expand() }; var missionManager = new AzureTableStorageManager(AzureTableName.Missions); if (missionRequests.Count > 1) //for admin list { var initialFilter = TableQuery.GenerateFilterCondition( AzureTableConstants.RowKey, QueryComparisons.Equal, AzureTableConstants.MissionRowKey); var missions = await missionManager.GetEntitiesAsync( queryOptions.GenerateTableQuery <Mission, MissionAzure>(initialFilter)); foreach (var missionRequest in missionRequests) { missionRequest.Mission = missions.FirstOrDefault(mission => mission.Id == missionRequest.MissionId).FromAzureModel(); } } else //for single request get full mission { var initialFilter = TableQuery.GenerateFilterCondition( AzureTableConstants.PartitionKey, QueryComparisons.Equal, missionRequests[0].MissionId); var missions = await missionManager.GetEntitiesAsync(queryOptions.GenerateTableQuery <Mission, MissionAzure>(initialFilter)); missionRequests[0].Mission = Converters.ConvertToMission(missions, true); } }
private static async Task FillUsers(List <MissionRequest> missionRequests) { var userIds = missionRequests.GroupBy(mr => mr.UserId).Select(group => group.Key).ToArray(); var expressions = new List <Expression <Func <User, bool> > >(); for (int index = 0; index < userIds.Length; index++) { var userId = userIds[index]; if (index > 0) { var lastCriteria = expressions[index - 1]; expressions.Add(user => lastCriteria.Invoke(user) || user.Id == userId); } else { expressions.Add(user => user.Id == userId); } } var queryOptions = new QueryOptions <User> { Filter = expressions.Last().Expand() }; var userManager = new AzureTableStorageManager(AzureTableName.User); if (missionRequests.Count > 1)//for admin list { var initialFilter = TableQuery.GenerateFilterCondition( AzureTableConstants.RowKey, QueryComparisons.Equal, AzureTableConstants.UserRowKey); var usersResult = await userManager.GetEntitiesAsync(queryOptions.GenerateTableQuery <User, UserAzure>(initialFilter));//TODO don't load all users foreach (var missionRequest in missionRequests) { missionRequest.User = usersResult.SingleOrDefault(user => user.Id == missionRequest.UserId).FromAzureModel(); } } else //for single request get user qualities { var initialFilter = TableQuery.GenerateFilterCondition( AzureTableConstants.PartitionKey, QueryComparisons.Equal, missionRequests[0].UserId); var usersResult = await userManager.GetEntitiesAsync(queryOptions.GenerateTableQuery <User, UserAzure>(initialFilter)); missionRequests[0].User = Converters.ConvertToUser(usersResult, true); } }
/// <summary> /// Return the list of hint requests. /// </summary> /// <param name="options">Options for table query.</param> /// <returns></returns> public async Task <List <HintRequest> > GetHintRequests(QueryOptions <HintRequest> options) { var tableQuery = options.GenerateTableQuery <HintRequest, HintRequestAzure>(); var hintRequests = await _azureManager.GetEntitiesAsync(tableQuery); return(hintRequests.Select(t => t.FromAzureModel()).ToList()); }
/// <summary> /// Gets the missionRequest. /// </summary> /// <param name="id"> /// The identifier. /// </param> /// <returns> /// Task{MissionRequest}. /// </returns> public async Task <MissionRequest> GetMissionRequest(string id) { var result = await _azureManager.GetEntitiesAsync(new TableQuery <MissionRequestAzure>().Where(GetFilterByPartitionKey(id))); var azureEntity = result.SingleOrDefault(); var model = azureEntity.FromAzureModel(); await GetExpandProperties(new List <string> { "User", "Mission" }, new List <MissionRequest> { model }); return(model); }
/// <summary> /// Gets the person qualities. /// </summary> /// <param name="options">The options.</param> /// <returns>Task{IEnumerable{PersonQuality}}.</returns> public async Task <List <PersonQuality> > GetPersonQualities(QueryOptions <PersonQuality> options) { var tableQuery = options.GenerateTableQuery <PersonQuality, PersonQualityAzure>(); var result = await _azureManager.GetEntitiesAsync(tableQuery); var personQualities = result.Select(az => az.FromAzureModel()).ToList(); return(personQualities.FilterCollectionPostFactum(options)); }
/// <summary> /// Gets the appErrorInfos. /// </summary> /// <param name="options"> /// The options. /// </param> /// <returns> /// Task{IEnumerable{AppErrorInfo}}. /// </returns> public async Task <IEnumerable <AppErrorInfo> > GetAppErrorInfos(QueryOptions <AppErrorInfo> options) { var tableQuery = options.GenerateTableQuery <AppErrorInfo, AppErrorInfoAzure>(); var result = await _azureManager.GetEntitiesAsync(tableQuery); var azureAppErrorInfos = result.Select(azureModel => azureModel.FromAzureModel()).ToList(); return(azureAppErrorInfos.FilterCollectionPostFactum(options)); }
/// <summary> /// Removes the kind actions (developer purpose, not for regular use). /// </summary> /// <param name="userId">The user identifier.</param> /// <returns></returns> public async Task RemoveKindActions(string userId) { var filter = TableQuery.GenerateFilterCondition( "UserId", QueryComparisons.Equal, userId); var kindActions = await _azureManager.GetEntitiesAsync(new TableQuery <KindActionAzure>().Where(filter)); foreach (var kindActionAzure in kindActions) { kindActionAzure.PartitionKey = kindActionAzure.Id; kindActionAzure.RowKey = "KindAction"; try { await _azureManager.DeleteEntityAsync(kindActionAzure); } catch { //do nothing } } }
/// <summary> /// The get user. /// </summary> /// <param name="id">The id.</param> /// <returns>The <see cref="Task" />.</returns> public async Task <User> GetUser(string id) { var userRelatedEntities = await _azureManager.GetEntitiesAsync(new TableQuery <UserAzure>().Where(id.GetFilterById())); return(Converters.ConvertToUser(userRelatedEntities, true)); }
/// <summary> /// Gets the mission. /// </summary> /// <param name="id"> /// The identifier. /// </param> /// <returns> /// Task{Mission}. /// </returns> public async Task <Mission> GetMission(string id) { var azureMissions = await _azureManager.GetEntitiesAsync(new TableQuery <MissionAzure>().Where(id.GetFilterById())); return(Converters.ConvertToMission(azureMissions, true)); }