Exemplo n.º 1
0
        public IActionResult Index(int year)
        {
            Func <string, IDictionary <string, object>, IEnumerable <WorldCupFsharpRepositoryModule.WorldCupDto> >
            readDataFunc = (s, p) => _postgresConnection.readData <WorldCupFsharpRepositoryModule.WorldCupDto>(s,
                                                                                                               p);

            var readData = FuncConvert.FromFunc(readDataFunc);

            var worldCupFsharpOption = WorldCupFsharpRepositoryModule.findByYear(readData, YearModule.create(year));

            if (worldCupFsharpOption.HasValue())
            {
                var worldCupFsharp = worldCupFsharpOption.Value;

                var worldCupVm = new WorldCupVm
                {
                    Year   = YearModule.value(worldCupFsharp.Year),
                    Host   = WorldCupHostModule.value(worldCupFsharp.Host),
                    Winner = CountryModule.value(worldCupFsharp.Winner)
                };

                return(Content(JsonConvert.SerializeObject(worldCupVm), "application/json"));
            }

            return(NotFound());
        }
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 WorldCupCsharp FindByYear(int year)
 {
     try
     {
         var readStatement =
             @"
         select id, year, host_country as host, winner
         from world_cup
         where year = @year";
         return(_postgresConnection.readData <WorldCupCsharp>(readStatement, new
         {
             year
         }).Single());
     }
     catch (Exception ex)
     {
         return(null);
     }
 }