public UserAccountModule(ICommandDispatcher commandDispatcher, IPasswordEncryptor passwordEncryptor) { Post["/register"] = _ => { var req = this.Bind<NewUserRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreateUser(req.Email, passwordEncryptor.Encrypt(req.Password), req.Name, req.PhoneNumber)); return null; }; Post["/password/requestReset"] = _ => { var req = this.Bind<ResetPasswordRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreatePasswordResetToken(req.Email) ); return null; }; Put["/password/reset/{token}"] = _ => { return null; }; }
private static void GenerateValues(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated) { if (original.ValuesMatch(updated)) return; if (updated.DefinitionValues == null || !updated.DefinitionValues.Any()) { dispatcher.Dispatch(new RemoveAllEntityValuesCommand(updated.Identity)); return; } dispatcher.Dispatch(new UpdateEntityValuesCommand(updated.Identity, BuildEntityValues(updated.Identity, updated.DefinitionValues))); }
private static void GenerateReLabelDescriptionCommand(ICommandDispatcher dispatcher, MetadataDefinitionResource original, MetadataDefinitionResource updated) { if (original.DescriptionMatches(updated)) return; dispatcher.Dispatch(new ReLabelMetadataDefinitionDescriptionCommand(updated.Identity, new MetadataDefinitionDescription(updated.Description.Trim()))); }
private static void GenerateAssociationCommand(ICommandDispatcher dispatcher, MetadataDefinitionGroupResource original, MetadataDefinitionGroupResource updated) { if (original.DefinitionIdsMatch(updated)) return; dispatcher.Dispatch(new AssociateDefinitionsToMetadataDefinitionGroupCommand(original.Identity, updated.Definitions.Select(x=> x.Id).ToArray())); }
private static void GenerateReLabelCommand(ICommandDispatcher dispatcher, MetadataDefinitionGroupResource original, MetadataDefinitionGroupResource updated) { if (original.DiscriptionMatches(updated)) return; dispatcher.Dispatch(new ReLabelMetadataDefinitionGroupCommand(updated.Identity, new MetadataDefinitionGroupName(updated.Name), new MetadataDefinitionGroupDescription(updated.Description), updated.Tracking)); }
private static void GenerateChangeGroupCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated) { if (original.DefinitionGroup != null && Equals(original.DefinitionGroup.Id, updated.DefinitionGroup.Id)) return; dispatcher.Dispatch(new EntityChangedGroupCommand(updated.Identity, updated.DefinitionGroup.Id)); }
public WorkModule(ICommandDispatcher dispatcher, ICommandDeserializer deserializer) { Post["/work"] = r => { object command; try { var reader = new StreamReader(Request.Body); string str = reader.ReadToEnd(); command = deserializer.Deserialize(str); } catch (InvalidCommandObjectException) { return new Response().WithStatusCode(HttpStatusCode.BadRequest); } try { dispatcher.Dispatch(command); return new Response().WithStatusCode(HttpStatusCode.OK); } catch (NoAvailableHandlerException) { return new Response().WithStatusCode(HttpStatusCode.NotImplemented); } }; }
public NewUserModule(IPasswordEncryptor passwordEncryptor, ICommandDispatcher commandDispatcher, IReadOnlyRepository readOnlyRepository) { Post["/user/facebook"] = r => { var newUserRequest = this.Bind<NewUserRequest>(); CheckForExistingFacebookUser(readOnlyRepository, newUserRequest); DispatchCommand(commandDispatcher, newUserRequest); return new Response().WithStatusCode(HttpStatusCode.OK); }; Post["/user"] = r => { var newUserRequest = this.Bind<NewUserRequest>(); CheckForExistingUser(readOnlyRepository, newUserRequest); commandDispatcher.Dispatch(this.VisitorSession(), new NewUserCommand { Email = newUserRequest.Email, EncryptedPassword = passwordEncryptor. Encrypt( newUserRequest. Password) }); return new Response().WithStatusCode(HttpStatusCode.OK); }; }
public void WhenIIssueACreateElectionCommand() { //setup the "bus" components m_commandDispatcher = new CommandDispatcher(); m_eventPublisher = new EventDispatcher(); //register the command handler var repository = MockRepository.GenerateStub<IRepository<Election>>(); m_commandDispatcher.Register(new MakeAnElectionCommandHandler(repository, null)); //register the event handler m_eventPublisher.RegisterHandler<ElectionMadeEvent>(@event => m_electionCreatedEvent = @event); //wire-up the domain event to the event publisher DomainEvents.Register<ElectionMadeEvent>(@event => m_eventPublisher.Publish(@event)); //create and send the command var command = new MakeAnElection { AdministratorCode = "AdmCode", CompanyCode = "CoCode", ParticipantId = "12345", ElectionAmount = 1000, ElectionReason = "election reason", }; m_commandDispatcher.Dispatch<MakeAnElection>(command); Assert.Pass(); }
private static void GenerateValues(ICommandDispatcher dispatcher, MetadataDefinitionResource original, MetadataDefinitionResource updated) { if (original.ValuesMatch(updated)) return; dispatcher.Dispatch(new UpdateMetadataDefinitionValuesCommand(updated.Identity, updated.Values)); }
private static void GenerateUpdateRegexCommand(ICommandDispatcher dispatcher,MetadataDefinitionResource original, MetadataDefinitionResource updated) { if (original.RegexMatches(updated)) return; dispatcher.Dispatch(new UpdateMetadataDefinitionRegexCommand(updated.Identity,updated.Regex)); }
public WorkModule(ICommandDispatcher dispatcher, ICommandDeserializer deserializer) { Post["/work"] = r => { IUserSession userSession = this.UserSession(); object command; try { var reader = new StreamReader(Request.Body); string str = reader.ReadToEnd(); command = deserializer.Deserialize(str); } catch (InvalidCommandObjectException) { throw new BadRequestException("Invalid command object."); } try { dispatcher.Dispatch(userSession, command); return null; } catch (NoAvailableHandlerException) { throw new NotImplementedException("The command does not have a handler."); } }; }
private static void GenerateReLabelCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated) { if (original.DiscriptionMatches(updated)) return; dispatcher.Dispatch(new ReLabelEntityCommand(updated.Identity, new EntityName(updated.Name.Trim()))); }
private static void GenerateChangeDataTypeCommand(ICommandDispatcher dispatcher,MetadataDefinitionResource original, MetadataDefinitionResource updated) { if (original.DataTypeMatches(updated)) return; dispatcher.Dispatch(new ChangeMetadataDefinitionDataTypeCommand(updated.Identity, updated.DataType)); }
public DisasterModule(ICommandDispatcher commandDispatcher) { Post["/Disasters"] = Request => { commandDispatcher.Dispatch(this.UserSession(), this.Bind<CreateNewDisaster>()); return null; }; }
public SeverityModule(ICommandDispatcher commandDispatcher) { Post["/severity"] = r => { var voteRequest = this.Bind<VoteOnSeverityRequest>(); commandDispatcher.Dispatch(this.UserSession(), new VoteOnSeverity(voteRequest.DisasterId, voteRequest.Severity)); return null; }; }
public VoteModule(ICommandDispatcher commandDispatcher) { Post["votes/controlled"] = r => { var voteRequest = this.Bind<VoteOnControlledRequest>(); commandDispatcher.Dispatch(this.UserSession(), new VoteOnControlled(voteRequest.DisasterId, voteRequest.IsControlled)); return null; }; Post["votes/severity"] = r => { var voteRequest = this.Bind<VoteOnSeverityRequest>(); commandDispatcher.Dispatch(this.UserSession(), new VoteOnSeverity(voteRequest.DisasterId, voteRequest.Severity)); return null; }; Post["votes/putout"] = r => { var voteRequest = this.Bind<VoteOnPutOutRequest>(); commandDispatcher.Dispatch(this.UserSession(), new VoteOnPutOut(voteRequest.DisasterId, voteRequest.IsPutOut)); return null; }; }
static void DispatchCommand(ICommandDispatcher commandDispatcher, NewUserRequest newUserRequest) { commandDispatcher.Dispatch(new UserSession(), new NewUserCommand { FirstName = newUserRequest.FirstName, LastName = newUserRequest.LastName, Name = newUserRequest.Name, FacebookId = newUserRequest.FacebookId, Locale = newUserRequest.Locale, Username = newUserRequest.Username }); }
public ImageModule(ICommandDispatcher commandDispatcher) { Post["/disasters/{disasterId}/image"] = r => { var req = this.Bind<AddImageRequest>(); UserSession userSession = this.UserSession(); commandDispatcher.Dispatch(userSession, new AddImageToDisaster(Guid.Parse((string) r.disasterId), req.Base64Image)); return null; }; }
static void DispatchCommand(IPasswordEncryptor passwordEncryptor, ICommandDispatcher commandDispatcher, NewUserRequest newUserRequest) { commandDispatcher.Dispatch(new NewUserCommand { Email = newUserRequest.Email, EncryptedPassword = passwordEncryptor.Encrypt( newUserRequest.Password), AgreementVersion = newUserRequest.AgreementVersion }); }
public VerificationModule(IReadOnlyRepository readOnlyRepository, ICommandDispatcher commandDispatcher) { Post["/verify"] = r => { var input = this.Bind<VerifyAccountRequest>(); try { readOnlyRepository.First<Verification>( x => x.EmailAddress == input.Email && x.VerificationCode == input.Code); }catch(ItemNotFoundException<Verification>) { return new Response().WithStatusCode(HttpStatusCode.Unauthorized); } commandDispatcher.Dispatch(new ActivateUser(input.Email)); return new Response().WithStatusCode(HttpStatusCode.OK); }; }
public DisasterModule(ICommandDispatcher commandDispatcher) { Post["/Disasters"] = Request => { var req = this.Bind<CreateNewDisasterRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreateNewDisaster(req.LocationDescription, req.Latitude, req.Longitude, req.FirstSeverity)); return new Response().WithStatusCode(HttpStatusCode.OK); }; Post["/SendDisasterByEmail"] = Request => { var emailInfo = this.Bind<SendDisasterByEmailRequest>(); try { var _model = new Disaster(DateTime.Parse(emailInfo.CreatedDate), emailInfo.LocationDescription, double.Parse(emailInfo.Latitude), double.Parse(emailInfo.Longitude)); var sender = new EmailSender( new EmailBodyRenderer( new TemplateProvider(new List<IEmailTemplate> { new DisasterEmailTemplate( new DefaultRootPathProvider()) }), new DefaultViewEngine()) , new EmailSubjectProvider(new List<IEmailSubject> {new DisasterEmailSubject()}), new MailgunSmtpClient()); sender.Send(_model, emailInfo.Email); return new Response().WithStatusCode(HttpStatusCode.OK); } catch (Exception ex) { return new Response().WithStatusCode(HttpStatusCode.NotFound); } }; }
public void CanDispatchRegisteredCommand() { _dispatcher.Dispatch(new Command1()); }
public UserAccountModule(IReadOnlyRepository readOnlyRepository, ICommandDispatcher commandDispatcher, IPasswordEncryptor passwordEncryptor, IMappingEngine mappingEngine) { Post["/register"] = _ => { var req = this.Bind <NewUserRequest>(); var abilities = mappingEngine.Map <IEnumerable <UserAbilityRequest>, IEnumerable <UserAbility> >(req.Abilities); commandDispatcher.Dispatch(this.UserSession(), new CreateEmailLoginUser(req.Email, passwordEncryptor.Encrypt(req.Password), req.Name, req.PhoneNumber, abilities)); return(null); }; Post["/register/facebook"] = _ => { var req = this.Bind <FacebookRegisterRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreateFacebookLoginUser(req.id, req.email, req.first_name, req.last_name, req.link, req.name, req.url_image)); return(null); }; Post["/register/google"] = _ => { var req = this.Bind <GoogleRegisterRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreateGoogleLoginUser(req.id, req.email, req.name.givenName, req.name.familyName, req.url, req.displayName, req.image.url)); return(null); }; Post["/password/requestReset"] = _ => { var req = this.Bind <ResetPasswordRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreatePasswordResetToken(req.Email)); return(null); }; Put["/password/reset/{token}"] = p => { var newPasswordRequest = this.Bind <NewPasswordRequest>(); var token = Guid.Parse((string)p.token); commandDispatcher.Dispatch(this.UserSession(), new ResetPassword(token, passwordEncryptor.Encrypt(newPasswordRequest.Password))); return(null); }; Post["/user/abilites"] = p => { var requestAbilites = this.Bind <UserAbilitiesRequest>(); commandDispatcher.Dispatch(this.UserSession(), new AddAbilitiesToUser(requestAbilites.UserId, requestAbilites.Abilities.Select(x => x.Id))); return(null); }; Get["/abilities"] = _ => { var abilites = readOnlyRepository.GetAll <UserAbility>(); var mappedAbilites = mappingEngine.Map <IEnumerable <UserAbility>, IEnumerable <UserAbilityRequest> >(abilites); return(mappedAbilites); }; Get["/testStatePattern"] = _ => { var traficLight = new Domain.DesignPattern.StatePattern.TraficLight(); var process = traficLight.StartTheTraficLight(); return(process); }; Get["/testNullObjectPattern"] = _ => { var dog = new Domain.DesignPattern.NullObjectPattern.Dog(); var dougSound = "Dog Sound: " + dog.MakeSound() + ", "; var unknown = Domain.DesignPattern.NullObjectPattern.Animal.Null; var noAnimalSound = "No Animal Sound: " + unknown.MakeSound(); return(dougSound + noAnimalSound); }; Get["/testObserverPattern"] = _ => { var observable = new Domain.DesignPattern.ObserverPattern.Observable(); var observer = new Domain.DesignPattern.ObserverPattern.Observer(); observable.SomethingHappened += observer.HandleEvent; var observerValue = observable.DoSomething(); return(observerValue); }; Get["/testBridgePattern/{currentSource}"] = _ => { var currentSource = (string)_.currentSource; var myCustomTv = new Domain.DesignPattern.BridgePattern.MyCustomTv(); switch (currentSource) { case "1": myCustomTv.VideoSource = new Domain.DesignPattern.BridgePattern.LocalCableTv(); break; case "2": myCustomTv.VideoSource = new Domain.DesignPattern.BridgePattern.CableColorTv(); break; case "3": myCustomTv.VideoSource = new Domain.DesignPattern.BridgePattern.TigoService(); break; } var tvGuide = myCustomTv.ShowTvGuide(); var playVideo = myCustomTv.ShowTvGuide(); return(tvGuide + " / " + playVideo); }; }
public async Task <ActionResult> Delete( Guid id, [FromServices] ICommandDispatcher commandDispatcher) { return(Ok((await commandDispatcher.Dispatch(new DeleteBlobCommand(id)).ConfigureAwait(false)).IsSuccess)); }
public async Task <ActionResult> Delete( [FromServices] ICommandDispatcher commandDispatcher) { return(Ok(await commandDispatcher.Dispatch(new DeactivateMyProfileCommand()).ConfigureAwait(false))); }
public void Call <TCommand>(TCommand command) { _commandDispatcher.Dispatch <TCommand>(command); }
protected override void When() { _commandDispatcher.Dispatch(new CreateUser(_newUserId, "when_creating_an_new_user", "when_creating_an_new_user", "*****@*****.**", "Tolle Timezone", "Admin")); }
public async Task Run(DateTime created, string username, Guid externalId) { await _commandDispatcher.Dispatch(new DeleteWorkoutExecutionCommand { Created = created, Username = username, ExternalId = externalId }, default); }
public async Task Dispatcher_Calls_Get_Service() { await _commandDispatcher.Dispatch(new TestCommand()); _serviceProvider.Verify(x => x.GetService(It.Is <Type>(y => y == typeof(ICommandHandler <TestCommand>))), Times.Once); }
protected async Task DispatchAsync <Tcommand>(Tcommand command) where Tcommand : ICommand {/*try,catch*/ await _commandDispatcher.Dispatch(command); }
public void AddProductType([FromBody] CreateProductTypeCommand command) { _commandDispatcher.Dispatch(command); }
public void Post([FromBody] CriarAtividade criarAtividade) { _commandDispatcher.Dispatch(criarAtividade); }
public async Task On(ArticleImported @event) { await _commandDispatcher.Dispatch(new CalculateKeywordsCommand(@event.Id)); }
public async Task <ActionResult> Post([FromBody] CreateCustomerCommand command) { await _commandDispatcher.Dispatch(command); return(new OkResult()); }
// POST api/<controller> public void Post(CreateSchemaCommand cmd) { _commandDispatcher.Dispatch(cmd); //return await Task.FromResult(new HttpResponseMessage(HttpStatusCode.Created)); }
public async Task Run(string username, Guid externalId) { await _commandDispatcher.Dispatch(new DeleteWorkoutPlanCommand { Username = username, ExternalId = externalId }, default); }
public async Task <ActionResult> CreateHabitant([FromBody] Habitant habitant, [FromServices] ICommandDispatcher commandDispatcher) { await commandDispatcher.Dispatch(new CreateHabitantCommand(habitant)).ConfigureAwait(false); return(Ok()); }
public async Task Create(string _name, int _couponCode, DateTime _validationStart, DateTime _validationEnd) { await _commandDispatcher.Dispatch <CreateDiscountCoupon.Command>(new CreateDiscountCoupon.Command { Data = new CreateDiscountCoupon.Data(_name, _couponCode, _validationStart, _validationEnd) }); }
public async Task <ActionResult> DeleteHabitant(int habitantId, [FromServices] ICommandDispatcher commandDispatcher) { await commandDispatcher.Dispatch(new DeleteHabitantCommand(habitantId)).ConfigureAwait(false); return(Ok()); }
public async Task <ActionResult> Put( ProfileRequestDto profileRequestDto, [FromServices] ICommandDispatcher commandDispatcher) { return(Ok(await commandDispatcher.Dispatch(new UpdateMyProfileCommand(profileRequestDto)).ConfigureAwait(false))); }
public void DeleteFlight(string flightId) { CommandDispatcher.Dispatch(new DeleteFlightCommand(flightId)); }
public async Task <ActionResult> Post( CreateBlobRequestDto createBlobRequestDto, [FromServices] ICommandDispatcher commandDispatcher) { return(Ok((await commandDispatcher.Dispatch(new CreateBlobCommand(createBlobRequestDto.Id, createBlobRequestDto.Blob)).ConfigureAwait(false)).IsSuccess)); }
public async Task Post(CreateDollarRateCommand command) => _commandDispatcher.Dispatch(command);
public async Task <CreateUserCommandResult> Create(CreateUserCommand command) { return(await dispatcher.Dispatch <CreateUserCommand, CreateUserCommandResult>(command)); }
public IActionResult Post([FromBody] CompanyDto companyDto) { _commandDispatcher.Dispatch(new AddCompanyCommand(companyDto)); return(Ok()); }
public UserAccountModule(IReadOnlyRepository readOnlyRepository,ICommandDispatcher commandDispatcher, IPasswordEncryptor passwordEncryptor, IMappingEngine mappingEngine) { Post["/register"] = _ => { var req = this.Bind<NewUserRequest>(); var abilities = mappingEngine.Map<IEnumerable<UserAbilityRequest>, IEnumerable<UserAbility>>(req.Abilities); commandDispatcher.Dispatch(this.UserSession(), new CreateEmailLoginUser(req.Email, passwordEncryptor.Encrypt(req.Password), req.Name, req.PhoneNumber, abilities)); return null; }; Post["/register/facebook"] = _ => { var req = this.Bind<FacebookRegisterRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreateFacebookLoginUser(req.id,req.email, req.first_name, req.last_name,req.link,req.name,req.url_image)); return null; }; Post["/register/google"] = _ => { var req = this.Bind<GoogleRegisterRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreateGoogleLoginUser(req.id,req.email,req.name.givenName,req.name.familyName,req.url,req.displayName,req.image.url)); return null; }; Post["/password/requestReset"] = _ => { var req = this.Bind<ResetPasswordRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreatePasswordResetToken(req.Email) ); return null; }; Put["/password/reset/{token}"] = p => { var newPasswordRequest = this.Bind<NewPasswordRequest>(); var token = Guid.Parse((string)p.token); commandDispatcher.Dispatch(this.UserSession(), new ResetPassword(token, passwordEncryptor.Encrypt(newPasswordRequest.Password))); return null; }; Post["/user/abilites"] = p => { var requestAbilites = this.Bind<UserAbilitiesRequest>(); commandDispatcher.Dispatch(this.UserSession(), new AddAbilitiesToUser(requestAbilites.UserId, requestAbilites.Abilities.Select(x => x.Id))); return null; }; Get["/abilities"] = _ => { var abilites = readOnlyRepository.GetAll<UserAbility>(); var mappedAbilites = mappingEngine.Map<IEnumerable<UserAbility>, IEnumerable<UserAbilityRequest>>(abilites); return mappedAbilites; }; }
public UserAccountModule(IReadOnlyRepository readOnlyRepository, ICommandDispatcher commandDispatcher, IPasswordEncryptor passwordEncryptor, IMappingEngine mappingEngine) { Post["/register"] = _ => { var req = this.Bind <NewUserRequest>(); var abilities = mappingEngine.Map <IEnumerable <UserAbilityRequest>, IEnumerable <UserAbility> >(req.Abilities); commandDispatcher.Dispatch(this.UserSession(), new CreateEmailLoginUser(req.Email, passwordEncryptor.Encrypt(req.Password), req.Name, req.PhoneNumber, abilities)); return(null); }; Post["/register/facebook"] = _ => { var req = this.Bind <FacebookRegisterRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreateFacebookLoginUser(req.id, req.email, req.first_name, req.last_name, req.link, req.name, req.url_image)); return(null); }; Post["/register/google"] = _ => { var req = this.Bind <GoogleRegisterRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreateGoogleLoginUser(req.id, req.email, req.name.givenName, req.name.familyName, req.url, req.displayName, req.image.url)); return(null); }; Post["/password/requestReset"] = _ => { var req = this.Bind <ResetPasswordRequest>(); commandDispatcher.Dispatch(this.UserSession(), new CreatePasswordResetToken(req.Email)); return(null); }; Put["/password/reset/{token}"] = p => { var newPasswordRequest = this.Bind <NewPasswordRequest>(); var token = Guid.Parse((string)p.token); commandDispatcher.Dispatch(this.UserSession(), new ResetPassword(token, passwordEncryptor.Encrypt(newPasswordRequest.Password))); return(null); }; Post["/user/abilites"] = p => { var requestAbilites = this.Bind <UserAbilitiesRequest>(); commandDispatcher.Dispatch(this.UserSession(), new AddAbilitiesToUser(requestAbilites.UserId, requestAbilites.Abilities.Select(x => x.Id))); return(null); }; Get["/abilities"] = _ => { var abilites = readOnlyRepository.GetAll <UserAbility>(); var mappedAbilites = mappingEngine.Map <IEnumerable <UserAbility>, IEnumerable <UserAbilityRequest> >(abilites); return(mappedAbilites); }; }
public void RemoveQuestionAnswer(QuestionAnswer questionAnswer) { _commandDispatcher.Dispatch(new RemoveAnswerCommand { QuestionAnswerId = questionAnswer.QuestionAnswerId }); }
public async Task CreateDollarPrice(CreateDollarRateCommand createDollarRateCommand) => _commandDispatcher.Dispatch(createDollarRateCommand);
public async Task Run(string username, WorkoutExecutionDTO workoutExecutionDTO) { await _commandDispatcher.Dispatch(new AddWorkoutExecutionCommand { Username = username, Workout = workoutExecutionDTO }, default); }
public async Task Run(string username, WorkoutPlanPersistanceDTO workoutPlanPersistanceDTO) { await _commandDispatcher.Dispatch(new AddWorkoutPlanCommand { Username = username, WorkoutPlan = workoutPlanPersistanceDTO }, default); }
public AdminModule(IReadOnlyRepository readOnlyRepository, IMappingEngine mappingEngine, ICommandDispatcher commandDispatcher) { Get["/users"] = _ => { this.RequiresClaims(new[] { "Administrator" }); var request = this.Bind<AdminUsersRequest>(); var parameter = Expression.Parameter(typeof(User), "User"); var mySortExpression = Expression.Lambda<Func<User, object>>(Expression.Property(parameter, request.Field), parameter); IQueryable<User> users = readOnlyRepository.Query<User>(x => x.Name != this.UserLoginSession().User.Name).AsQueryable(); var orderedUsers = users.OrderBy(mySortExpression); IQueryable<User> pagedUsers = orderedUsers.Skip(request.PageSize * (request.PageNumber - 1)).Take(request.PageSize); List<AdminUserResponse> mappedItems = mappingEngine .Map<IQueryable<User>, IEnumerable<AdminUserResponse>>(pagedUsers).ToList(); return new AdminUsersListResponse(mappedItems); }; Post["/users/enable"] = _ => { this.RequiresClaims(new[] {"Administrator"}); var request = this.Bind<AdminEnableUsersRequest>(); if (request.Enable) { commandDispatcher.Dispatch(this.UserSession(), new EnableUser(request.Id)); } else { commandDispatcher.Dispatch(this.UserSession(), new DisableUser(request.Id)); } return null; }; Get["/user/{userId}"] = _ => { var userId = Guid.Parse((string)_.userId); var user = readOnlyRepository.GetById<User>(userId); var mappedUser = mappingEngine .Map<User, AdminUserResponse>(user); return mappedUser; }; Post["/user"] = _ => { var request = this.Bind<AdminUpdateUserRequest>(); commandDispatcher.Dispatch(this.UserSession(), new UpdateUserProfile(request.Id, request.Name, request.Email)); return null; }; }
public async Task <CreateIssueCommandResult> Create(CreateIssueCommand command) { return(await commandDispatcher.Dispatch <CreateIssueCommand, CreateIssueCommandResult>(command)); }