public static List<ApiConfiguration> Get(IHandleGettingConfiguration configuration, IHandleGettingIntegrationClient client)
 {
     var config = new GetAllConfigurations();
     var clientCommand = new GetIntegrationClients();
     configuration.Handle(config);
     client.Handle(clientCommand);
     return config.Configurations.Select(s => new ApiConfiguration(s, clientCommand.Clients.FirstOrDefault(w => w.Id == s.ClientId))).ToList();
 }
 public void SetWeekdays(IHandleGettingConfiguration handler, GetWeekdays command)
 {
     handler.Handle(command);
     Weekdays = command.Weekdays.ToList();
 }
 public void SetFrequency(IHandleGettingConfiguration handler, GetFrequencyTypes command)
 {
     handler.Handle(command);
     Frequency = command.Frequency.ToList();
 }
 public void SetAuthentication(IHandleGettingConfiguration handler, GetAuthenticationTypes command)
 {
     handler.Handle(command);
     Authentication = command.Authentication.ToList();
 }
 public static PushConfiguration Existing(IHandleGettingConfiguration handler, GetApiPushConfiguration command)
 {
     handler.Handle(command);
     return new PushConfiguration(command.Configuration);
 }
 public void SetFrequency(IHandleGettingConfiguration handler)
 {
     var command = new GetFrequencyTypes();
     handler.Handle(command);
     Frequency = command.Frequency.ToList();
 }
 public void SetAuthentication(IHandleGettingConfiguration handler)
 {
     var command = new GetAuthenticationTypes();
     handler.Handle(command);
     Authentication = command.Authentication.ToList();
 }
        public ApiModule(IHandleGettingConfiguration setup, IHandleSavingConfiguration save, IHandleGettingIntegrationClient client,
            IUserManagementApiClient api, IHandleGettingDataPlatformClient dataPlatform, IHandleGettingMetadata metadata)
        {
            this.RequiresAnyClaim(new[] { RoleType.Admin.ToString(), RoleType.ProductManager.ToString(), RoleType.Support.ToString() });

            Get["/integrations/for/api/push"] = _ =>
            {
                var model = PushConfiguration.Create();
                var token = Context.Request.Headers.Authorization.Any() ? Context.Request.Headers.Authorization.Split(' ')[1] : string.Empty;
                model.SetFrequency(setup, new GetFrequencyTypes());
                model.SetAuthentication(setup, new GetAuthenticationTypes());
                model.SetDataPlatformClients(dataPlatform, new GetDataPlatformClients(api, token));
                model.SetWeekdays(setup, new GetWeekdays());
                model.SetIntegrationClients(client, new GetIntegrationClients());
                return View["integrations/api/push", model];
            };

            Get["/integrations/for/api/push/edit/{id}/{clientId}"] = _ =>
                {
                    int id;
                    int clientId;

                    int.TryParse(_.Id, out id);
                    int.TryParse(_.clientId, out clientId);

                    if (id == 0 || clientId == 0)
                        return HttpStatusCode.NoResponse;

                    var token = Context.Request.Headers.Authorization.Any() ? Context.Request.Headers.Authorization.Split(' ')[1] : string.Empty;
                    var model = PushConfiguration.Existing(setup, new GetApiPushConfiguration(id, clientId));
                    model.SetFrequency(setup, new GetFrequencyTypes());
                    model.SetAuthentication(setup, new GetAuthenticationTypes());
                    model.SetDataPlatformClients(dataPlatform, new GetDataPlatformClients(api, token));
                    model.SetWeekdays(setup, new GetWeekdays());
                    model.SetIntegrationClients(client, new GetIntegrationClients());
                    return View["integrations/api/push", model];
                };

            Post["/integrations/for/api/push/save"] = _ =>
            {
                var configuration = this.Bind<PushConfiguration>();
                var token = Context.Request.Headers.Authorization.Any() ? Context.Request.Headers.Authorization.Split(' ')[1] : string.Empty;
                configuration.SetDataPlatformClients(dataPlatform, new GetDataPlatformClients(api, token));
                var command = new AddApiPushConfiguration(configuration);
                save.Handle(command);
                return Response.AsRedirect("/integrations/for/api/configurations");
            };

            Get["/integrations/for/api/pull"] = _ =>
            {
                var model = PullConfiguration.Create();
                model.SetAuthentication(setup);
                model.SetFrequency(setup);
                model.SetWeekdays(setup, new GetWeekdays());
                model.SetIntegrationClients(client, new GetIntegrationClients());
                return View["integrations/api/pull", model];
            };

            Get["/integrations/for/api/configurations"] = _ => View["integrations/api/configurations", ApiConfiguration.Get(setup, client)];

            Get["/integrations/for/api/metadata/push"] = _ =>
            {
                var command = new GetApiResponseMetadataCommand();
                metadata.Handle(command);
                return View["integrations/api/pushmetadata", command.Metadata];
            };
        }