Ejemplo n.º 1
0
        public IList <FlightModel> GetAllFlights(FlightType flightType)
        {
            using var dbContext = new LocalDatabaseContext();
            var flights = dbContext.Flights.Where(x => x.Type == flightType);

            return(this.mapper.ProjectTo <FlightModel>(flights).ToList());
        }
Ejemplo n.º 2
0
        // TODO 2.1: Upravte metodu tak, aby vrátila pouze lety specifického typu
        public IList <FlightModel> GetAllFlights()
        {
            using var dbContext = new LocalDatabaseContext();

            var flights = dbContext.Flights;

            return(this.mapper.ProjectTo <FlightModel>(flights).ToList());
        }
Ejemplo n.º 3
0
        public IList <AirplaneModel> GetClubAirplanes()
        {
            using var dbContext = new LocalDatabaseContext();

            var airplanes = dbContext.ClubAirplanes
                            .Include(airplane => airplane.AirplaneType);

            return(this.mapper.ProjectTo <AirplaneModel>(airplanes).ToList());
        }
Ejemplo n.º 4
0
        // TODO 2.3: Vytvořte metodu, která načte letadla, která jsou ve vzduchu, seřadí je od nejstarších,
        // a v případě shody dá vlečné pred kluzák, který táhne

        public void LandFlight(FlightLandingModel landingModel)
        {
            using var dbContext = new LocalDatabaseContext();

            var flight = dbContext.Flights.Find(landingModel.FlightId);

            flight.LandingTime = landingModel.LandingTime;
            dbContext.SaveChanges();
        }
Ejemplo n.º 5
0
        public void TakeoffFlight(long?gliderFlightId, long?towplaneFlightId)
        {
            using var dbContext = new LocalDatabaseContext();

            var flightStart = new FlightStart
            {
                Glider   = dbContext.Flights.Find(gliderFlightId),
                Towplane = dbContext.Flights.Find(towplaneFlightId),
            };

            dbContext.FlightStarts.Add(flightStart);
            dbContext.SaveChanges();
        }
Ejemplo n.º 6
0
        public long AddGuestAirplane(AirplaneModel airplaneModel)
        {
            using var dbContext = new LocalDatabaseContext();

            Airplane airplane = new Airplane
            {
                GuestAirplaneImmatriculation = airplaneModel.Immatriculation,
                GuestAirplaneType            = airplaneModel.Type,
            };

            dbContext.Airplanes.Add(airplane);
            dbContext.SaveChanges();
            return(airplane.Id);
        }
Ejemplo n.º 7
0
        public IList <FlightModel> GetAirplanesInAir()
        {
            using var dbContext = new LocalDatabaseContext();

            var flights = dbContext.Flights
                          .Include(x => x.Airplane)
                          .Include(x => x.Copilot)
                          .Include(x => x.Pilot)
                          .Where(x => x.LandingTime == null)
                          .OrderBy(x => x.TakeoffTime)
                          .ThenByDescending(x => x.Type);

            return(this.mapper.ProjectTo <FlightModel>(flights).ToList());
        }
Ejemplo n.º 8
0
        // ReSharper disable once UnusedMember.Global - used by Framework
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IMapper mapper, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddLog4Net();

            // Security headers make me happy
            app.UseHsts(options => options.MaxAge(365).IncludeSubdomains());
            app.UseXContentTypeOptions();
            app.UseReferrerPolicy(opts => opts.NoReferrer());
            app.UseXXssProtection(options => options.EnabledWithBlockMode());
            app.UseXfo(options => options.Deny());

            app.UseCsp(opts => opts
                       .BlockAllMixedContent()
                       .StyleSources(s => s.Self())
                       .StyleSources(s => s.UnsafeInline())
                       .FontSources(s => s.Self())
                       .FormActions(s => s.Self())
                       .FrameAncestors(s => s.Self())
                       .ImageSources(s => s.Self())
                       .ScriptSources(s => s.Self()));
            // End Security Headers

            app.UseDefaultFiles();
            app.UseStaticFiles();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                TestDatabaseGenerator.RenewDatabase();
            }
            else
            {
                using var dbContext = new Repositories.LocalDatabaseContext();
                dbContext.Database.EnsureCreated();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints => {
                endpoints.MapControllers();
            });

            mapper.ConfigurationProvider.AssertConfigurationIsValid();
        }
