public static void TransferDataFromMongoToMsSql() { using (var msDb = new AirportDbContext()) { MongoDataReader reader = new MongoDataReader(); var comapnies = reader.GetCompanies(); foreach (var company in comapnies) { var newCompany = new Airport.Data.Company(); newCompany.Name = company.Name; msDb.Companies.Add(newCompany); } var customers = reader.GetCustomers(); foreach (var customer in customers) { var newCustomer = new Airport.Data.Customer(); newCustomer.FirstName = customer.FirstName; newCustomer.LastName = customer.LastName; msDb.Customers.Add(newCustomer); } var destinations = reader.GetDestinations(); foreach (var dest in destinations) { var destination = new Airport.Data.Destination(); destination.Name = dest.Name; msDb.Destinations.Add(destination); } msDb.SaveChanges(); } }
public DbPlane CreatePlane(DbPlane plane) { using (context = new AirportDbContext()) { DbPlane dbPlane = context.Planes.Add(plane); context.SaveChanges(); return(dbPlane); } }
public DbStation UpdateStationById(int id, DbStation station) { using (context = new AirportDbContext()) { DbStation original = context.Stations.SingleOrDefault(s => s.Id == id); if (original != null) { original.CurrentPlane = station.CurrentPlane; original.NextStationsIds = station.NextStationsIds; original.TimeToExecution = station.TimeToExecution; } context.SaveChanges(); return(original); } }
private void InsertToDatabase(int companyId, int customerId, int destinationId, decimal price, DateTime date) { using (var db = new AirportDbContext()) { var ticket = new Ticket(); ticket.Company = db.Companies.Find(companyId); ticket.Customer = db.Customers.Find(customerId); ticket.Destination = db.Destinations.Find(destinationId); ticket.TravelingDate = date; ticket.Price = price; db.Tickets.Add(ticket); db.SaveChanges(); } }
public bool Save(CustomerContractsModel customer) { if (customer == null) { throw new ArgumentNullException(nameof(customer)); } this._customer = ModelConverterHelper.GetModelFromContract(customer); using (_context) { var customerModel = _context.Customer.FirstOrDefault(x => x.Id == this._customer.Id); customerModel = _customer; _context.SaveChanges(); } return(true); }
private void SeedUsers() { if (!_context.Users.Any()) { var userData = File .ReadAllText("../Airport.Infrastructure/Persistence/DbSeed/UserData.json"); var users = JsonSerializer.Deserialize <List <User> >(userData); foreach (var user in users) { CreatePasswordHash("password", out var passwordHash, out var passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; user.IsConfirmed = true; _context.Users.Add(user); } _context.SaveChanges(); } }
public void ParseXML() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("../../CompanyInfo.xml"); string xPathQuery = "/companyInfo/company"; var mongoInserter = new MongoDataInserter(); XmlNodeList companyList = xmlDoc.SelectNodes(xPathQuery); foreach (XmlNode company in companyList) { var companyName = company.Attributes["name"].Value; var town = company.SelectSingleNode("town").InnerText; var airplainsCount = company.SelectSingleNode("airplains").InnerText; var employeesCount = company.SelectSingleNode("employees").InnerText; using (var msDb = new AirportDbContext()) { var companyFromDb = msDb.Companies.FirstOrDefault(x => x.Name == companyName); var companyInfo = new Airport.Data.CompanyInfo(); companyInfo.Town = town; companyInfo.AirplainsCount = int.Parse(airplainsCount); companyInfo.EmployeesCount = int.Parse(employeesCount); companyInfo.Company = companyFromDb; msDb.CompanyInfo.Add(companyInfo); msDb.SaveChanges(); } var mongoInfo = new MongoDBController.CompanyInfo(); mongoInfo.AirplainsCount = int.Parse(airplainsCount); mongoInfo.EmployeesCount = int.Parse(employeesCount); mongoInfo.Town = town; mongoInfo.CompanyName = companyName; mongoInserter.AddCompanyInfo(mongoInfo); } }
public void CommitChanges() { _dbContext.SaveChanges(); }
public void Save() { _context.SaveChanges(); }
public int SaveChanges() { return(_dbContext.SaveChanges()); }