private static void InitializeDimensions(AirportDbContext db) {//TODO luggage dimensions ja weight index lehelt ära if (db.Luggages.Count() != 0) { return; } var dimensions = new[] { new LuggageData() { Id = "1", PassengerId = "Mari", Name = "MariLuggage", Dimensions = "S: 40 x 30 x 20", Weight = "Max 5 kg" }, new LuggageData() { Id = "2", PassengerId = "Jaan", Name = "JaanLuggage", Dimensions = "M: 100 x 50 x 80", Weight = "Max 10 kg" }, new LuggageData() { Id = "3", PassengerId = "Jaak", Name = "JaakLuggage", Dimensions = "L: 150 x 120 x 170", Weight = "Max 25 kg" } }; AddSet(dimensions, db); }
private static Func <AirportDbContext> AirportContext() { var fileName = Path.Join(Path.GetDirectoryName(typeof(AirportDbContext).Assembly.Location), "Airports.db"); return(AirportDbContext.DataContextFactory(fileName)); }
private static void InitializeStopOvers(AirportDbContext db) { if (db.StopOvers.Count() != 0) { return; } var airports = new[] { new StopOverData { Id = "None", Country = "None", City = "None" }, new StopOverData { Id = "NL", Country = "Netherlands", City = "Amsterdam" }, new StopOverData { Id = "SP", Country = "Spain", City = "Madrid" }, new StopOverData { Id = "ENG", Country = "England", City = "London" }, new StopOverData { Id = "AM", Country = "America", City = "Los Angeles" } }; AddSet(airports, db); }
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(); } }
static void Main(string[] args) { using (var contex = new AirportDbContext()) { ProfitReporter.CreateXMLProfitReport("test.xml", contex, DateTime.MinValue, DateTime.MaxValue); } }
public DbDeparture CreateDeparture(DbDeparture departure) { using (context = new AirportDbContext()) { DbDeparture dbDeparture = context.Departures.Add(departure); return(dbDeparture); } }
public override void TestInitialize() { base.TestInitialize(); var options = new DbContextOptionsBuilder <AirportDbContext>().UseInMemoryDatabase("TestDb").Options; var c = new AirportDbContext(options); obj = new TestClass(c, c.Airports); }
public DbArrival CreateArrival(DbArrival arrival) { using (context = new AirportDbContext()) { DbArrival dbArrival = context.Arrivals.Add(arrival); return(dbArrival); } }
public DbPlane CreatePlane(DbPlane plane) { using (context = new AirportDbContext()) { DbPlane dbPlane = context.Planes.Add(plane); context.SaveChanges(); return(dbPlane); } }
public AirportUnitOfWork(AirportDbContext dbContext) { _dbContext = dbContext; BusinessObjectRepository = new BaseRepository <BusinessObject>(_dbContext); EmployeeRepository = new BaseRepository <Employee>(_dbContext); OfferRepository = new BaseRepository <Offer>(_dbContext); BusinessObjectEmployeeRepository = new BaseRepository <BusinessObjectEmployee>(_dbContext); }
private List <Report> GetRecords() { var destinationFrom = "Sphia"; var reports = new List <Report>(); using (var db = new AirportDbContext()) { //Tickets.Select(t => t); var data = db.Tickets .Join(db.Destinations, t => t.CustomerId, d => d.Id, (t, d) => new { Destination = d.Name, TravelDate = t.TravelingDate }) .GroupBy(x => new { x.Destination, x.TravelDate.Year }, x => new { x.TravelDate }, (key, groups) => new { Destination = key.Destination, Yuer = key.Year, TiketCount = groups.Count() }); foreach (var item in data) { Report newRekord = new Report() { From = destinationFrom, To = item.Destination, SellTicketsCount = item.TiketCount, Year = item.Yuer }; reports.Add(newRekord); } } //for (int i = 0; i < 15; i++) //{ // reports.Add(new Report() // { // From = "aasas", // To = "daya", // SellTiketsCount = 50, // Year = 2014 // }); //} return(reports); }
public override void TestInitialize() { var options = new DbContextOptionsBuilder <AirportDbContext>() .UseInMemoryDatabase("TestDb") .Options; db = new AirportDbContext(options); DbSet = ((AirportDbContext)db).StopOvers; obj = new StopOversRepository((AirportDbContext)db); base.TestInitialize(); }
public void InitTest() { _context = new AirportDbContext(); _restMethods = new RESTMethods(); // _context.Database.EnsureDeleted(); // _context.Database.EnsureCreated(); var airplaneTypes = DataSourceStub.Instance.AirplaneTypes; // _context.AirplaneTypes.AddRange(airplaneTypes); // _context.SaveChanges(); }
public UnitOfWork( AirportDbContext dbContext ) { _dbContext = dbContext; AirhostessRepository = new AirhostessRepository(dbContext); CrewRepository = new CrewRepository(dbContext); DepartureRepository = new DepartureRepository(dbContext); FlightRepository = new FlightRepository(dbContext); PilotRepository = new PilotRepository(dbContext); PlaneRepository = new PlaneRepository(dbContext); PlaneTypeRepository = new PlaneTypeRepository(dbContext); TicketRepository = new TicketRepository(dbContext); }
/// <summary> /// Saves the company name, id, and profits for the specified time span in a xml file. /// </summary> /// <param name="fileName">The full name of the output file.</param> /// <param name="airportDbContext">The context used as a connection to the database.</param> /// <param name="startDate">The start of the time span it witch the profits will be shown</param> /// <param name="endDate">The end of the time span it witch the profits will be shown</param> public static void CreateXMLProfitReport(string fileName, AirportDbContext airportDbContext, DateTime startDate, DateTime endDate) { var companyTicketPriceJoin = airportDbContext.Companies.Join(airportDbContext.Tickets, comp => comp.Id, ticket => ticket.CompanyId, (company, ticket) => new { CompanyName = company.Name, CompanyId = company.Id, TicketPrice = ticket.Price }); var compantyProfitStatistics = companyTicketPriceJoin.GroupBy( //Select the items we will group by x => new { x.CompanyId, x.CompanyName }, //Select the elements we will need in additional operations x => new { TicketPrice = x.TicketPrice }, //Construct the result (key, groupEl) => new { CompanyId = key.CompanyId, CompanyName = key.CompanyName, Profit = groupEl.Sum(x => x.TicketPrice) }); Encoding encoding = Encoding.GetEncoding("windows-1251"); using (var xmlReport = new XmlTextWriter(fileName, encoding)) { xmlReport.Formatting = Formatting.Indented; xmlReport.IndentChar = '\t'; xmlReport.Indentation = 1; xmlReport.WriteStartDocument(); xmlReport.WriteStartElement("profit-reports"); foreach (var company in compantyProfitStatistics) { xmlReport.WriteStartElement("company"); xmlReport.WriteElementString("id", company.CompanyId.ToString()); xmlReport.WriteElementString("name", company.CompanyName); xmlReport.WriteElementString("profit", company.Profit.ToString()); xmlReport.WriteEndElement(); } xmlReport.WriteEndElement(); } }
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); } }
public void GlobalSetup() { MapperConfig.InitMappers(); // Migrate database if needed var optionsBuilder = new DbContextOptionsBuilder(new DbContextOptions <AirportDbContext>()); optionsBuilder.UseSqlServer(ConnectionString, b => b.MigrationsAssembly("Airport.Data")); var options = optionsBuilder.Options as DbContextOptions <AirportDbContext>; using (var airportDbContext = new AirportDbContext(options)) { airportDbContext.Database.Migrate(); } }
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 override void TestInitialize() { base.TestInitialize(); var options = new DbContextOptionsBuilder <AirportDbContext>() .UseInMemoryDatabase("TestDb") .Options; var c = new AirportDbContext(options); obj = new TestClass(c, c.Airports); count = GetRandom.UInt8(20, 40); foreach (var p in c.Airports) { c.Entry(p).State = EntityState.Deleted; } AddItems(); }
public async void GetAllAirportsReturnNotNull() { ICachingService cache = new CachingService(); DbContextOptions <AirportDbContext> options = new DbContextOptionsBuilder <AirportDbContext>(). UseSqlServer("data source=.;initial catalog=test_Local;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"") .Options; AirportDbContext context = new AirportDbContext(options); IAirportRepository airportRepository = new AirportRepository(context); IAirportConnector airport = new AirportConnector(cache, airportRepository); var airports = await airport.GetAllAirports(); Assert.NotNull(airports); }
public async void GetAllAirportsCount() { ICachingService cache = new CachingService(); DbContextOptions <AirportDbContext> options = new DbContextOptionsBuilder <AirportDbContext>(). UseSqlServer("data source=.;initial catalog=test_Local;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"") .Options; AirportDbContext context = new AirportDbContext(options); IAirportRepository airportRepository = new AirportRepository(context); IAirportConnector airport = new AirportConnector(cache, airportRepository); int expectedValue = 1062; var airports = await airport.GetAllAirports(); int actualValue = airports.Airports.ToList().Count(); Assert.Equal(expectedValue, actualValue); }
private static void InitializeAirports(AirportDbContext db) { if (db.Airports.Count() != 0) { return; } var airports = new[] { new AirportData { Id = "EST", Country = "Estonia", Phone = "555 8555" }, new AirportData { Id = "SWE", Country = "Sweden", Phone = "455 4555" }, new AirportData { Id = "LAT", Country = "Latvia", Phone = "644 6444" }, new AirportData { Id = "DMK", Country = "Denmark", Phone = "677 7666" } }; AddSet(airports, db); }
private static void InitializeAirlineCompanys(AirportDbContext db) { if (db.AirlineCompanies.Count() != 0) { return; } var airports = new[] { new AirlineCompanyData { Id = "EST", Name = "Estonian Air", Address = "Estair.com" }, new AirlineCompanyData { Id = "SWE", Name = "Air Leap", Address = "AirLeap.com" }, new AirlineCompanyData { Id = "LAT", Name = "Air Baltic", Address = "AirBaltic.com" }, new AirlineCompanyData { Id = "DMK", Name = "Danish Air Transport", Address = "DanishAirTransport.com" } }; AddSet(airports, db); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, AirportDbContext db) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors(options => { options.AllowAnyOrigin(); options.AllowAnyMethod(); options.AllowAnyHeader(); }); //db.Database.EnsureDeleted(); db.Database.EnsureCreated(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public void InitTest() { var mapperConfig = new MapperConfiguration(cfg => { cfg.CreateMap <AirplaneTypeDto, AirplaneType>(); cfg.CreateMap <AirplaneType, AirplaneTypeDto>(); cfg.CreateMap <AirplaneType, AirplaneType>(); }); _mapper = new Mapper(mapperConfig); _context = new AirportDbContext(); _repository = new AirplaneTypeRepository(_context, _mapper); _validator = new AirplaneTypeDtoValidator(); _service = new AirplaneTypeService(_mapper, _repository, _validator); // _context.Database.EnsureDeleted(); // _context.Database.EnsureCreated(); // Ensure seed data for context var airplaneTypes = DataSourceStub.Instance.AirplaneTypes; // _context.AirplaneTypes.AddRange(airplaneTypes); // _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 TicketRepository(AirportDbContext context, IMapper mapper) : base(context, mapper) { _context = context; _mapper = mapper; }
public FlightOfPassengersRepository(AirportDbContext c) : base(c, c.FlightOfPassengers) { }
public static AirportInitializer GetAirportInitializer(AirportDbContext airportDbContext) { return(new AirportInitializer(airportDbContext, new DataSource())); }
public static IUnitOfWork GetUnitOfWork(AirportDbContext airportDbContext) { var unitOfWork = new UnitOfWork(airportDbContext); return(unitOfWork); }