Пример #1
0
 public FlightsController(TakeAFlightContext context, ApplicationDbContext userContext)
 {
     _context      = context;
     _Userscontext = userContext;
     //LoadDefaultData.LoadDefaulDestinationData(_context);
     //LoadDefaultData.CreateRandomFlightsData(_context);
 }
Пример #2
0
        public static void CreateRandomFlightsData(TakeAFlightContext context)
        {
            Random             rnd = new Random();
            List <Destination> destinationsList = context.Destinations.ToList();

            for (int i = 0; i < 200; i++)
            {
                int         randomIndex  = rnd.Next(0, destinationsList.Count);
                Destination selectedDest = destinationsList[randomIndex];
                //									year,  month,       day,  hour,     min,      sec
                DateTime deparuteData = new DateTime(2019, i % 12 + 1, i % 28 + 1, i % 23 + 1, i % 12 * 5, 0);
                TimeSpan durationTime = new TimeSpan(i % 5 + 1, i % 12 * 5, 0);
                double   price        = rnd.Next(500, 2000);
                Flight   tempFlight   = new Flight()
                {
                    DestinationID = selectedDest.DestinationID,
                    Departure     = deparuteData,
                    Duration      = durationTime,
                    Price         = price,
                    Destination   = selectedDest
                };
                context.Flight.Add(tempFlight);
            }
            context.SaveChanges();
        }
Пример #3
0
        public static void LoadDefaulDestinationData(TakeAFlightContext context)
        {
            var    Folder     = Directory.GetCurrentDirectory();
            string jsonString = File.ReadAllText(Folder + @"\bin\Debug\netcoreapp2.0\wwwroot\lib\Data\Destinastion.json");
            JArray jsonData   = JArray.Parse(jsonString);

            List <Destination> destList = jsonData.ToObject <List <Destination> >();

            destList.ForEach(obj => context.Destinations.Add(obj));
            context.SaveChanges();
        }
Пример #4
0
 public ManageController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     IEmailSender emailSender,
     ILogger <ManageController> logger,
     UrlEncoder urlEncoder, TakeAFlightContext dbContext)
 {
     _userManager        = userManager;
     _signInManager      = signInManager;
     _emailSender        = emailSender;
     _logger             = logger;
     _urlEncoder         = urlEncoder;
     _takeAFlightContext = dbContext;
 }
Пример #5
0
 public AccountController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     IEmailSender emailSender,
     ILogger <AccountController> logger,
     RoleManager <IdentityRole> _role,
     ApplicationDbContext userContext,
     TakeAFlightContext dbContext)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _emailSender   = emailSender;
     _logger        = logger;
     _roleManager   = _role;
     _Usercontext   = userContext;
     _DbContext     = dbContext;
     //await LoadDefaultData.CreateRolesandUsers(_roleManager, _userManager, dbContext);
 }
Пример #6
0
        //Creating Admin Role to handle admin options like edit and delete a flight for example.
        public static async Task CreateRolesandUsers(RoleManager <IdentityRole> roleManager,
                                                     UserManager <ApplicationUser> userManager, TakeAFlightContext takeAFlight)
        {
            bool isRoleExist = await roleManager.RoleExistsAsync("Admin");

            if (!isRoleExist)
            {
                // first we create Admin rool
                var role = new IdentityRole();
                role.Name = "Admin";
                await roleManager.CreateAsync(role);

                //Here we create a Admin super user who will maintain the website

                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";

                string userPWD = "Admin1234!";

                IdentityResult chkUser = await userManager.CreateAsync(user, userPWD);

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = await userManager.AddToRoleAsync(user, "Admin");
                }

                var passenger = new Passenger
                {
                    FirstName         = "roei",
                    ApplicationUserID = user.Id,
                    DateOfBirth       = new DateTime(),
                    Gender            = Sex.Man,
                    IdPassenger       = 123456789,
                    LastName          = "bbb",
                    Nationality       = Nationality.Europe,
                    User = user
                };
                await takeAFlight.AddAsync(passenger);

                await takeAFlight.SaveChangesAsync();
            }
        }
Пример #7
0
 public HomeController(TakeAFlightContext context)
 {
     dbContext = context;
 }
Пример #8
0
 public ViewCartController(TakeAFlightContext context, ApplicationDbContext userContext)
 {
     _context      = context;
     _Userscontext = userContext;
 }