示例#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());
        }
示例#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);
        }
示例#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);
        }
示例#5
0
        public void Save(WorldCupFsharp worldCup)
        {
            var saveStatement =
                @"
                insert into world_cup
                    (id, year, host_country, winner)
                values
                    (@id, @year, @hostCountry, @winner);";

            _postgresConnection.writeData(saveStatement,
                                          new
            {
                WorldCupId  = WorldCupIdModule.value(worldCup.Id),
                Year        = YearModule.value(worldCup.Year),
                HostCountry = WorldCupHostModule.value(worldCup.Host),
                Winner      = CountryModule.value(worldCup.Winner)
            });
        }
        public IActionResult Index(int year)
        {
            var worldCupFSharp = _worldCupRepositoryCSharpV1.FindByYear(year);

            if (worldCupFSharp == null)
            {
                return(NotFound());
            }

            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"));
        }
        public IActionResult Index(int year)
        {
            var worldCupFsharpOption = _worldCupRepository.FindByYear(YearModule.create(year));

            if (OptionModule.IsSome(worldCupFsharpOption)) //you'll get access to Option, List, etc module options as well
            {
                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());
        }