AlarmPointService.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Dynamic.Core;
  5. using FMSAdmin.Data;
  6. using FMSAdmin.Helpers;
  7. using FMSAdmin.Entities;
  8. using Microsoft.Extensions.Logging;
  9. using FMSAdmin.Models;
  10. using System.Linq.Expressions;
  11. using LinqKit;
  12. namespace FMSApp.Services {
  13. public class AlarmPointService {
  14. private readonly ILogger<AlarmPointService> _logger;
  15. private readonly FMSContext _context;
  16. public AlarmPointService(
  17. ILogger<AlarmPointService> logger,
  18. FMSContext context) {
  19. _logger = logger;
  20. _context = context;
  21. }
  22. public void Create(FmsAlarmPoint data) {
  23. _context.FmsAlarmPoint.Add(data);
  24. _context.SaveChanges();
  25. }
  26. public IQueryable<FmsAlarmPoint> GetAll() {
  27. var query = _context.FmsAlarmPoint;
  28. return query;
  29. }
  30. public FmsAlarmPoint Get(int siteId, int facilityTypeId, int facilityCode, int propertyId) {
  31. var data = _context.FmsAlarmPoint
  32. .Where(x => x.SiteId == siteId
  33. && x.FacilityTypeId == facilityTypeId
  34. && x.FacilityCode == facilityCode
  35. && x.PropertyId == propertyId).FirstOrDefault();
  36. return data;
  37. }
  38. public IQueryable<FmsAlarmPoint> Gets(int id, int siteId) {
  39. var data = _context.FmsAlarmPoint.Where(x => x.SiteId == siteId);
  40. return data;
  41. }
  42. public void Delete(int siteId, int facilityTypeId, int facilityCode, int propertyId) {
  43. var data = _context.FmsAlarmPoint.First(x => x.SiteId == siteId
  44. && x.FacilityTypeId == facilityTypeId
  45. && x.FacilityCode == facilityCode
  46. && x.PropertyId == propertyId);
  47. _context.FmsAlarmPoint.Remove(data);
  48. _context.SaveChanges();
  49. }
  50. public IQueryable<BemsMonitoringPointHistory15min> GetPointHistoryList(int siteId) {
  51. var query =
  52. from x in _context.BemsMonitoringPointHistory15min
  53. where x.FmsAlarmPoint.SiteId == siteId
  54. select x;
  55. return query;
  56. }
  57. public IQueryable<FmsAlarmLog> GetAlarmLog(int siteId) {
  58. var query =
  59. from x in _context.FmsAlarmLog
  60. where x.AlarmPoint.SiteId == siteId
  61. select x;
  62. return query;
  63. }
  64. }
  65. }