Exemplo n.º 1
0
        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;
                };
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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);
                                    }
                                };
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 12
0
        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.");
                                    }
                                };
        }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 15
0
 public DisasterModule(ICommandDispatcher commandDispatcher)
 {
     Post["/Disasters"] =
         Request =>
             {
                 commandDispatcher.Dispatch(this.UserSession(), this.Bind<CreateNewDisaster>());
                 return null;
             };
 }
Exemplo n.º 16
0
 public SeverityModule(ICommandDispatcher commandDispatcher)
 {
     Post["/severity"] = r =>
         {
             var voteRequest = this.Bind<VoteOnSeverityRequest>();
             commandDispatcher.Dispatch(this.UserSession(), new VoteOnSeverity(voteRequest.DisasterId, voteRequest.Severity));
             return null;
         };
 }
Exemplo n.º 17
0
 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;
         };
 }
Exemplo n.º 18
0
 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                                                                  
                                                       });
 }
Exemplo n.º 19
0
 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;
             };
 }
Exemplo n.º 20
0
 static void DispatchCommand(IPasswordEncryptor passwordEncryptor, ICommandDispatcher commandDispatcher,
                             NewUserRequest newUserRequest)
 {
     commandDispatcher.Dispatch(new NewUserCommand
                                    {
                                        Email = newUserRequest.Email,
                                        EncryptedPassword =
                                            passwordEncryptor.Encrypt(
                                                newUserRequest.Password),
                                        AgreementVersion =
                                            newUserRequest.AgreementVersion
                                    });
 }
Exemplo n.º 21
0
 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);
                           };
 }
Exemplo n.º 22
0
        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);
            };
        }
Exemplo n.º 25
0
 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)));
 }
Exemplo n.º 27
0
 public void Call <TCommand>(TCommand command)
 {
     _commandDispatcher.Dispatch <TCommand>(command);
 }
Exemplo n.º 28
0
 protected override void When()
 {
     _commandDispatcher.Dispatch(new CreateUser(_newUserId, "when_creating_an_new_user", "when_creating_an_new_user", "*****@*****.**", "Tolle Timezone", "Admin"));
 }
Exemplo n.º 29
0
 public async Task Run(DateTime created, string username, Guid externalId)
 {
     await _commandDispatcher.Dispatch(new DeleteWorkoutExecutionCommand { Created = created, Username = username, ExternalId = externalId }, default);
 }
Exemplo n.º 30
0
        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);
        }
Exemplo n.º 31
0
 protected async Task DispatchAsync <Tcommand>(Tcommand command) where Tcommand : ICommand
 {/*try,catch*/
     await _commandDispatcher.Dispatch(command);
 }
Exemplo n.º 32
0
 public void AddProductType([FromBody] CreateProductTypeCommand command)
 {
     _commandDispatcher.Dispatch(command);
 }
Exemplo n.º 33
0
 public void Post([FromBody] CriarAtividade criarAtividade)
 {
     _commandDispatcher.Dispatch(criarAtividade);
 }
Exemplo n.º 34
0
 public async Task On(ArticleImported @event)
 {
     await _commandDispatcher.Dispatch(new CalculateKeywordsCommand(@event.Id));
 }
Exemplo n.º 35
0
        public async Task <ActionResult> Post([FromBody] CreateCustomerCommand command)
        {
            await _commandDispatcher.Dispatch(command);

            return(new OkResult());
        }
Exemplo n.º 36
0
 // POST api/<controller>
 public void Post(CreateSchemaCommand cmd)
 {
     _commandDispatcher.Dispatch(cmd);
     //return await Task.FromResult(new HttpResponseMessage(HttpStatusCode.Created));
 }
Exemplo n.º 37
0
 public async Task Run(string username, Guid externalId)
 {
     await _commandDispatcher.Dispatch(new DeleteWorkoutPlanCommand { Username = username, ExternalId = externalId }, default);
 }
Exemplo n.º 38
0
        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)
     });
 }
Exemplo n.º 40
0
        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));
 }
Exemplo n.º 43
0
 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);
Exemplo n.º 45
0
 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());
        }
Exemplo n.º 47
0
        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;
            };
        }
Exemplo n.º 48
0
        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);
            };
        }
Exemplo n.º 49
0
 public void RemoveQuestionAnswer(QuestionAnswer questionAnswer)
 {
     _commandDispatcher.Dispatch(new RemoveAnswerCommand {
         QuestionAnswerId = questionAnswer.QuestionAnswerId
     });
 }
Exemplo n.º 50
0
 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);
 }
Exemplo n.º 53
0
        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;
                };

            

        }
Exemplo n.º 54
0
 public async Task <CreateIssueCommandResult> Create(CreateIssueCommand command)
 {
     return(await commandDispatcher.Dispatch <CreateIssueCommand, CreateIssueCommandResult>(command));
 }