12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using Microsoft.Extensions.Logging;
- using FMSAdmin.Data;
- using System.Linq;
- using FMSAdmin.Helpers;
- using FMSAdmin.Entities;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Transactions;
- namespace FMSAdmin.Services {
- public class DrawingService {
- private readonly ILogger<DrawingService> _logger;
- private readonly FMSContext _context;
- private readonly StorageHelper _storage;
- public DrawingService(
- ILogger<DrawingService> logger,
- FMSContext context,
- StorageHelper storage) {
- _logger = logger;
- _context = context;
- _storage = storage;
- }
- public void Create(FmsDrawing data) {
- using (var trans = new TransactionScope()) {
- if (data.CmFile != null && data.CmFile.IsUpload) {
- var category = _context.CmFileCategory.First(x => x.Name == "drawing");
- data.CmFile.FileCategory = category;
- data.CmFile.CreatedDate = DateTime.Now;
- data.CmFile.SiteId = data.SiteId;
- } else {
- data.CmFile = null;
- }
- data.FmsDrawingHistory.Add(new FmsDrawingHistory {
- SiteId = data.SiteId,
- RevisionNo = 0,
- Description = data.Description,
- CmFile = data.CmFile,
- UpdatedDate = DateTime.Now,
- UpdatedUserId = data.CreateUserId
- });
- _context.FmsDrawing.Add(data);
- _context.SaveChanges();
- if (data.CmFile != null && data.CmFile.IsUpload) {
- // 카피
- _storage.CopyEntity(data.CmFile.Path, data.CmFile);
- }
- trans.Complete();
- }
- }
- public void Edit(int id, int siteId, FmsDrawing data) {
- using (var trans = new TransactionScope()) {
- var persist = _context.FmsDrawing
- .Where(x => x.DrawingId == id && x.SiteId == siteId).FirstOrDefault();
- if (persist == null) {
- throw new ServiceException("정보를 찾을 수 없습니다.");
- }
- persist.SiteId = data.SiteId;
- persist.DrawingGroupId = data.DrawingGroupId;
- persist.DrawingTypeId = data.DrawingTypeId;
- persist.DrawingNo = data.DrawingNo;
- persist.Name = data.Name;
- persist.Description = data.Description;
- _context.FmsDrawing.Update(persist);
- _context.SaveChanges();
- trans.Complete();
- }
- }
- public void Delete(int id, int siteId) {
- var data = _context.FmsDrawing.First(x => x.DrawingId == id && x.SiteId == siteId);
- _context.FmsDrawing.Remove(data);
- _context.SaveChanges();
- }
- public IQueryable<FmsDrawing> GetAll() {
- var query = _context.FmsDrawing;
- return query;
- }
- public IQueryable<FmsDrawing> Get(int id, int siteId) {
- var data = _context.FmsDrawing.Where(x => x.DrawingId == id && x.SiteId == siteId);
- return data;
- }
- }
- }
|