コード例 #1
0
ファイル: GetModelsByIds.cs プロジェクト: varumug/Ed-Fi-ODS-1
        public async Task ExecuteAsync(TContext context, TResult result, CancellationToken cancellationToken)
        {
            try
            {
                // Load the entity
                var models = await _repository.GetByIdsAsync(context.Ids, cancellationToken);

                // If it wasn't found, throw an exception
                if (context.Ids.Count == 1 && models.Count == 0)
                {
                    string message = string.Format(
                        "Entity of type '{0}' with id of '{1}' was not found.",
                        typeof(TEntityModel).Name,
                        context.Ids[0]);

                    // Capture exception information, but don't throw it for performance reasons
                    result.Exception = new NotFoundException(
                        message,
                        typeof(TEntityModel).Name,
                        context.Ids[0]
                        .ToString());

                    return;
                }

                context.PersistentModels = models;
            }
            catch (Exception ex)
            {
                result.Exception = ex;
            }
        }
コード例 #2
0
 /// <summary>
 /// Authorizes a call to get a single entity by its unique identifier.
 /// </summary>
 /// <param name="ids">The values of the unique identifiers to be retrieved.</param>
 /// <returns>The specified entity if found; otherwise null.</returns>
 public async Task <IList <T> > GetByIdsAsync(IList <Guid> ids, CancellationToken cancellationToken)
 {
     // This method is still used by GetById and GetBySpecification, but should never be exposed
     // to the callers since no authorization is performed.
     return(await _next.GetByIdsAsync(ids, cancellationToken));
 }
コード例 #3
0
ファイル: GetEntityById.cs プロジェクト: varumug/Ed-Fi-ODS-1
        /// <summary>
        /// Gets a single entity by its unique identifier.
        /// </summary>
        /// <param name="id">The value of the unique identifier.</param>
        /// <returns>The specified entity if found; otherwise null.</returns>
        public async Task <TEntity> GetByIdAsync(Guid id, CancellationToken cancellationToken)
        {
            var entities = await _getEntitiesByIds.GetByIdsAsync(new[] { id }, cancellationToken).ConfigureAwait(false);

            return(entities.SingleOrDefault());
        }
コード例 #4
0
 /// <summary>
 /// Gets a single entity by its unique identifier.
 /// </summary>
 /// <param name="id">The value of the unique identifier.</param>
 /// <returns>The specified entity if found; otherwise null.</returns>
 public async Task <TEntity> GetByIdAsync(Guid id, CancellationToken cancellationToken)
 {
     return(await _getEntitiesByIds.GetByIdsAsync(new[] { id }, cancellationToken)
            .ContinueWith(x => x.Result.SingleOrDefault(), cancellationToken));
 }
コード例 #5
0
 public async Task <IList <TEntity> > GetByIdsAsync(IList <Guid> ids, CancellationToken cancellationToken)
 => await _getEntitiesByIds.GetByIdsAsync(ids, cancellationToken);