using System.Linq; using FMSAdmin.Data; using FMSAdmin.Entities; using Microsoft.Extensions.Logging; namespace FMSAdmin.Services { public class Investigation1CodeTypeService { private readonly ILogger _logger; private readonly FMSContext _context; public Investigation1CodeTypeService( ILogger logger, FMSContext context) { _logger = logger; _context = context; } public void Create(CmInvestigation1CodeType data) { _context.CmInvestigation1CodeType.Add(data); _context.SaveChanges(); } public void Edit(int id, CmInvestigation1CodeType data) { var persist = _context.CmInvestigation1CodeType .Where(x => x.InvestigationTypeId == id).FirstOrDefault(); if (persist == null) { throw new ServiceException("정보를 찾을 수 없습니다."); } persist.Name = data.Name; persist.IsUse = data.IsUse; _context.CmInvestigation1CodeType.Update(persist); _context.SaveChanges(); } public void Delete(int id) { var data = _context.CmInvestigation1CodeType.First(x => x.InvestigationTypeId == id); _context.CmInvestigation1CodeType.Remove(data); _context.SaveChanges(); } public IQueryable GetAll() { var query = _context.CmInvestigation1CodeType; return query; } public IQueryable Get(int id) { var data = _context.CmInvestigation1CodeType.Where(x => x.InvestigationTypeId == id); return data; } } }