DrawingCodeTypeService.cs 1.7 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 DrawingCodeTypeService {
  7. private readonly ILogger<DrawingCodeTypeService> _logger;
  8. private readonly FMSContext _context;
  9. public DrawingCodeTypeService(
  10. ILogger<DrawingCodeTypeService> logger,
  11. FMSContext context) {
  12. _logger = logger;
  13. _context = context;
  14. }
  15. public void Create(FmsDrawingCodeType data) {
  16. _context.FmsDrawingCodeType.Add(data);
  17. _context.SaveChanges();
  18. }
  19. public void Edit(int id, FmsDrawingCodeType data) {
  20. var persist = _context.FmsDrawingCodeType
  21. .Where(x => x.DrawingTypeId == id).FirstOrDefault();
  22. if (persist == null) {
  23. throw new ServiceException("정보를 찾을 수 없습니다.");
  24. }
  25. persist.Name = data.Name;
  26. persist.IsUse = data.IsUse;
  27. _context.FmsDrawingCodeType.Update(persist);
  28. _context.SaveChanges();
  29. }
  30. public void Delete(int id) {
  31. var data = _context.FmsDrawingCodeType.First(x => x.DrawingTypeId == id);
  32. _context.FmsDrawingCodeType.Remove(data);
  33. _context.SaveChanges();
  34. }
  35. public IQueryable<FmsDrawingCodeType> GetAll() {
  36. var query = _context.FmsDrawingCodeType;
  37. return query;
  38. }
  39. public IQueryable<FmsDrawingCodeType> Get(int id) {
  40. var data = _context.FmsDrawingCodeType.Where(x => x.DrawingTypeId == id);
  41. return data;
  42. }
  43. }
  44. }