Ejemplo n.º 9
0
        public long AddGuestPerson(PersonModel pilot)
        {
            using var dbContext = new LocalDatabaseContext();

            var address = new Address {
                City = pilot.Address.City, Country = pilot.Address.Country, PostalCode = pilot.Address.PostalCode, Street = pilot.Address.Street
            };
            var person = new Person {
                Address = address, FirstName = pilot.FirstName, LastName = pilot.LastName, PersonType = PersonType.Guest
            };

            dbContext.Persons.Add(person);
            dbContext.SaveChanges();

            return(person.Id);
        }
Ejemplo n.º 10
0
        public bool TryGetAirplane(AirplaneModel airplaneModel, out long airplaneId)
        {
            using var dbContext = new LocalDatabaseContext();

            var firstAirplane = dbContext.Airplanes.FirstOrDefault(airplane => airplane.Id == airplaneModel.Id);

            if (firstAirplane != null)
            {
                airplaneId = firstAirplane.Id;
                return(true);
            }
            else
            {
                airplaneId = 0;
                return(false);
            }
        }
Ejemplo n.º 11
0
        public IList <ReportModel> GetReport()
        {
            using var dbContext = new LocalDatabaseContext();

            var flightStarts = dbContext.FlightStarts
                               .Include(flight => flight.Glider)
                               .Include(flight => flight.Glider.Airplane)
                               .Include(flight => flight.Glider.Pilot)
                               .Include(flight => flight.Glider.Copilot)
                               .Include(flight => flight.Towplane)
                               .Include(flight => flight.Towplane.Airplane)
                               .Include(flight => flight.Towplane.Pilot)
                               .Include(flight => flight.Towplane.Copilot)
                               .OrderByDescending(start => start.Towplane.TakeoffTime);

            return(this.mapper.ProjectTo <ReportModel>(flightStarts).ToList());
        }
Ejemplo n.º 12
0
        public bool TryGetPerson(PersonModel personModel, out long personId)
        {
            using var dbContext = new LocalDatabaseContext();

            Person firstPerson = dbContext.Persons.FirstOrDefault(person => person.MemberId == personModel.MemberId);

            if (firstPerson != null)
            {
                personId = firstPerson.Id;
                return(true);
            }
            else
            {
                personId = 0;
                return(false);
            }
        }
Ejemplo n.º 13
0
        public long CreateClubMember(PersonModel pilot)
        {
            using var dbContext = new LocalDatabaseContext();

            var person = new Person
            {
                FirstName  = pilot.FirstName,
                LastName   = pilot.LastName,
                PersonType = PersonType.ClubMember,
                MemberId   = pilot.MemberId,
            };

            dbContext.Persons.Add(person);
            dbContext.SaveChanges();

            return(person.Id);
        }
Ejemplo n.º 14
0
        public long CreateFlight(CreateFlightModel model)
        {
            using var dbContext = new LocalDatabaseContext();

            var copilot = model.CopilotId != null
                ? dbContext.Persons.Find(model.CopilotId)
                : null;

            var flight = new Flight
            {
                Airplane    = dbContext.Airplanes.Find(model.AirplaneId),
                Copilot     = copilot,
                Pilot       = dbContext.Persons.Find(model.PilotId),
                TakeoffTime = model.TakeOffTime,
                Task        = model.Task
            };

            dbContext.Flights.Add(flight);
            dbContext.SaveChanges();

            return(flight.Id);
        }