コード例 #1
0
        public ForecastController(ForecastContext context)
        {
            _context = context;
            //Don't return anything yet... I don't know what to do with this context.

            // _context.ForecastItems.ToList();
        }
コード例 #2
0
 public async Task <City> GetCityAsync(string name)
 {
     using (var context = new ForecastContext(_connectionString))
     {
         return(await context.Cities.SingleOrDefaultAsync(city => city.Name.ToLower() == name.ToLower()));
     }
 }
コード例 #3
0
 public IList <Schedule> GetAllSchedules()
 {
     using (var context = new ForecastContext())
     {
         return(context.Schedules.ToList());
     }
 }
コード例 #4
0
 public Schedule GetSchedule(int scheduleId)
 {
     using (var context = new ForecastContext())
     {
         return(context.Schedules.Find(scheduleId));
     }
 }
コード例 #5
0
 public async Task <IEnumerable <City> > GetCitiesAsync()
 {
     using (var context = new ForecastContext(_connectionString))
     {
         return(await context.Cities.ToArrayAsync());
     }
 }
コード例 #6
0
 public Schedule UpdateSchedule(int scheduleId, Schedule schedule)
 {
     using (var context = new ForecastContext())
     {
         var origSchedule = context.Schedules.Find(scheduleId);
         if (origSchedule.Name != schedule.Name)
         {
             origSchedule.Name = schedule.Name;
         }
         if (origSchedule.Amount != schedule.Amount)
         {
             origSchedule.Amount = schedule.Amount;
         }
         if (origSchedule.ScheduleType != schedule.ScheduleType)
         {
             origSchedule.ScheduleType = schedule.ScheduleType;
         }
         if (origSchedule.Value != schedule.Value)
         {
             origSchedule.Value = schedule.Value;
         }
         if (origSchedule.Begin != schedule.Begin)
         {
             origSchedule.Begin = schedule.Begin;
         }
         if (origSchedule.End != schedule.End)
         {
             origSchedule.End = schedule.End;
         }
         context.SaveChanges();
         return(origSchedule);
     }
 }
コード例 #7
0
 public async Task AddForecastAsync(Context.Models.Forecast forecast)
 {
     using (var context = new ForecastContext(_connectionString))
     {
         context.Forecasts.Add(forecast);
         await context.SaveChangesAsync();
     }
 }
コード例 #8
0
 public Schedule AddSchedule(Schedule schedule)
 {
     using (var context = new ForecastContext())
     {
         context.Schedules.Add(schedule);
         context.SaveChanges();
     }
     return(schedule);
 }
コード例 #9
0
 public void DeleteSchedule(int scheduleId)
 {
     using (var context = new ForecastContext())
     {
         var schedule = context.Schedules.Find(scheduleId);
         context.Schedules.Remove(schedule);
         context.SaveChanges();
     }
 }
コード例 #10
0
 public async Task <DayForecast> GetDayForecastAsync(int cityId, DateTime date)
 {
     using (var context = new ForecastContext(_connectionString))
     {
         return(await context.DayForecasts
                .Where(df => df.Date == date.Date && df.CityForecast.City.Id == cityId)
                .OrderByDescending(df => df.Id)
                .FirstOrDefaultAsync());
     }
 }
コード例 #11
0
 private void PullDataFromDb()
 {
     using (var db = new ForecastContext())
     {
         db.Database.EnsureCreated();
         foreach (var item in db.Items)
         {
             Items.Add(new ForecastItem(_forecastService, item));
         }
     }
 }
コード例 #12
0
        public IList <Schedule> GetActiveSchedules()
        {
            var now = DateTime.UtcNow;

            using (var context = new ForecastContext())
            {
                return(context.Schedules
                       .Where(s => (s.Begin == null || s.Begin <= now) && (s.End == null || s.End >= now))
                       .ToList());
            }
        }
コード例 #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ForecastContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            //var context = app.ApplicationServices.GetService<ForecastContext>();
            //GenerateTestData(context);

            app.UseHttpsRedirection();
            app.UseMvc();

            app.UseDefaultFiles();
            app.UseStaticFiles();
        }
コード例 #14
0
        private void GenerateTestData(ForecastContext context)
        {
            //var sweden = new Country
            //{
            //  CountryId = 1,
            //  Name = "Sverige",
            //  CountryCode = "SV"
            //};

            //var stockholm = new City
            //{
            //  CityId = 2673730,
            //  Name = "Stockholm",
            //  CountryId = 1
            //};

            //context.Countries.Add(sweden);
            //context.Cities.Add(stockholm);

            //context.SaveChanges();
        }
コード例 #15
0
 public GenericRepository(ForecastContext context)
 {
     Context = context;
     Set     = Context.Set <T>();
 }
コード例 #16
0
 public WeatherForecastController(ILogger <WeatherForecastController> logger, ForecastContext ctx)
 {
     _logger = logger;
     _ctx    = ctx;
 }
コード例 #17
0
 public ValorForecastRepository(ForecastContext context, IVariablesToken variables)
 {
     _context   = context;
     _variables = variables;
     DbSet      = _context.Set <ValorForecast>();
 }
コード例 #18
0
 public GismeteoService()
 {
     _context        = new ForecastContext();
     _gismeteoParser = new GismeteoParser();
 }
コード例 #19
0
 public ForecastController(ForecastContext context)
 {
     Context = context;
 }
コード例 #20
0
 public CityRepository(ForecastContext context) : base(context)
 {
 }
コード例 #21
0
 public ForecastTransferService()
 {
     _context = new ForecastContext();
 }
コード例 #22
0
 public HistoryRepository(ForecastContext context)
 {
     _context = context;
 }
コード例 #23
0
 public UnitOfWork(ForecastContext context)
 {
     _context = context;
 }
コード例 #24
0
 public CityRepository(ForecastContext context)
 {
     _context = context;
 }
コード例 #25
0
 public BaseRepository(ForecastContext context, IVariablesToken variables)
 {
     _context   = context;
     _variables = variables;
     DbSet      = _context.Set <TEntity>();
 }
コード例 #26
0
 public ForecastController(IForecastService forecastService, ForecastContext context)
 {
     _forecastService = forecastService;
     _context         = context;
 }