Esempio n. 1
0
        private static void Main()
        {
            using (var flightManagerDbContext = new FlightManagerDbContext())
            {
                flightManagerDbContext.Database.Migrate();
                for (int i = 0; i < 10; ++i)
                {
                    flightManagerDbContext.Set <Aircraft>().Add(
                        new Aircraft()
                    {
                        Name = string.Concat("Aircraft ", i), Count = 5, InFlyFuelConsumption = (i * 158.99), InTakeOffFuelConsumption = (58.45 + i), PassengerCapacity = 200, MaxSpeed = "Not Defined"
                    }
                        );
                }

                Random random = new Random();
                for (int i = 0; i < 100; ++i)
                {
                    flightManagerDbContext.Set <Airport>().Add(
                        new Airport()
                    {
                        Name = string.Concat("Airport", i), Latitude = random.NextDouble(), Longitude = random.NextDouble()
                    }
                        );
                }

                flightManagerDbContext.SaveChanges();
            }
        }
 public FlightController(IUserService UserService, IFlightService FlightService, IReservationService ReservationService, FlightManagerDbContext context)
 {
     this.FlightService      = FlightService;
     this.UserService        = UserService;
     this.ReservationService = ReservationService;
     this.context            = context;
 }
Esempio n. 3
0
 public RegisterModel(
     UserManager <User> userManager,
     SignInManager <User> signInManager,
     FlightManagerDbContext flightManagerDbContext)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     this.flightManagerDbContext = flightManagerDbContext;
 }
 public ReservationService(FlightManagerDbContext context, IEmailSender emailSender)
 {
     this.context     = context;
     this.emailSender = emailSender;
 }
Esempio n. 5
0
 public AirlineRepository(FlightManagerDbContext context)
 {
     this.context = context;
 }
Esempio n. 6
0
 public UserController(FlightManagerDbContext context)
 {
     this.context = context;
 }
Esempio n. 7
0
 public BaseController()
 {
     //Initialize the DbContext for one HTTP Request. It will be dispose ate the end of the request when UnitOfWork will be disposed
     _flightManagerDbContext = new FlightManagerDbContext();
 }
Esempio n. 8
0
 /// <summary>
 /// Сетва базата данни
 /// </summary>
 /// <param name="context"></param>
 public ReservationService(FlightManagerDbContext context)
 {
     this.dbContext = context;
 }
Esempio n. 9
0
 public UserService(FlightManagerDbContext context, UserManager <AppUser> userManager, RoleManager <IdentityRole> roleManager)
 {
     this.context     = context;
     this.userManager = userManager;
     this.roleManager = roleManager;
 }
Esempio n. 10
0
 // private readonly RoleManager<IdentityRole> roleManager;
 public HomeController(FlightManagerDbContext flightManagerDbContext)//, RoleManager<IdentityRole> roleManager)
 {
     this.context = flightManagerDbContext;
     // this.roleManager = roleManager;
 }
Esempio n. 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="flightManagerDbContext">Db Context instanciate in the UnitOfWork</param>
 public Repository(FlightManagerDbContext flightManagerDbContext)
 {
     _flightManagerDbContext = flightManagerDbContext;
     _entities = flightManagerDbContext.Set <TEntity>();
 }
Esempio n. 12
0
 public UserService(FlightManagerDbContext context)
 {
     dBContext = context;
 }
 /// <summary>
 /// Сетва базата данни
 /// </summary>
 /// <param name="context"></param>
 public UserServices(FlightManagerDbContext context)
 {
     this.dbContext = context;
 }
Esempio n. 14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="flightManagerDbContext">DbContext created </param>
 public UnitOfWork(FlightManagerDbContext flightManagerDbContext)
 {
     _flightManagerDbContext = flightManagerDbContext;
 }
Esempio n. 15
0
 public UserController(FlightManagerDbContext context, IUserService service, UserManager <AppUser> userManager)
 {
     this.context     = context;
     this.service     = service;
     this.userManager = userManager;
 }
Esempio n. 16
0
 public UserService(FlightManagerDbContext context, UserManager <User> userManager)
 {
     this.context = context;
 }
Esempio n. 17
0
 public FlightService(FlightManagerDbContext context)
 {
     this.context = context;
 }
Esempio n. 18
0
 public ReservationController(FlightManagerDbContext context, EmailConfiguration emailConfiguration)
 {
     this.context            = context;
     this.emailConfiguration = emailConfiguration;
 }
Esempio n. 19
0
 /// <summary>
 /// Constructor used to assign the DBContetxt to the service
 /// </summary>
 /// <param name="flightManagerDbContext">DbContext for Flight Manager Simulator</param>
 public AirportService(FlightManagerDbContext flightManagerDbContext)
 {
     _flightManagerDbContext = flightManagerDbContext;
     this.UnitOfWork         = new UnitOfWork(_flightManagerDbContext);
 }
Esempio n. 20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, FlightManagerDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });

            var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();

            if (!roleManager.RoleExistsAsync("admin").Result)
            {
                roleManager.CreateAsync(new IdentityRole("admin")).Wait();
            }
            if (!roleManager.RoleExistsAsync("employee").Result)
            {
                roleManager.CreateAsync(new IdentityRole("employee")).Wait();
            }

            var userManager = serviceProvider.GetRequiredService <UserManager <AppUser> >();

            if (!context.Users.Any())
            {
                //Create the one and only admin
                var user = new AppUser()
                {
                    UserName    = Configuration.GetSection("AdminCredentials")["Username"],
                    Email       = Configuration.GetSection("AdminCredentials")["Email"],
                    FirstName   = Configuration.GetSection("AdminCredentials")["FirstName"],
                    LastName    = Configuration.GetSection("AdminCredentials")["LastName"],
                    UCN         = Configuration.GetSection("AdminCredentials")["UCN"],
                    Address     = Configuration.GetSection("AdminCredentials")["Address"],
                    PhoneNumber = Configuration.GetSection("AdminCredentials")["PhoneNumber"],
                };

                var pass        = Configuration.GetSection("AdminCredentials")["Password"];
                var createdUser = userManager.CreateAsync(user, pass);

                if (createdUser.Result.Succeeded)
                {
                    userManager.AddToRoleAsync(user, "admin").Wait();
                    context.SaveChanges();
                }
            }
        }