Created
March 24, 2011 12:45
-
-
Save mps/884992 to your computer and use it in GitHub Desktop.
Delete everything for an Agency
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
private static void Delete(string customerCode) | |
{ | |
MongoInitializer.Initialize(); | |
var connectionString = ConfigurationManager.ConnectionStrings["AccuAutoMongo"]; | |
MServer = MongoServer.Create(connectionString.ConnectionString); | |
MDatabase = MServer[ConfigurationManager.AppSettings["DbName"] ?? "AccuAuto"]; | |
var clientCollection = MDatabase.GetCollection<Mongo.Data.Client>("Client"); | |
var paymentCollection = MDatabase.GetCollection<Mongo.Data.Payment>("Payment"); | |
var attachmentCollection = MDatabase.GetCollection<Mongo.Data.FileAttachment>("FileAttachment"); | |
var commissionCollection = MDatabase.GetCollection<Mongo.Data.ManagementCommission>("ManagementCommission"); | |
var policyCollection = MDatabase.GetCollection<Policy>("Policy"); | |
var factory = new MongoConversionRepositories.ConversionRepositoryFactory(); | |
var agencyRepo = factory.BuildAgencyRepository(); | |
var agency = agencyRepo.GetByCustomerCode(customerCode); | |
if (agency == null) | |
throw new ArgumentException("Could not find the agency for customercode: {0}", customerCode); | |
var paymentQuery = Query<Mongo.Data.Payment>.EQ(p => p.OldAgencyId, agency.Id); | |
paymentCollection.Remove(paymentQuery); | |
var attachmentQuery = Query<Mongo.Data.FileAttachment>.EQ(p => p.OldAgencyId, agency.Id); | |
attachmentCollection.Remove(attachmentQuery); | |
var clientQuery = Query<Mongo.Data.Client>.EQ(p => p.OldAgencyId, agency.Id); | |
clientCollection.Remove(clientQuery); | |
var policyQuery = Query<Policy>.EQ(p => p.AgencyId, agency.Id); | |
policyCollection.Remove(policyQuery); | |
var commissionQuery = Query<Mongo.Data.ManagementCommission>.EQ(p => p.OldAgencyId, agency.Id); | |
commissionCollection.Remove(commissionQuery); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment