добавил последовательности в монго дб)
This commit is contained in:
parent
c22035dc50
commit
0b937cbc0b
@ -12,6 +12,12 @@ namespace database
|
||||
private IMongoCollection<Branch> _branchCollection;
|
||||
private IMongoCollection<Status> _statusCollection;
|
||||
private IMongoCollection<BodyType> _bodyTypeCollection;
|
||||
private class Sequence
|
||||
{
|
||||
public string Id;
|
||||
public int count;
|
||||
}
|
||||
private IMongoCollection<Sequence> _sequenceCollection;
|
||||
|
||||
public ImplementationMongoDB()
|
||||
{
|
||||
@ -32,6 +38,13 @@ namespace database
|
||||
// Car
|
||||
public override void AddCar(Car car)
|
||||
{
|
||||
if (car.Id == 0)
|
||||
{
|
||||
Sequence sequence = _sequenceCollection.Find(seq => seq.Id == "car").FirstOrDefault();
|
||||
sequence.count++;
|
||||
car.Id = sequence.count;
|
||||
_sequenceCollection.ReplaceOne(seq => seq.Id == "car", sequence);
|
||||
}
|
||||
_carCollection.InsertOne(car);
|
||||
}
|
||||
|
||||
@ -58,6 +71,13 @@ namespace database
|
||||
// Client
|
||||
public override void AddClient(Client client)
|
||||
{
|
||||
if (client.Id == 0)
|
||||
{
|
||||
Sequence sequence = _sequenceCollection.Find(seq => seq.Id == "client").FirstOrDefault();
|
||||
sequence.count++;
|
||||
client.Id = sequence.count;
|
||||
_sequenceCollection.ReplaceOne(seq => seq.Id == "client", sequence);
|
||||
}
|
||||
_clientCollection.InsertOne(client);
|
||||
}
|
||||
|
||||
@ -84,6 +104,13 @@ namespace database
|
||||
// Rental
|
||||
public override void AddRental(Rental rental)
|
||||
{
|
||||
if (rental.Id == 0)
|
||||
{
|
||||
Sequence sequence = _sequenceCollection.Find(seq => seq.Id == "rental").FirstOrDefault();
|
||||
sequence.count++;
|
||||
rental.Id = sequence.count;
|
||||
_sequenceCollection.ReplaceOne(seq => seq.Id == "rental", sequence);
|
||||
}
|
||||
_rentalCollection.InsertOne(rental);
|
||||
}
|
||||
|
||||
@ -110,6 +137,13 @@ namespace database
|
||||
// CarModel
|
||||
public override void AddCarModel(CarModel carModel)
|
||||
{
|
||||
if (carModel.Id == 0)
|
||||
{
|
||||
Sequence sequence = _sequenceCollection.Find(seq => seq.Id == "car_model").FirstOrDefault();
|
||||
sequence.count++;
|
||||
carModel.Id = sequence.count;
|
||||
_sequenceCollection.ReplaceOne(seq => seq.Id == "car_model", sequence);
|
||||
}
|
||||
_carModelCollection.InsertOne(carModel);
|
||||
}
|
||||
|
||||
@ -136,6 +170,13 @@ namespace database
|
||||
// Branch
|
||||
public override void AddBranch(Branch branch)
|
||||
{
|
||||
if (branch.Id == 0)
|
||||
{
|
||||
Sequence sequence = _sequenceCollection.Find(seq => seq.Id == "branch").FirstOrDefault();
|
||||
sequence.count++;
|
||||
branch.Id = sequence.count;
|
||||
_sequenceCollection.ReplaceOne(seq => seq.Id == "branch", sequence);
|
||||
}
|
||||
_branchCollection.InsertOne(branch);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user