/// <summary>
        /// Queries an entity by its identifier.
        /// </summary>
        /// <typeparam name="TEntity">Type of the entity to retreive.</typeparam>
        /// <param name="context">Query Source to use for retreiving the entity.</param>
        /// <param name="id">Identifier of the entity to retreive.</param>
        /// <returns>The entity of the specified type with the specified identifier.</returns>
        public static Task <TEntity> GetById <TEntity>(this IEntityQuerySource context, int id)
            where TEntity : EntityBase
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(context.FirstOrDefault(q => q.Get <TEntity>().Where(x => x.Id == id)));
        }
Beispiel #2
0
        /// <summary>
        /// Gets an account by its email address.
        /// </summary>
        /// <param name="email">email address of the account to get.</param>
        /// <param name="suppressException">If true, no exception will be thrown if the account could not be found.</param>
        /// <returns>The account with the specified email address; or null if it does not exist.</returns>
        /// <exception cref="EmailNotRegisteredException">Thrown if the account could not be found.</exception>
        private async Task <Account> GetAccountByEmail(string email, bool suppressException)
        {
            var account = await _entityQuerySource.FirstOrDefault(q => q.Get <Account>()
                                                                  .Where(a => string.Equals(a.EmailAddress, email, StringComparison.OrdinalIgnoreCase)));

            if (!suppressException && account == null)
            {
                throw new EmailNotRegisteredException(email);
            }

            return(account);
        }