Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.ComponentModel.DataAnnotations;
- namespace WeatherViewer.Models
- {
- public partial class DlMainWeather
- {
- [DataType(DataType.DateTime)]
- [Required]
- public DateTime TmStamp { get; set; }
- public double? AirTempAvg { get; set; }
- }
- }
- using System;
- using Microsoft.EntityFrameworkCore;
- namespace WeatherViewer.Models
- {
- public partial class TelemetryDataContext : DbContext
- {
- public TelemetryDataContext()
- {
- }
- public TelemetryDataContext(DbContextOptions<TelemetryDataContext> options)
- : base(options)
- {
- }
- public virtual DbSet<DlMainWeather> DlMainWeather { get; set; }
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- if (!optionsBuilder.IsConfigured)
- {
- optionsBuilder.UseSqlServer("connectionstring");
- }
- }
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.HasAnnotation("ProductVersion", "2.2.2-servicing-10034");
- modelBuilder.Entity<DlMainWeather>(entity =>
- {
- entity.HasKey(e => new { e.TmStamp,})
- .HasName("PK__DL_MAIN___B3E4C26B9637DE80");
- entity.ToTable("DL_MAIN_Weather");
- entity.Property(e => e.AirTempAvg).HasColumnName("AirTemp_Avg");
- });
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace WeatherViewer.Models
- {
- public class WeatherDataAccessLayer
- {
- TelemetryDataContext db = new TelemetryDataContext();
- public IEnumerable<DlMainWeather> GetTemperatures(double backtime)
- {
- IEnumerable<DlMainWeather> temparray = db.DlMainWeather
- .Where(dt => dt.TmStamp.Date > DateTime.Now.AddHours(-backtime))
- .Select(dt => new { dt.TmStamp.Date, dt.AirTempAvg });
- return temparray;
- }
- }
- }
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.AspNetCore.Mvc;
- using WeatherViewer.Models;
- namespace WeatherViewer.Controllers
- {
- public class WeatherController : Controller
- {
- WeatherDataAccessLayer weatherobj = new WeatherDataAccessLayer();
- public IActionResult Index()
- {
- return View();
- }
- public ActionResult TemperatureSummary()
- {
- return PartialView("_TemperatureReport");
- }
- public JsonResult TemperatureReturn()
- {
- List<DlMainWeather> temparray = new List<DlMainWeather>();
- temparray = weatherobj.GetTemperatures(12).ToList();
- return new JsonResult(temparray);
- }
- }
- }
Add Comment
Please, Sign In to add comment