123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- using Microsoft.EntityFrameworkCore;
- using ProductionLineMonitor.Core.IRepositories;
- using ProductionLineMonitor.Core.Models;
- using System.Collections;
- using System;
- namespace ProductionLineMonitor.EntityFramework.Repositories
- {
- public class UnitOfWork : IUnitOfWork
- {
- private readonly ProductionLineContext _context;
- public UnitOfWork(ProductionLineContext context)
- {
- _context = context;
- }
- private readonly IBaseRepository<User>? _userRepository = null;
- public IBaseRepository<User> UserRepository =>
- _userRepository ?? new BaseRepository<User>(_context);
- private readonly IBaseRepository<Role>? _roleRepository = null;
- public IBaseRepository<Role> RoleRepository =>
- _roleRepository ?? new BaseRepository<Role>(_context);
- private readonly IBaseRepository<Machine>? _machineRepository = null;
- public IBaseRepository<Machine> MachineRepository =>
- _machineRepository ?? new BaseRepository<Machine>(_context);
- private readonly IBaseRepository<MachineOutPutPerHour>? _machineOutPutPerHourRepository = null;
- public IBaseRepository<MachineOutPutPerHour> MachineOutPutPerHourRepository =>
- _machineOutPutPerHourRepository ?? new BaseRepository<MachineOutPutPerHour>(_context);
- private readonly IBaseRepository<ProductionLine>? _productionLineRepository = null;
- public IBaseRepository<ProductionLine> ProductionLineRepository =>
- _productionLineRepository ?? new BaseRepository<ProductionLine>(_context);
- private readonly IBaseRepository<Recipe>? _recipeRepository = null;
- public IBaseRepository<Recipe> RecipeRepository =>
- _recipeRepository ?? new BaseRepository<Recipe>(_context);
- private readonly IBaseRepository<MachineFaultComparison>? _machineFaultComparisonRepository = null;
- public IBaseRepository<MachineFaultComparison> MachineFaultComparisonRepository =>
- _machineFaultComparisonRepository ?? new BaseRepository<MachineFaultComparison>(_context);
- private readonly IBaseRepository<MachineFaultRecord>? _machineFaultRecordRepository = null;
- public IBaseRepository<MachineFaultRecord> MachineFaultRecordRepository =>
- _machineFaultRecordRepository ?? new BaseRepository<MachineFaultRecord>(_context);
- private readonly IBaseRepository<Cim>? _cimRepository = null;
- public IBaseRepository<Cim> CimRepository =>
- _cimRepository ?? new BaseRepository<Cim>(_context);
- private readonly IBaseRepository<MachineStatistic>? _machineStatisticRepository = null;
- public IBaseRepository<MachineStatistic> MachineStatisticRepository =>
- _machineStatisticRepository ?? new BaseRepository<MachineStatistic>(_context);
- private readonly IBaseRepository<MachinePowerConsumption>? _machinePowerConsumptionRepository = null;
- public IBaseRepository<MachinePowerConsumption> MachinePowerConsumptionRepository =>
- _machinePowerConsumptionRepository ?? new BaseRepository<MachinePowerConsumption>(_context);
- private readonly IBaseRepository<MachineProcessPS>? _machineProcessPSRepository = null;
- public IBaseRepository<MachineProcessPS> MachineProcessPSRepository =>
- _machineProcessPSRepository ?? new BaseRepository<MachineProcessPS>(_context);
- private readonly IBaseRepository<MachineProcessFOG>? _machineProcessFOGRepository = null;
- public IBaseRepository<MachineProcessFOG> MachineProcessFOGRepository =>
- _machineProcessFOGRepository ?? new BaseRepository<MachineProcessFOG>(_context);
- private readonly IBaseRepository<MachineProcessBT>? _machineProcessBTRepository = null;
- public IBaseRepository<MachineProcessBT> MachineProcessBTRepository =>
- _machineProcessBTRepository ?? new BaseRepository<MachineProcessBT>(_context);
- private readonly IBaseRepository<MachineProcessPSEPD>? _machineProcessPSEPDRepository = null;
- public IBaseRepository<MachineProcessPSEPD> MachineProcessPSEPDRepository =>
- _machineProcessPSEPDRepository ?? new BaseRepository<MachineProcessPSEPD>(_context);
- private readonly IBaseRepository<RoleMenu>? _roleMenuRepository = null;
- public IBaseRepository<RoleMenu> RoleMenuRepository =>
- _roleMenuRepository ?? new BaseRepository<RoleMenu>(_context);
- private readonly IBaseRepository<Menu>? _menuRepository = null;
- public IBaseRepository<Menu> MenuRepository =>
- _menuRepository ?? new BaseRepository<Menu>(_context);
- private readonly IBaseRepository<ElectricEnergyMeter>? _electricEnergyMeterRepository = null;
- public IBaseRepository<ElectricEnergyMeter> ElectricEnergyMeterRepository =>
- _electricEnergyMeterRepository ?? new BaseRepository<ElectricEnergyMeter>(_context);
- private readonly IBaseRepository<ElectricEnergyMeterLog>? _electricEnergyMeterLogRepository = null;
- public IBaseRepository<ElectricEnergyMeterLog> ElectricEnergyMeterLogRepository =>
- _electricEnergyMeterLogRepository ?? new BaseRepository<ElectricEnergyMeterLog>(_context);
- private readonly IBaseRepository<EmailInfo>? _emailInfoRepository = null;
- public IBaseRepository<EmailInfo> EmailInfoRepository =>
- _emailInfoRepository ?? new BaseRepository<EmailInfo>(_context);
- public void Dispose()
- {
- _context?.Dispose();
- }
- public int SaveChanges()
- {
- return _context.SaveChanges();
- }
- public void ExecuteSql(string sql, params object[] sqlParams)
- {
- _context.Database.ExecuteSqlRaw(sql, sqlParams);
- }
- private Hashtable? repositorys;
- public IBaseRepository<TEntity> Repository<TEntity>() where TEntity : Base
- {
- repositorys ??= new Hashtable();
- var entityType = typeof(TEntity);
- if (!repositorys.ContainsKey(entityType.Name))
- {
- var baseType = typeof(BaseRepository<>);
- var repositoryInstance = Activator.CreateInstance(baseType.MakeGenericType(entityType), _context);
- repositorys.Add(entityType.Name, repositoryInstance);
- }
- return (IBaseRepository<TEntity>)repositorys[entityType.Name];
- }
- public DbContext GetDbContext()
- {
- return _context;
- }
- }
- }
|