SiteService.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IdentityModel.Tokens.Jwt;
  4. using System.Linq;
  5. using System.Security.Claims;
  6. using System.Text;
  7. using FMSAdmin.Data;
  8. using FMSAdmin.Helpers;
  9. using FMSAdmin.Entities;
  10. using Microsoft.EntityFrameworkCore;
  11. using Microsoft.Extensions.Logging;
  12. using Microsoft.Extensions.Options;
  13. using Microsoft.IdentityModel.Tokens;
  14. using FMSAdmin.Models;
  15. namespace FMSApp.Services {
  16. public class SiteService {
  17. private readonly ILogger<SiteService> _logger;
  18. private readonly FMSContext _context;
  19. private readonly AppSettings _appSettings;
  20. public SiteService(
  21. ILogger<SiteService> logger,
  22. FMSContext context,
  23. IOptions<AppSettings> appSettings) {
  24. _logger = logger;
  25. _context = context;
  26. _appSettings = appSettings.Value;
  27. }
  28. public void Save(CmSite data) {
  29. var persist = _context.CmSite
  30. .Where(x => x.SiteId == data.SiteId).FirstOrDefault();
  31. if (persist == null) {
  32. var check = _context.CmSite.Where(x => x.SiteId == data.SiteId).Count();
  33. if (check > 0) {
  34. throw new ServiceException("아이디가 중복됩니다.");
  35. }
  36. _context.CmSite.Add(data);
  37. _context.SaveChanges();
  38. } else {
  39. persist.IsUse = data.IsUse;
  40. persist.IsControlSchedule = data.IsControlSchedule;
  41. //
  42. _context.SaveChanges();
  43. }
  44. }
  45. public IQueryable<CmSite> GetAll() {
  46. var query = _context.CmSite;
  47. return query;
  48. }
  49. public IQueryable<CmSite> Get(int siteId) {
  50. var data = _context.CmSite.Where(x => x.SiteId == siteId);
  51. return data;
  52. }
  53. }
  54. }