11using TechInventory . Models ;
22using TechInventory . Data . Repository ;
3- using TechInventory . Data . UnitOfWork ;
3+ using TechInventory . Data . Context ;
44
55namespace TechInventory . Services . Device ;
66
7- public class DeviceService : IDeviceService , IDisposable
7+ public class DeviceService ( InventoryDbContext context ) : IDeviceService
88{
9- private readonly UnitOfWork _unitOfWork ;
10- private readonly IRepository < Models . Device > _repository ;
11- private readonly IRepository < Models . DeviceModel > _deviceModelRepository ;
12- private bool _disposed = false ;
13-
14- public DeviceService ( IUnitOfWork unitOfWork )
15- {
16- _unitOfWork = ( UnitOfWork ) unitOfWork ;
17- _repository = _unitOfWork . DeviceRepository ;
18- _deviceModelRepository = _unitOfWork . DeviceModelRepository ;
19- }
9+ private readonly IRepository < Models . Device > _repository = new Repository < Models . Device > ( context ) ;
10+ private readonly IRepository < Models . DeviceModel > _deviceModelRepository = new Repository < Models . DeviceModel > ( context ) ;
2011
2112 public async Task < Result < bool > > AddDevice ( Models . Device device )
2213 {
@@ -25,7 +16,7 @@ public async Task<Result<bool>> AddDevice(Models.Device device)
2516 return checkResult ;
2617
2718 await _repository . CreateAsync ( device ) ;
28- return await _unitOfWork . CommitAsync ( ) ;
19+ return await _repository . CommitAsync ( ) ;
2920 }
3021
3122 public async Task < Result < bool > > DeleteDevice ( int id )
@@ -38,7 +29,7 @@ public async Task<Result<bool>> DeleteDevice(int id)
3829 if ( ! deleteResult . IsSuccessful )
3930 return Result < bool > . Failure ( deleteResult . Message , false ) ;
4031
41- var commitResult = await _unitOfWork . CommitAsync ( ) ;
32+ var commitResult = await _repository . CommitAsync ( ) ;
4233
4334 return commitResult . IsSuccessful ? Result < bool > . Success ( true ) : Result < bool > . Failure ( commitResult . Message , false ) ;
4435 }
@@ -48,9 +39,9 @@ public async Task<Result<bool>> UpdateDevice(Models.Device device)
4839 var checkResult = await CheckIncludes ( device ) ;
4940 if ( ! checkResult . IsSuccessful )
5041 return checkResult ;
51-
42+
5243 _repository . Update ( device ) ;
53- return await _unitOfWork . CommitAsync ( ) ;
44+ return await _repository . CommitAsync ( ) ;
5445 }
5546
5647 public async Task < Models . Device ? > GetDeviceById ( int id )
@@ -92,24 +83,4 @@ public async Task<Result<bool>> CheckIncludes(Models.Device device)
9283
9384 return Result < bool > . Success ( true ) ;
9485 }
95-
96- protected virtual void Dispose ( bool disposing )
97- {
98- if ( ! _disposed )
99- {
100- if ( disposing )
101- {
102- // Nothing to dispose here as per the request.
103- // _unitOfWork is managed by DI container.
104- }
105-
106- _disposed = true ;
107- }
108- }
109-
110- public void Dispose ( )
111- {
112- Dispose ( true ) ;
113- GC . SuppressFinalize ( this ) ;
114- }
11586}
0 commit comments