Investigation3CodeTypeService.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Linq;
  2. using FMSAdmin.Data;
  3. using FMSAdmin.Entities;
  4. using Microsoft.Extensions.Logging;
  5. namespace FMSAdmin.Services {
  6. public class Investigation3CodeTypeService {
  7. private readonly ILogger<Investigation3CodeTypeService> _logger;
  8. private readonly FMSContext _context;
  9. public Investigation3CodeTypeService(
  10. ILogger<Investigation3CodeTypeService> logger,
  11. FMSContext context) {
  12. _logger = logger;
  13. _context = context;
  14. }
  15. public void Create(CmInvestigation3CodeType data) {
  16. _context.CmInvestigation3CodeType.Add(data);
  17. _context.SaveChanges();
  18. }
  19. public void Edit(int id, CmInvestigation3CodeType data) {
  20. var persist = _context.CmInvestigation3CodeType
  21. .Where(x => x.InvestigationTypeId == id).FirstOrDefault();
  22. if (persist == null) {
  23. throw new ServiceException("정보를 찾을 수 없습니다.");
  24. }
  25. persist.Name = data.Name;
  26. persist.IsUse = data.IsUse;
  27. _context.CmInvestigation3CodeType.Update(persist);
  28. _context.SaveChanges();
  29. }
  30. public void Delete(int id) {
  31. var data = _context.CmInvestigation3CodeType.First(x => x.InvestigationTypeId == id);
  32. _context.CmInvestigation3CodeType.Remove(data);
  33. _context.SaveChanges();
  34. }
  35. public IQueryable<CmInvestigation3CodeType> GetAll() {
  36. var query = _context.CmInvestigation3CodeType;
  37. return query;
  38. }
  39. public IQueryable<CmInvestigation3CodeType> Get(int id) {
  40. var data = _context.CmInvestigation3CodeType.Where(x => x.InvestigationTypeId == id);
  41. return data;
  42. }
  43. }
  44. }