Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "WorldCup API", Version = "v1"
                });
            });

            services.AddSingleton <IPostgresConnection, PostgresConnection>();
            services.AddSingleton <IWorldCupRepositoryCSharpV0, WorldCupRepositoryCSharpV0>();
            services.AddSingleton <IWorldCupRepositoryCSharpV1, WorldCupRepositoryCSharpV1>();
            services.AddSingleton <IWorldCupRepository, WorldCupRepository>();

            services.AddSingleton <ICreateWorldCupWorkflow>(s =>
            {
                var worldCupRepoService = s.GetService <IWorldCupRepository>();

                return(new CreateWorldCupWorkflow(
                           generateId: () => WorldCupId.NewWorldCupId(Guid.NewGuid()),
                           findWorldCup: year => worldCupRepoService.FindByYear(year),
                           saveWorldCup: wc => worldCupRepoService.Save(wc)
                           ));
            });
        }
Exemplo n.º 2
0
        public WorldCupFsharp FindByYear(int year)
        {
            try
            {
                var readStatement =
                    @"
                select id, year, host_country as hostCountry, winner
                from world_cup
                where year = @year";
                var result = _postgresConnection.readData <WorldCupFsharpDto>(readStatement, new
                {
                    year
                }).Single();

                return(new WorldCupFsharp(
                           WorldCupId.NewWorldCupId(result.Id),
                           YearModule.create(result.Year),
                           WorldCupHost.NewHost(Country.NewCountry(result.HostCountry)),
                           Country.NewCountry(result.Winner)
                           ));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public void Post([FromBody] WorldCupVm wc)
        {
            var worldCupCsharp = new WorldCupFsharp(
                WorldCupId.NewWorldCupId(Guid.NewGuid()),
                YearModule.create(wc.Year),
                WorldCupHostModule.create(wc.Host),
                Country.NewCountry(wc.Winner)
                );

            _worldCupRepositoryCSharpV1.Save(worldCupCsharp);
        }
Exemplo n.º 4
0
        public void Post([FromBody] WorldCupVm wc)
        {
            var worldCupFsharpToSave = new WorldCupFsharp(
                WorldCupId.NewWorldCupId(Guid.NewGuid()),
                YearModule.create(wc.Year),
                WorldCupHostModule.create(wc.Host),
                Country.NewCountry(wc.Winner)
                );

            Action <string, IDictionary <string, object> > writeData = _postgresConnection.writeData;
            var fSharpWriteData = FuncConvert.FromAction(writeData);


            WorldCupFsharpRepositoryModule.save(fSharpWriteData, worldCupFsharpToSave);
        }