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