public async Task <IEnumerable <GetAddressView> > Handle(AddressesBy query, CancellationToken cancellationToken) { var addresses = _db.Query <Address>(); // Id provided so only use that if (query.Id.HasValue) { var theAddress = await addresses.FirstOrDefaultAsync(x => x.Id == query.Id, cancellationToken).ConfigureAwait(false); if (theAddress == null) { return(new List <GetAddressView>()); } var addressView = _mapper.Map <Address, GetAddressView>(theAddress); return(new[] { addressView }); } // Return the results return(_mapper.Map <IEnumerable <Address>, IEnumerable <GetAddressView> >(addresses)); }
public Task <IQueryable <EmailAddressView> > Handle(EmailAddressViewsBy query) { var queryable = _entities.Query <EmailAddress>() .Where(QueryEmailAddresses.ByUserId(query.UserId)) ; if (query.IsVerified.HasValue) { queryable = queryable.Where(x => x.IsVerified == query.IsVerified.Value); } var projection = queryable .Select(x => new EmailAddressView { EmailAddressId = x.Id, UserId = x.UserId, Value = x.Value, HashedValue = x.HashedValue, IsVerified = x.IsVerified, IsPrimary = x.IsPrimary, }) .OrderBy(query.OrderBy); return(Task.FromResult(projection)); }
public async Task <User> Handle(UserBy query) { var queryable = _entities.Query <User>().EagerLoad(query.EagerLoad); Task <User> entityTask; if (query.Id.HasValue) { entityTask = queryable.ByIdAsync(query.Id.Value); } else if (query.Principal != null && query.Principal.Identity.IsAuthenticated) { entityTask = queryable.ByIdAsync(query.Principal.Identity.GetUserId <int>()); } else if (query.UserLoginInfo != null) { entityTask = queryable.ByUserLoginInfoAsync(query.UserLoginInfo); } else { entityTask = queryable.ByNameAsync(query.Name); } return(await entityTask.ConfigureAwait(false)); }
public async Task <IEnumerable <GetCustomerWithAddressView> > Handle(CustomersBy query, CancellationToken cancellationToken) { var customersQuery = _db.Query <Customer>(); // Id provided so only use that if (query.Id.HasValue) { var theCustomer = await customersQuery.Select(GetCustomerWithAddressView.Projector).FirstOrDefaultAsync(x => x.Id == query.Id, cancellationToken).ConfigureAwait(false); if (theCustomer == null) { return(new List <GetCustomerWithAddressView>()); } return(new [] { theCustomer }); } // Apply filters if (!string.IsNullOrEmpty(query.FirstName)) { customersQuery = customersQuery.Where(x => x.FirstName.Contains(query.FirstName)); } if (!string.IsNullOrEmpty(query.LastName)) { customersQuery = customersQuery.Where(x => x.LastName.Contains(query.LastName)); } // Execute the query and return the results var customers = await customersQuery.Select(GetCustomerWithAddressView.Projector).ToListAsync(cancellationToken).ConfigureAwait(false); // Return the results return(customers); }
public async Task <EmailAddress> Handle(EmailAddressBy query) { var queryable = _entities.Query <EmailAddress>() .EagerLoad(query.EagerLoad); Task <EmailAddress> entityTask; if (query.Id.HasValue) { entityTask = queryable.ByIdAsync(query.Id.Value); } else if (query.Claim != null && query.Claim.Type == ClaimTypes.Email) { entityTask = queryable.ByValueAsync(query.Claim.Value); } else { entityTask = queryable.ByValueAsync(query.Value); } EmailAddress entity = await entityTask.ConfigureAwait(false); if (entity != null && query.IsVerified.HasValue && query.IsVerified.Value != entity.IsVerified) { entity = null; } return(entity); }
public async Task <EmailVerification> Handle(EmailVerificationBy query) { var entity = await _entities.Query <EmailVerification>() .EagerLoad(query.EagerLoad) .ByTicketAsync(query.Ticket) .ConfigureAwait(false); return(entity); }
public Task <IQueryable <RemoteMembership> > Handle(RemoteMembershipsByUser query) { var queryable = _entities.Query <RemoteMembership>().EagerLoad(query.EagerLoad); if (query.UserId.HasValue) { return(Task.FromResult(queryable.ByUserId(query.UserId.Value))); } return(Task.FromResult(queryable.ByUserName(query.UserName))); }
public async Task <IEnumerable <PersonByView> > Handle(PersonByQuery query, CancellationToken cancellationToken) { var personQuery = _db.Query <Person>(query.IncludeDeleted); if (string.IsNullOrWhiteSpace(query.Name) == false) { personQuery = personQuery.Where(p => p.Name == query.Name); } return(await personQuery.Select(PersonByView.Projector).ToListAsync(cancellationToken)); }
public Task <IQueryable <EmailAddress> > Handle(EmailAddressesBy query) { var queryable = _entities.Query <EmailAddress>() .EagerLoad(query.EagerLoad) .ByUserId(query.UserId); if (query.IsVerified.HasValue) { queryable = queryable.Where(x => x.IsVerified == query.IsVerified.Value); } return(Task.FromResult(queryable)); }
public async Task <UserView> Handle(UserViewBy query) { var queryable = _entities.Query <User>(); if (query.Id.HasValue) { queryable = queryable.Where(EntityExtensions.ById <User>(query.Id.Value)); } else if (query.Principal != null && query.Principal.Identity.IsAuthenticated) { queryable = queryable.Where(EntityExtensions.ById <User>(query.Principal.Identity.GetUserId <int>())); } else { queryable = queryable.Where(QueryUsers.ByName(query.Name)); } // project before querying to only get the data needed for the view. var projection = await queryable.Select(x => new { UserId = x.Id, UserName = x.Name, PrimaryEmailAddress = x.EmailAddresses.Where(y => y.IsPrimary) .Select(y => new { y.Value, y.HashedValue, }) .FirstOrDefault(), }) .SingleOrDefaultAsync().ConfigureAwait(false); if (projection == null) { return(null); } var view = new UserView { UserId = projection.UserId, UserName = projection.UserName, PrimaryEmailAddress = projection.PrimaryEmailAddress.Value, PrimaryEmailHash = projection.PrimaryEmailAddress.HashedValue, }; return(view); }
public Task <IQueryable <RemoteMembershipView> > Handle(RemoteMembershipViewsBy query) { var queryable = _entities.Query <RemoteMembership>().ByUserId(query.UserId); var projection = queryable .Select(x => new RemoteMembershipView { Provider = x.LoginProvider, Key = x.ProviderKey, UserId = x.UserId, }) .OrderBy(query.OrderBy); return(Task.FromResult(projection)); }
public Task <RemoteMembership> Handle(RemoteMembershipByUser query) { if (query.UserLoginInfo == null) { return(Task.FromResult(null as RemoteMembership)); } var queryable = _entities.Query <RemoteMembership>().EagerLoad(query.EagerLoad); if (query.UserId.HasValue) { return(queryable.ByUserIdAndLoginInfoAsync(query.UserId.Value, query.UserLoginInfo)); } return(queryable.ByUserNameAndLoginInfoAsync(query.UserName, query.UserLoginInfo)); }
public Task <bool> Handle(UserHasLocalMembership query) { var queryable = _entities.Query <LocalMembership>(); if (query.UserId.HasValue) { return(queryable.AnyAsync(QueryLocalMemberships.ByUserId(query.UserId.Value))); } if (query.Principal != null && query.Principal.Identity.HasAppUserId()) { return(queryable.AnyAsync(QueryLocalMemberships.ByUserId(query.Principal.Identity.GetUserId <int>()))); } return(queryable.AnyAsync(QueryLocalMemberships.ByUserName(query.UserName))); }
public async Task <IEnumerable <GetCustomerWithAddressView> > Handle(CustomersWithIncludeBy query, CancellationToken cancellationToken) { // Create a list of the expressions you would usually put into Include() statements. // For example if you want .Include(c => Address), do this... var includes = new List <Expression <Func <Customer, object> > > { c => c.Address, //c => c.OtherRelatedEntity }; // Pass include expressions list to Query(). When providing this list it's not necessary to specify generic types // to specify generic types as they can be inferred from the List instance. var customersQuery = _db.Query(includes); // Equivalent to: //var customersQuery = _db.Query<Customer>().Include(c => c.Address); // Id provided so only use that if (query.Id.HasValue) { var theCustomer = await customersQuery.FirstOrDefaultAsync(x => x.Id == query.Id, cancellationToken).ConfigureAwait(false); var custView = _mapper.Map <Customer, GetCustomerWithAddressView>(theCustomer); return(new[] { custView }); } // Apply filters if (!string.IsNullOrEmpty(query.FirstName)) { customersQuery = customersQuery.Where(x => x.FirstName.Contains(query.FirstName)); } if (!string.IsNullOrEmpty(query.LastName)) { customersQuery = customersQuery.Where(x => x.LastName.Contains(query.LastName)); } // Execute the query and return the results var customers = await customersQuery.ToListAsync(cancellationToken).ConfigureAwait(false); // Return the results return(_mapper.Map <IEnumerable <Customer>, IEnumerable <GetCustomerWithAddressView> >(customers)); }
public async Task <IEnumerable <GetCustomerEmployerMappingDetailedDataView> > Handle(GetCustomerEmployerMappings query, CancellationToken cancellationToken) { var includes = new List <Expression <Func <CustomerEmployerMapping, object> > > { cem => cem.Customer, cem => cem.Employer, }; var cemQuery = _db.Query(includes); // Equivalent to: //var cemQuery = _db.Query<CustomerEmployerMapping>().Include(cem => cem.Customer).Include(cem => cem.Employer); // Execute the query and return the results var cems = await cemQuery.ToListAsync(cancellationToken).ConfigureAwait(false); // Return the results return(_mapper.Map <IEnumerable <CustomerEmployerMapping>, IEnumerable <GetCustomerEmployerMappingDetailedDataView> >(cems)); }
public async Task <LocalMembership> Handle(LocalMembershipByUser query) { var queryable = _entities.Query <LocalMembership>().EagerLoad(query.EagerLoad); Task <LocalMembership> entityTask; if (query.UserId.HasValue) { entityTask = queryable.ByUserIdAsync(query.UserId.Value); } else if (query.UserLoginInfo != null) { entityTask = queryable.ByUserLoginInfoAsync(query.UserLoginInfo); } else { entityTask = queryable.ByUserNameAsync(query.UserName); } return(await entityTask.ConfigureAwait(false)); }
public async Task Handle(VerifyEmailSecret command) { var entity = await _entities.Query <EmailVerification>().ByTicketAsync(command.Ticket); command.Token = entity.Token; }
public Task <LocalMembership> Handle(LocalMembershipByVerifiedEmail query) { var queryable = _entities.Query <LocalMembership>().EagerLoad(query.EagerLoad); return(queryable.ByVerifiedEmailAsync(query.EmailAddress)); }
public GetCustomerEmployerMappings() { _readDb = Substitute.For <IReadEntities>(); _mapper = new MapperConfiguration(c => c.AddProfiles( new List <Profile> { new CommandToEntityProfile(), new EntityToViewProfile(), } )) .CreateMapper(); var anAddress = new Address { Id = 1, Street = "street", Suburb = "suburb", State = "state", Country = "country", PostalCode = "postcode", }; _addresses = new List <Address>() { anAddress }; var mockAddressQueryable = _addresses.AsQueryable().BuildMock(); _readDb.Query <Address>().Returns(mockAddressQueryable); var aCust = new Customer { Id = 101, FirstName = "first name", LastName = "last name", EmailAddress = "my.email@address", AddressId = anAddress.Id }; _customers = new List <Customer>() { aCust }; var mockCustomerQueryable = _customers.AsQueryable().BuildMock(); _readDb.Query <Customer>().Returns(mockCustomerQueryable); //_readDb.Query<Customer>(Arg.Any<IEnumerable<Expression<Func<Customer, object>>>>()).Returns(mockCustomerQueryable); var anEmp = new Employer { Id = 1001, Name = "employer", }; _employers = new List <Employer>() { anEmp }; var mockEmployerQueryable = _employers.AsQueryable().BuildMock(); _readDb.Query <Employer>().Returns(mockEmployerQueryable); var aMapping = new CustomerEmployerMapping { Id = 999, CustomerId = aCust.Id, EmployerId = anEmp.Id }; _customerEmployerMappings = new List <CustomerEmployerMapping>() { aMapping }; var mockCustomerEmployerMappingQueryable = _customerEmployerMappings.AsQueryable().BuildMock(); _readDb.Query <CustomerEmployerMapping>().Returns(mockCustomerEmployerMappingQueryable); }