コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var config = new MongoDBConfig();

            Configuration.Bind(config);

            #region Statistics
            var statisticsContext    = new StatisticsContext(config);
            var statisticsRepository = new StatisticsRepository(statisticsContext);
            services.AddSingleton <StatisticsRepository>(statisticsRepository);
            #endregion

            var statistics = statisticsRepository.GetAll().GetAwaiter().GetResult();
            if (statistics.Count() == 0)
            {
                this.seedDefaultStatisticsObject(statisticsRepository);
            }

            services.AddControllers();
            services.AddCors(options =>
            {
                options.AddPolicy(MyAllowSpecificOrigins,
                                  builder =>
                {
                    builder.WithOrigins("http://localhost:4200")
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });
        }
コード例 #2
0
        public async Task <ActionResult <Statistics> > Get()
        {
            var Statistics = await _statisticsRepository.GetAll();

            return(new ObjectResult(Statistics.FirstOrDefault()));
        }
コード例 #3
0
 public IEnumerable <Statistics> GetAllStatistics()
 {
     return(statisticsRepository.GetAll());
 }