Exemple #1
0
        public async Task <IHttpActionResult> GetReviewPieces(int exerciseId, int reviewId)
        {
            var    filterPartition   = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, ReviewPiece.GetPartitionKey(exerciseId));
            var    filterRowFrom     = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, KeyUtils.IntToKey(reviewId));
            var    filterRowTo       = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, KeyUtils.IntToKey(reviewId) + "Z");
            string combinedRowFilter = TableQuery.CombineFilters(filterRowFrom, TableOperators.And, filterRowTo);
            string combinedFilter    = TableQuery.CombineFilters(filterPartition, TableOperators.And, combinedRowFilter);
            var    query             = new TableQuery <ReviewPiece>().Where(combinedFilter);
            var    pieces            = await AzureStorageUtils.ExecuteQueryAsync(AzureStorageUtils.TableNames.ReviewPieces, query);

            // The access entity was written at the review start. See ReviewsApiController.PostStartReview
            var userRowKey = ReviewPiece.GetRowKey(reviewId, ReviewPiece.PieceTypes.Viewer, this.GetUserId());

            if (pieces.Any(i => i.RowKey == userRowKey))
            {
                RemoveAccessEntries(pieces);
            }
            else
            {
                pieces.Clear();
            }

            var piecesArr = pieces.Select(i => i.Json).ToArray();

            return(Ok(piecesArr));
        }
        public async Task <IHttpActionResult> GetTranscript(int id)
        {
            var partitionKey    = KeyUtils.IntToKey(id);
            var filterPartition = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey);
            // Since we do RowKey = KeyUtils.DateTimeToDescKey(now), the last written record is at the top.
            var query    = new TableQuery <GameCopycatEntity2>().Where(filterPartition).Take(1);
            var entities = await AzureStorageUtils.ExecuteQueryAsync(AzureStorageUtils.TableNames.GameCopycat, query);

            var result = entities.Any() ? entities.Single() : new object();

            return(Ok(result));
        }
Exemple #3
0
        public async Task <IHttpActionResult> GetAllReviewPieces(int exerciseId)
        {
            var filterPartition = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, ReviewPiece.GetPartitionKey(exerciseId));
            var query           = new TableQuery <ReviewPiece>().Where(filterPartition);
            var allPieces       = await AzureStorageUtils.ExecuteQueryAsync(AzureStorageUtils.TableNames.ReviewPieces, query);

            // Enforce access rights. The exercise author cannot see review items in an unfinished review. An access entity is written when a review is finished. See ReviewsApiController.PostFinishReview
            var userAccessCode = ReviewPiece.PieceTypes.Viewer + KeyUtils.IntToKey(this.GetUserId());
            // Find the ReviewIds which are allowed to access.
            var reviewIds = allPieces
                            .Where(i => ReviewPiece.GetUserAccessCode(i.RowKey) == userAccessCode)
                            .Select(i => ReviewPiece.GetReviewId(i.RowKey))
                            .ToList();

            RemoveAccessEntries(allPieces);

            // Filter the record set.
            var accessablePieces = allPieces.Where(i => reviewIds.Contains(ReviewPiece.GetReviewId(i.RowKey)));
            var piecesArr        = accessablePieces.Select(i => i.Json).ToArray();

            return(Ok(piecesArr));
        }
        private async Task <DapperHelper.PageItems <ResourceDto> > GetHistoryResources(int userId, string secondaryFilter, int offset = 0, int limit = 0)
        {
            var result = new DapperHelper.PageItems <ResourceDto>();

            var partitionKey    = KeyUtils.IntToKey(userId);
            var filterPartition = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey);
            var combinedFilter  = !String.IsNullOrEmpty(secondaryFilter) ? TableQuery.CombineFilters(filterPartition, TableOperators.And, secondaryFilter) : filterPartition;
            var query           = new TableQuery <LibraryHistoryEntity>().Where(combinedFilter);
            var entities        = await AzureStorageUtils.ExecuteQueryAsync(AzureStorageUtils.TableNames.LibraryHistory, query);

            result.TotalCount = entities.Count();

            if (entities.Any())
            {
                var historyItems = (limit != 0)
                        ? entities.Skip(offset).Take(limit)
                        : entities;

                result.Items = await HydrateHistoryItems(historyItems, userId);
            }

            return(result);
        }