public async Task <IActionResult> GetById(Guid id, CancellationToken ct = default) { var location = await _queryProcessor.Query(new GetLocationById(id), ct); if (location == null) { return(BadRequest("No location with ID " + id.ToString() + " was found.")); } return(Ok(location)); }
public AssignEmployeeToLocationRequestValidator(IQueryProcessor queryProcessor) { RuleFor(x => x.LocationId).MustAsync((id, ct) => queryProcessor.Query(new LocationExists(id), ct)) .WithMessage("No Location with this ID exists."); RuleFor(x => x.EmployeeId).MustAsync((id, ct) => queryProcessor.Query(new EmployeeExists(id), ct)) .WithMessage("No Employee with this ID exists."); RuleFor(x => new { x.LocationId, x.EmployeeId }) .MustAsync(async(x, ct) => !await queryProcessor.Query(new IsEmployeeAlreadyAssignedToLocation(x.EmployeeId, x.LocationId), ct)) .WithMessage("This Employee is already assigned to that Location."); }
public async Task <IActionResult> GetById(Guid id, CancellationToken ct = default) { var employee = await _queryProcessor.Query(new GetEmployeeById(id), ct); //It is possible for GetByID() to return null. //If it does, we return HTTP 400 Bad Request if (employee == null) { return(BadRequest("No Employee with ID " + id + " was found.")); } //Otherwise, we return the employee return(Ok(employee)); }
public FactModule(IQueryProcessor queryProcessor, ICommandSender dispatcher) : base() { Get("/api/fact", async _ => { var base64Url = (string)this.Request.Query.url; var listFacts = new ListFactsQuery( string.IsNullOrEmpty(base64Url) == false ? Encoding.UTF8.GetString(Convert.FromBase64String(base64Url)) : null, (int?)this.Request.Query.skip, (int?)this.Request.Query.take ); return(await queryProcessor.Query(listFacts)); }); Post("/api/fact", async _ => { try { var command = new ReportSuspiciousFactCommand() { StartNodeXPath = Request.Form.startNodeXPath, StartOffset = Request.Form.startOffset, EndNodeXPath = Request.Form.endNodeXPath, EndOffset = Request.Form.endOffset, Reporter = Guid.Parse(Context.CurrentUser.FindFirstValue("userId")), WebPageUrl = GetFactUrl(), Wording = Request.Form.wording }; await dispatcher.Send(command); return(Negotiate.WithStatusCode(HttpStatusCode.OK)); } catch (DomainException ex) { return(BadRequest(ex)); } }); }
public async Task <BoardQueryType?> Board(string id) { var request = new BoardInfoQuery { BoardId = id }; var board = await processor.Query(request); if (board.Result == null) { return(null); } return(new BoardQueryType(board, processor)); }
public CreateEmployeeRequestValidator(IQueryProcessor queryProcessor) { RuleFor(x => x.LocationId).MustAsync((id, ct) => queryProcessor.Query(new LocationExists(id), ct)) .WithMessage("No Location with this ID exists."); RuleFor(x => x.FirstName).NotNull().NotEmpty().WithMessage("The First Name cannot be blank."); RuleFor(x => x.LastName).NotNull().NotEmpty().WithMessage("The Last Name cannot be blank."); RuleFor(x => x.JobTitle).NotNull().NotEmpty().WithMessage("The Job Title cannot be blank."); RuleFor(x => x.DateOfBirth).LessThan(DateTime.Today.AddYears(-16)).WithMessage("Employees must be 16 years old or older."); }
public async Task <IActionResult> Activate(Guid id) { if (id == Guid.Empty) { return(BadRequest("Please provide userid")); } var userModel = await _queryProcessor.Query(new GetUser(id)); if (userModel == null) { return(NotFound()); } var activateUserCommand = new ActivateUserCommand(id); await _commandSender.Send(activateUserCommand); return(NoContent()); }
public async Task Handle(RegisterUserCommand command) { if (await queryProcessor.Query(new FindUserQuery(command.UserId)) != null) { throw new UserAlreadyExists(command.UserId); } var user = new User(command.UserId); await repository.Save(user); }
public async Task <BoardQueryType> Board() { var request = new BoardInfoQuery { BoardId = boardId }; var queryResult = await processor.Query(request); return(new BoardQueryType(queryResult, processor)); }
public async Task <List <TodoQueryType> > Todos(int take, int?skip) { var request = new TodosOfBoardQuery { BoardId = Id, NumberOfRequestedTodos = take, NumberOfSkippedTodos = skip ?? 0 }; var queryResult = await processor.Query(request); var result = from todo in queryResult.Result select new TodoQueryType(todo, processor); return(result.ToList()); }
public ClaimsPrincipal ValidateUser(string token) { var jwtPayload = tokenGenerator.Decode(token); if (jwtPayload.Expire < DateTime.UtcNow) { return(null); } if (queryProcessor.Query(new FindUserQuery(jwtPayload.UserId)).Result == null) { return(null); } return(new ClaimsPrincipal(new [] { new ClaimsIdentity( new CustomIdentity(jwtPayload.UserId.ToString()), jwtPayload.Claims.Select(x => new Claim(x.Key, x.Value)) ) })); }
public AuthenticationModule( ICommandSender commandSender, ITokenEncoder tokenEncoder, IQueryProcessor queryProcessor) { Post("/api/register", async _ => { var command = this.Bind <RegisterUserCommand>(); await commandSender.Send(command); var token = new JwtPayload(command.UserId); return(Negotiate .WithStatusCode(HttpStatusCode.OK) .WithModel(new { token = tokenEncoder.Encode(token), expire = token.Expire })); }); Post("/api/login", async _ => { var userId = this.Request.Form.UserId; if (string.IsNullOrEmpty(userId)) { return(Negotiate.WithStatusCode(HttpStatusCode.Unauthorized)); } var user = await queryProcessor.Query(new FindUserQuery(userId)); if (user == null) { return(Negotiate.WithStatusCode(HttpStatusCode.Unauthorized)); } var token = new JwtPayload(userId); return(Negotiate .WithStatusCode(HttpStatusCode.OK) .WithModel(new { token = tokenEncoder.Encode(token), expire = token.Expire })); }); }
public async Task<ActionResult> Index() { ViewData.Model = await _queryProcessor.Query(new GetInventoryItems()); return View(); }
public async Task <ActionResult> Get() { var test = await _queryProcessor.Query <GetSomethingQuery, GetSomethingQueryResponse>(new GetSomethingQuery()); return(Ok()); }
public async Task <IReadOnlyCollection <FoosballGameListItem> > GetGamesList() { return(await _queryProcessor.Query(new GetFoosballGames())); }