public async Task <AuthInfoDto> Authorize(AuthorizeAccountCommand command) { var account = await queryFactory.ResolveQuery <AccountByLoginAndPasswordQuery>() .Execute(command.Login, command.Password); return(this.accountApiService.CreateAuthInfo(account)); }
public void ShowBookById(int id) { var book = queryFactory .ResolveQuery <BookByIdQuery>() .Execute(id); Console.WriteLine($"Book by id #{book.BookId}: {book.Title} - {book.Genre}"); }
public async Task <IActionResult> Authorize( AuthorizeUserCommand command) { ModelState.ThrowValidationExceptionIfInvalid <User.Errors>(); var user = await queryFactory.ResolveQuery <UserByLoginAndPasswordQuery>() .Execute(command.Login, command.Password); return(Ok(GetTokenData(user))); }
private static void Main(string[] args) { // Getting the factories IQueryFactory queryFactory = Container.Current.Resolve <IQueryFactory>(); ICommandsFactory commandsFactory = Container.Current.Resolve <ICommandsFactory>(); // Executing commands Console.WriteLine("Crating new user..."); CreateUserCommand createUserCommand = new CreateUserCommand( Guid.NewGuid().ToString().ToUpperInvariant().Replace("-", "").Substring(0, 6), Guid.NewGuid().ToString().ToUpperInvariant().Replace("-", "").Substring(0, 6), Guid.NewGuid().ToString().ToUpperInvariant().Replace("-", "").Substring(0, 6) + "@email.com"); commandsFactory.ExecuteQuery(createUserCommand); Console.WriteLine("User created with Id = {0}", createUserCommand.Id); Console.WriteLine(); // Executing queries IEnumerable <User> activeUsers = queryFactory .ResolveQuery <IActiveUsersQuery>() .Execute(); Console.WriteLine("Active users: "); foreach (User t in activeUsers) { Console.WriteLine("{0} {1} {2} {3}", t.Id, t.LastName, t.FirstName, t.Email); } Console.WriteLine(); IEnumerable <User> inactiveUsers = queryFactory .ResolveQuery <IInactiveUsersQuery>() .Execute(); Console.WriteLine("Inactive users: "); foreach (User t in inactiveUsers) { Console.WriteLine("{0} {1} {2} {3}", t.Id, t.LastName, t.FirstName, t.Email); } Console.WriteLine(); User user = queryFactory .ResolveQuery <IUserByEmailQuery>() .Execute("*****@*****.**"); Console.WriteLine("User by e-mail \"[email protected]\":"); Console.WriteLine("{0} {1} {2} {3}", user.Id, user.LastName, user.FirstName, user.Email); Console.Read(); }
public ActionResult <IQueryable <CategoryDto> > GetAll() { var result = _queryFactory.ResolveQuery <IGetCategoriesQuery>().Execute(); if (result != null) { return(Ok(result)); } return(NoContent()); }
private async Task <AccountDto> GetAccountByToken(string token) { try { var accountId = Utils.GetAccountIdFromJwt(token); if (Context.ConnectionManager.IsConnected(accountId)) { throw new ConflictException("ALREADY_CONNECTED"); } var account = await queryFactory.ResolveQuery <AccountByIdQuery>().Execute(accountId); return(AutoMapper.Mapper.Map <Account, AccountDto>(account)); } catch (NotFoundException ex) { await Disconnect(404, ex.Message); throw; } catch (ConflictException ex) { await Disconnect(409, ex.Message); throw; } catch (Exception ex) { logger.LogCritical(ex, "Unhandled exception in AuthMessageHandler in method 'GetAccountByToken'."); throw; } }
public async Task <IActionResult> GetInfo(int accountId, CancellationToken token = default(CancellationToken)) { var response = await queryFactory.ResolveQuery <AccountByIdQuery>().Execute(accountId); return(Ok(AutoMapper.Mapper.Map <Account, AccountDto>(response))); }