-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The logic of the repositories is abstracted into an interface and an abstract class to reduce the lines of code used in the repositories.
- Loading branch information
1 parent
ae69891
commit aa07b40
Showing
26 changed files
with
118 additions
and
466 deletions.
There are no files selected for viewing
11 changes: 2 additions & 9 deletions
11
src/Armory/Armament/Ammunition/Domain/IAmmunitionRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using Armory.Shared.Domain.Repositories; | ||
|
||
namespace Armory.Armament.Ammunition.Domain | ||
{ | ||
public interface IAmmunitionRepository | ||
public interface IAmmunitionRepository : IRepository<Ammunition, string> | ||
{ | ||
Task Save(Ammunition ammunition); | ||
Task<Ammunition> Find(string lot, bool noTracking); | ||
Task<Ammunition> Find(string lot); | ||
Task<IEnumerable<Ammunition>> SearchAll(bool noTracking); | ||
Task<IEnumerable<Ammunition>> SearchAll(); | ||
Task<IEnumerable<Ammunition>> SearchAllByFlight(string flightCode); | ||
Task<bool> Any(Expression<Func<Ammunition, bool>> predicate); | ||
Task Update(Ammunition newAmmunition); | ||
} | ||
} |
48 changes: 8 additions & 40 deletions
48
src/Armory/Armament/Ammunition/Infrastructure/Persistence/MySqlAmmunitionRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using Armory.Armament.Ammunition.Domain; | ||
using Armory.Shared.Infrastructure.Persistence.EntityFramework; | ||
using Armory.Shared.Infrastructure.Repositories; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Armory.Armament.Ammunition.Infrastructure.Persistence | ||
{ | ||
public class MySqlAmmunitionRepository : IAmmunitionRepository | ||
public class MySqlAmmunitionRepository : Repository<Domain.Ammunition, string>, IAmmunitionRepository | ||
{ | ||
private readonly ArmoryDbContext _context; | ||
|
||
public MySqlAmmunitionRepository(ArmoryDbContext context) | ||
public MySqlAmmunitionRepository(ArmoryDbContext context) : base(context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task Save(Domain.Ammunition ammunition) | ||
public override async Task<Domain.Ammunition> Find(string lot, bool noTracking) | ||
{ | ||
await _context.Ammunition.AddAsync(ammunition); | ||
await _context.SaveChangesAsync(); | ||
} | ||
|
||
public async Task<Domain.Ammunition> Find(string lot, bool noTracking) | ||
{ | ||
var query = noTracking ? _context.Ammunition.AsNoTracking() : _context.Ammunition.AsTracking(); | ||
var query = noTracking ? Context.Ammunition.AsNoTracking() : Context.Ammunition.AsTracking(); | ||
|
||
return await query.FirstOrDefaultAsync(c => c.Lot == lot); | ||
} | ||
|
||
public async Task<Domain.Ammunition> Find(string lot) | ||
{ | ||
return await Find(lot, true); | ||
} | ||
|
||
public async Task<IEnumerable<Domain.Ammunition>> SearchAll(bool noTracking) | ||
{ | ||
var query = noTracking ? _context.Ammunition.AsNoTracking() : _context.Ammunition.AsTracking(); | ||
|
||
return await query.ToListAsync(); | ||
} | ||
|
||
public async Task<IEnumerable<Domain.Ammunition>> SearchAll() | ||
{ | ||
return await SearchAll(true); | ||
} | ||
|
||
public async Task<IEnumerable<Domain.Ammunition>> SearchAllByFlight(string flightCode) | ||
{ | ||
return await _context.Ammunition.AsNoTracking() | ||
return await Context.Ammunition.AsNoTracking() | ||
.Where(a => a.FlightCode == flightCode) | ||
.ToListAsync(); | ||
} | ||
|
||
public async Task<bool> Any(Expression<Func<Domain.Ammunition, bool>> predicate) | ||
{ | ||
return await _context.Ammunition.AnyAsync(predicate); | ||
} | ||
|
||
public async Task Update(Domain.Ammunition newAmmunition) | ||
{ | ||
_context.Ammunition.Update(newAmmunition); | ||
await _context.SaveChangesAsync(); | ||
Context.Ammunition.Update(newAmmunition); | ||
await Context.SaveChangesAsync(); | ||
} | ||
} | ||
} |
11 changes: 2 additions & 9 deletions
11
src/Armory/Armament/Equipments/Domain/IEquipmentsRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using Armory.Shared.Domain.Repositories; | ||
|
||
namespace Armory.Armament.Equipments.Domain | ||
{ | ||
public interface IEquipmentsRepository | ||
public interface IEquipmentsRepository : IRepository<Equipment, string> | ||
{ | ||
Task Save(Equipment equipment); | ||
Task<Equipment> Find(string serial, bool noTracking); | ||
Task<Equipment> Find(string serial); | ||
Task<IEnumerable<Equipment>> SearchAll(bool noTracking); | ||
Task<IEnumerable<Equipment>> SearchAll(); | ||
Task<IEnumerable<Equipment>> SearchAllByFlight(string flightCode); | ||
Task<bool> Any(Expression<Func<Equipment, bool>> predicate); | ||
Task Update(Equipment newEquipment); | ||
} | ||
} |
48 changes: 8 additions & 40 deletions
48
src/Armory/Armament/Equipments/Infrastructure/Persistence/MySqlEquipmentsRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using Armory.Armament.Equipments.Domain; | ||
using Armory.Shared.Infrastructure.Persistence.EntityFramework; | ||
using Armory.Shared.Infrastructure.Repositories; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Armory.Armament.Equipments.Infrastructure.Persistence | ||
{ | ||
public class MySqlEquipmentsRepository : IEquipmentsRepository | ||
public class MySqlEquipmentsRepository : Repository<Equipment, string>, IEquipmentsRepository | ||
{ | ||
private readonly ArmoryDbContext _context; | ||
|
||
public MySqlEquipmentsRepository(ArmoryDbContext context) | ||
public MySqlEquipmentsRepository(ArmoryDbContext context) : base(context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task Save(Equipment equipment) | ||
public override async Task<Equipment> Find(string serial, bool noTracking) | ||
{ | ||
await _context.Equipments.AddAsync(equipment); | ||
await _context.SaveChangesAsync(); | ||
} | ||
|
||
public async Task<Equipment> Find(string serial, bool noTracking) | ||
{ | ||
var query = noTracking ? _context.Equipments.AsNoTracking() : _context.Equipments.AsTracking(); | ||
var query = noTracking ? Context.Equipments.AsNoTracking() : Context.Equipments.AsTracking(); | ||
|
||
return await query.FirstOrDefaultAsync(e => e.Serial == serial); | ||
} | ||
|
||
public async Task<Equipment> Find(string serial) | ||
{ | ||
return await Find(serial, true); | ||
} | ||
|
||
public async Task<IEnumerable<Equipment>> SearchAll(bool noTracking) | ||
{ | ||
var query = noTracking ? _context.Equipments.AsNoTracking() : _context.Equipments.AsTracking(); | ||
|
||
return await query.ToListAsync(); | ||
} | ||
|
||
public async Task<IEnumerable<Equipment>> SearchAll() | ||
{ | ||
return await SearchAll(true); | ||
} | ||
|
||
public async Task<IEnumerable<Equipment>> SearchAllByFlight(string flightCode) | ||
{ | ||
return await _context.Equipments.AsNoTracking() | ||
return await Context.Equipments.AsNoTracking() | ||
.Where(e => e.FlightCode == flightCode) | ||
.ToListAsync(); | ||
} | ||
|
||
public async Task<bool> Any(Expression<Func<Equipment, bool>> predicate) | ||
{ | ||
return await _context.Equipments.AnyAsync(predicate); | ||
} | ||
|
||
public async Task Update(Equipment newEquipment) | ||
{ | ||
_context.Equipments.Update(newEquipment); | ||
await _context.SaveChangesAsync(); | ||
Context.Equipments.Update(newEquipment); | ||
await Context.SaveChangesAsync(); | ||
} | ||
} | ||
} |
11 changes: 2 additions & 9 deletions
11
src/Armory/Armament/Explosives/Domain/IExplosivesRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using Armory.Shared.Domain.Repositories; | ||
|
||
namespace Armory.Armament.Explosives.Domain | ||
{ | ||
public interface IExplosivesRepository | ||
public interface IExplosivesRepository : IRepository<Explosive, string> | ||
{ | ||
Task Save(Explosive explosive); | ||
Task<Explosive> Find(string serial, bool noTracking); | ||
Task<Explosive> Find(string serial); | ||
Task<IEnumerable<Explosive>> SearchAll(bool noTracking); | ||
Task<IEnumerable<Explosive>> SearchAll(); | ||
Task<IEnumerable<Explosive>> SearchAllByFlight(string flightCode); | ||
Task<bool> Any(Expression<Func<Explosive, bool>> predicate); | ||
Task Update(Explosive newExplosive); | ||
} | ||
} |
48 changes: 8 additions & 40 deletions
48
src/Armory/Armament/Explosives/Infrastructure/Persistence/MySqlExplosivesRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using Armory.Armament.Explosives.Domain; | ||
using Armory.Shared.Infrastructure.Persistence.EntityFramework; | ||
using Armory.Shared.Infrastructure.Repositories; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Armory.Armament.Explosives.Infrastructure.Persistence | ||
{ | ||
public class MySqlExplosivesRepository : IExplosivesRepository | ||
public class MySqlExplosivesRepository : Repository<Explosive, string>, IExplosivesRepository | ||
{ | ||
private readonly ArmoryDbContext _context; | ||
|
||
public MySqlExplosivesRepository(ArmoryDbContext context) | ||
public MySqlExplosivesRepository(ArmoryDbContext context) : base(context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task Save(Explosive explosive) | ||
public override async Task<Explosive> Find(string serial, bool noTracking) | ||
{ | ||
await _context.Explosives.AddAsync(explosive); | ||
await _context.SaveChangesAsync(); | ||
} | ||
|
||
public async Task<Explosive> Find(string serial, bool noTracking) | ||
{ | ||
var query = noTracking ? _context.Explosives.AsNoTracking() : _context.Explosives.AsTracking(); | ||
var query = noTracking ? Context.Explosives.AsNoTracking() : Context.Explosives.AsTracking(); | ||
|
||
return await query.FirstOrDefaultAsync(e => e.Serial == serial); | ||
} | ||
|
||
public async Task<Explosive> Find(string serial) | ||
{ | ||
return await Find(serial, true); | ||
} | ||
|
||
public async Task<IEnumerable<Explosive>> SearchAll(bool noTracking) | ||
{ | ||
var query = noTracking ? _context.Explosives.AsNoTracking() : _context.Explosives.AsTracking(); | ||
|
||
return await query.ToListAsync(); | ||
} | ||
|
||
public async Task<IEnumerable<Explosive>> SearchAll() | ||
{ | ||
return await SearchAll(true); | ||
} | ||
|
||
public async Task<IEnumerable<Explosive>> SearchAllByFlight(string flightCode) | ||
{ | ||
return await _context.Explosives.AsNoTracking() | ||
return await Context.Explosives.AsNoTracking() | ||
.Where(e => e.FlightCode == flightCode) | ||
.ToListAsync(); | ||
} | ||
|
||
public async Task<bool> Any(Expression<Func<Explosive, bool>> predicate) | ||
{ | ||
return await _context.Explosives.AnyAsync(predicate); | ||
} | ||
|
||
public async Task Update(Explosive newExplosive) | ||
{ | ||
_context.Update(newExplosive); | ||
await _context.SaveChangesAsync(); | ||
Context.Update(newExplosive); | ||
await Context.SaveChangesAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using Armory.Shared.Domain.Repositories; | ||
|
||
namespace Armory.Armament.Weapons.Domain | ||
{ | ||
public interface IWeaponsRepository | ||
public interface IWeaponsRepository : IRepository<Weapon, string> | ||
{ | ||
Task Save(Weapon weapon); | ||
Task<Weapon> Find(string serial, bool noTracking); | ||
Task<Weapon> Find(string serial); | ||
Task<IEnumerable<Weapon>> SearchAll(bool noTracking); | ||
Task<IEnumerable<Weapon>> SearchAll(); | ||
Task<IEnumerable<Weapon>> SearchAllByFlight(string flightCode); | ||
Task<bool> Any(Expression<Func<Weapon, bool>> predicate); | ||
Task Update(Weapon newWeapon); | ||
} | ||
} |
Oops, something went wrong.