FloorService.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 FloorService {
  17. private readonly ILogger<FloorService> _logger;
  18. private readonly FMSContext _context;
  19. private readonly AppSettings _appSettings;
  20. public FloorService(
  21. ILogger<FloorService> logger,
  22. FMSContext context,
  23. IOptions<AppSettings> appSettings) {
  24. _logger = logger;
  25. _context = context;
  26. _appSettings = appSettings.Value;
  27. }
  28. public void Save(CmFloor data) {
  29. var persist = _context.CmFloor
  30. .Where(x => x.SiteId == data.SiteId
  31. && x.BuildingId == data.BuildingId
  32. && x.FloorId == data.FloorId).FirstOrDefault();
  33. if (persist == null) {
  34. var check = _context.CmFloor.Where(x => x.SiteId == data.SiteId
  35. && x.BuildingId == data.BuildingId
  36. && x.FloorId == data.FloorId).Count();
  37. if (check > 0) {
  38. throw new ServiceException("아이디가 중복됩니다.");
  39. }
  40. _context.CmFloor.Add(data);
  41. _context.SaveChanges();
  42. } else {
  43. persist.Name = data.Name;
  44. //
  45. _context.SaveChanges();
  46. }
  47. }
  48. public IQueryable<CmFloor> GetAll() {
  49. var query = _context.CmFloor;
  50. return query;
  51. }
  52. }
  53. }