Guest User

Untitled

a guest
Feb 16th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. using System.ComponentModel.DataAnnotations;
  2.  
  3. namespace WeatherViewer.Models
  4. {
  5. public partial class DlMainWeather
  6. {
  7. [DataType(DataType.DateTime)]
  8. [Required]
  9. public DateTime TmStamp { get; set; }
  10. public double? AirTempAvg { get; set; }
  11. }
  12. }
  13.  
  14. using System;
  15. using Microsoft.EntityFrameworkCore;
  16.  
  17. namespace WeatherViewer.Models
  18. {
  19. public partial class TelemetryDataContext : DbContext
  20. {
  21. public TelemetryDataContext()
  22. {
  23. }
  24.  
  25. public TelemetryDataContext(DbContextOptions<TelemetryDataContext> options)
  26. : base(options)
  27. {
  28. }
  29.  
  30. public virtual DbSet<DlMainWeather> DlMainWeather { get; set; }
  31.  
  32. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  33. {
  34. if (!optionsBuilder.IsConfigured)
  35. {
  36. optionsBuilder.UseSqlServer("connectionstring");
  37. }
  38. }
  39.  
  40. protected override void OnModelCreating(ModelBuilder modelBuilder)
  41. {
  42. modelBuilder.HasAnnotation("ProductVersion", "2.2.2-servicing-10034");
  43.  
  44.  
  45. modelBuilder.Entity<DlMainWeather>(entity =>
  46. {
  47. entity.HasKey(e => new { e.TmStamp,})
  48. .HasName("PK__DL_MAIN___B3E4C26B9637DE80");
  49.  
  50. entity.ToTable("DL_MAIN_Weather");
  51.  
  52. entity.Property(e => e.AirTempAvg).HasColumnName("AirTemp_Avg");
  53.  
  54. });
  55.  
  56. }
  57. }
  58. }
  59.  
  60. using System;
  61. using System.Collections.Generic;
  62. using System.Linq;
  63.  
  64.  
  65. namespace WeatherViewer.Models
  66. {
  67. public class WeatherDataAccessLayer
  68. {
  69. TelemetryDataContext db = new TelemetryDataContext();
  70. public IEnumerable<DlMainWeather> GetTemperatures(double backtime)
  71. {
  72. IEnumerable<DlMainWeather> temparray = db.DlMainWeather
  73. .Where(dt => dt.TmStamp.Date > DateTime.Now.AddHours(-backtime))
  74. .Select(dt => new { dt.TmStamp.Date, dt.AirTempAvg });
  75. return temparray;
  76. }
  77. }
  78. }
  79.  
  80. using System.Collections.Generic;
  81. using System.Linq;
  82. using Microsoft.AspNetCore.Mvc;
  83. using WeatherViewer.Models;
  84.  
  85. namespace WeatherViewer.Controllers
  86. {
  87.  
  88. public class WeatherController : Controller
  89. {
  90. WeatherDataAccessLayer weatherobj = new WeatherDataAccessLayer();
  91.  
  92. public IActionResult Index()
  93. {
  94. return View();
  95. }
  96.  
  97. public ActionResult TemperatureSummary()
  98. {
  99. return PartialView("_TemperatureReport");
  100. }
  101.  
  102. public JsonResult TemperatureReturn()
  103. {
  104. List<DlMainWeather> temparray = new List<DlMainWeather>();
  105. temparray = weatherobj.GetTemperatures(12).ToList();
  106. return new JsonResult(temparray);
  107. }
  108. }
  109. }
Add Comment
Please, Sign In to add comment