コード例 #1
0
        //Post method for registration
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                // var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email };

                ApplicationUser user;

                if ((Input.UserRole == "WVUEmployee") || (Input.UserRole == "ParkingEmployee"))
                {
                    user = new WVUEmployee(Input.FirstName, Input.LastName, Input.Email, Input.PhoneNumber, Input.Password, Input.DepartmentID);
                }
                else
                {
                    user = new Visitor(Input.FirstName, Input.LastName, Input.Email, Input.PhoneNumber, Input.Password, Input.OrganizationName);
                }

                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, Input.UserRole);

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email and change your password",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedEmail)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
コード例 #2
0
        //[HttpPost]
        public IActionResult DetermineDistanceMatrixResult(string sortOrder, DistanceMatrixViewModel inputViewModel)
        {
            //Ternary conditional operator
            //if()? true : false
            ViewData["DistanceSortParam"] = String.IsNullOrEmpty(sortOrder) ? "distance_desc" : "";

            ViewData["DurationSortParam"] = sortOrder == "duration" ? "duration_desc" : "duration";

            string WVUEmployeeID = inputViewModel.WvuEmployeeID;

            //To use session objects, need to set statements in Startup.cs
            if (WVUEmployeeID != null)
            {
                HttpContext.Session.SetString("WVUEmployeeID", WVUEmployeeID);
            }

            if (!String.IsNullOrEmpty(HttpContext.Session.GetString("WVUEmployeeID")))
            {
                WVUEmployeeID = HttpContext.Session.GetString("WVUEmployeeID");
            }

            WVUEmployee employee = iApplicationUserRepo.FindWvuEmployee(WVUEmployeeID);
            string      origin   = employee.Department.DepartmentAddress;

            if (inputViewModel.WvuEmployeeID != null)
            {
                inputViewModel = CreateDistanceMatrix(origin);
                HttpContext.Session.SetComplexData("inputViewModel", inputViewModel);
            }
            else
            {
                inputViewModel = HttpContext.Session.GetComplexData <DistanceMatrixViewModel>("inputViewModel");
            }


            switch (sortOrder)
            {
            case "distance_desc": inputViewModel.DistanceMatrix = inputViewModel.DistanceMatrix.OrderByDescending(d => d.DistanceInMiles).ToList();
                ViewData["DistanceImage"] = "descending";
                break;

            case "duration": inputViewModel.DistanceMatrix = inputViewModel.DistanceMatrix.OrderBy(d => d.DurationInMinutes).ToList();
                break;

            case "duration_desc": inputViewModel.DistanceMatrix = inputViewModel.DistanceMatrix.OrderByDescending(d => d.DurationInMinutes).ToList();
                ViewData["DurationImage"] = "descending";
                break;

            default: inputViewModel.DistanceMatrix = inputViewModel.DistanceMatrix.OrderBy(d => d.DistanceInMiles).ToList();
                break;
            }


            DropDownListForEmployees();

            return(View("DetermineDistanceMatrix", inputViewModel));
        }
コード例 #3
0
        public FileResult DisplayParkingLotsOnMap()
        {
            List <Lot>       allLots    = iLotRepo.ListAllLots();
            List <MapMarker> mapMarkers = new List <MapMarker>();

            foreach (Lot eachLot in allLots)
            {
                MapMarker       eachMapMarker = new MapMarker();
                List <Location> locations     = new List <Location>();
                Location        eachLocation  = new Location(eachLot.LotAddress);
                locations.Add(eachLocation);
                eachMapMarker.Locations = locations;

                eachMapMarker.Label = eachLot.LotNumber; //can only be 0-9 or A-Z

                eachMapMarker.Color = GoogleApi.Entities.Maps.StaticMaps.Request.Enums.MapColor.Blue;

                mapMarkers.Add(eachMapMarker);
            }

            StaticMapsRequest staticMapsRequest = new StaticMapsRequest();

            if (!String.IsNullOrEmpty(HttpContext.Session.GetString("WVUEmployeeID")))
            {
                string      WVUEmployeeID = HttpContext.Session.GetString("WVUEmployeeID");
                WVUEmployee employee      = iApplicationUserRepo.FindWvuEmployee(WVUEmployeeID);
                string      origin        = employee.Department.DepartmentAddress;

                MapMarker       eachMapMarker    = new MapMarker();
                List <Location> locations        = new List <Location>();
                Location        employeeLocation = new Location(origin);
                locations.Add(employeeLocation);
                eachMapMarker.Locations = locations;

                eachMapMarker.Label = "E"; //can only be 0-9 or A-Z

                eachMapMarker.Color = GoogleApi.Entities.Maps.StaticMaps.Request.Enums.MapColor.Purple;

                mapMarkers.Add(eachMapMarker);

                staticMapsRequest.Center = employeeLocation;
            }


            staticMapsRequest.Key = "AIzaSyBRT65jDLR_mhb4yzGbMBMaIZALz57028A";

            staticMapsRequest.Markers = mapMarkers;

            staticMapsRequest.Type = GoogleApi.Entities.Maps.StaticMaps.Request.Enums.MapType.Roadmap;

            StaticMapsResponse response = GoogleApi.GoogleMaps.StaticMaps.Query(staticMapsRequest);

            var file = response.Buffer;

            return(File(file, "image/jpeg"));
        }
コード例 #4
0
        public List <ApplicationUser> CreateMockAppUsersData()
        {
            List <ApplicationUser> mockAppUserData = new List <ApplicationUser>();

            Visitor visitor = new Visitor("Test", "Visitor1", "*****@*****.**", "3040001111", "Test.Visitor1", "TestVisitorOrganization");

            visitor.Id = "1";
            mockAppUserData.Add(visitor);

            WVUEmployee employee = new WVUEmployee("Test", "Employee1", "*****@*****.**", "3041110000", "Test.Employee1", 1);

            employee.Id = "2";
            mockAppUserData.Add(employee);

            return(mockAppUserData);
        }
コード例 #5
0
        public List <WVUEmployee> CreateMockWVUEmployeeData()
        {
            List <WVUEmployee> mockWVUEmployeeData = new List <WVUEmployee>();

            WVUEmployee employee = new WVUEmployee("John", "Doe", "*****@*****.**", "3041112222", "jdoe", 1);

            employee.PermitID = 1;
            mockWVUEmployeeData.Add(employee);

            employee = new WVUEmployee("Jane", "Doe", "*****@*****.**", "3042222222", "jadoe", 2);
            mockWVUEmployeeData.Add(employee);

            employee = new WVUEmployee("Dan", "Johnson", "*****@*****.**", "3042223333", "djohnson", 1);
            mockWVUEmployeeData.Add(employee);

            employee = new WVUEmployee("Jennifer", "Smith", "*****@*****.**", "3043332222", "jsmith", 2);
            mockWVUEmployeeData.Add(employee);

            return(mockWVUEmployeeData);
        }
コード例 #6
0
        public static async Task InitializeAsync(IServiceProvider services)
        {
            ApplicationDbContext database
                = services.GetRequiredService <ApplicationDbContext>();

            //To add roles we need to create a RoleManager
            RoleManager <IdentityRole> roleManager
                = services.GetRequiredService <RoleManager <IdentityRole> >();

            //To add app users, we need to create a UserManager object
            UserManager <ApplicationUser> userManager = services.GetRequiredService <UserManager <ApplicationUser> >();

            if (!database.Roles.Any())
            {
                IdentityRole role = new IdentityRole("WVUEmployee");
                await roleManager.CreateAsync(role);

                role = new IdentityRole("ParkingEmployee");
                await roleManager.CreateAsync(role);

                role = new IdentityRole("Visitor");
                await roleManager.CreateAsync(role);
            }

            if (!database.Departments.Any())
            {
                Department department = new Department("MIS", "1601 University Ave, Morgantown, WV 26506");
                database.Departments.Add(department);
                database.SaveChanges();

                department = new Department("Mechanical Engineering", "1306 Evansdale Dr, Morgantown, WV 26506");
                database.Departments.Add(department);
                database.SaveChanges();

                department = new Department("Pediatrics", "1 Medical Center Dr, Morgantown, WV 26506");
                database.Departments.Add(department);
                database.SaveChanges();

                department = new Department("WVU Parking Office", "Maiden Ln, Morgantown, WV 26506");
                database.Departments.Add(department);
                database.SaveChanges();
            }

            //Populate all the appusers together
            if (!database.ApplicationUsers.Any())
            {
                Visitor visitor = new Visitor("Test", "Visitor1", "*****@*****.**", "3040000001", "TestVisitor1", "Mylan");
                visitor.EmailConfirmed = true;
                await userManager.CreateAsync(visitor);

                await userManager.AddToRoleAsync(visitor, "Visitor");

                WVUEmployee employee = new WVUEmployee("Test", "WVUEmployee1", "*****@*****.**", "3040000002", "TestWVUEmployee1", 1);
                employee.EmailConfirmed = true;
                await userManager.CreateAsync(employee);

                await userManager.AddToRoleAsync(employee, "WVUEmployee");

                employee = new WVUEmployee("Test", "WVUEmployee2", "*****@*****.**", "3040000003", "TestWVUEmployee2", 2);
                employee.EmailConfirmed = true;
                await userManager.CreateAsync(employee);

                await userManager.AddToRoleAsync(employee, "WVUEmployee");

                employee = new WVUEmployee("Test", "WVUEmployee3", "*****@*****.**", "3040000004", "TestWVUEmployee3", 3);
                employee.EmailConfirmed = true;
                await userManager.CreateAsync(employee);

                await userManager.AddToRoleAsync(employee, "WVUEmployee");

                WVUEmployee parkingEmployee = new WVUEmployee("Test", "ParkingEmployee1", "*****@*****.**", "3040000003", "TestParkingEmployee1", 4);
                employee.EmailConfirmed = true;
                await userManager.CreateAsync(parkingEmployee);

                await userManager.AddToRoleAsync(parkingEmployee, "WVUEmployee");

                await userManager.AddToRoleAsync(parkingEmployee, "ParkingEmployee");
            }

            //If you are populating each AppUser sub class seperately
            if (database.WVUEmployees.Any())
            {
            }

            if (!database.Lots.Any()) // only if no data or rows are in lots table
            {
                Lot lot = new Lot("1", "Art Museum Education Center",
                                  "2 Fine Arts Dr, Morgantown, WV 26506", 140);
                lot.CurrentOccupancy = 140;
                database.Lots.Add(lot);
                database.SaveChanges();

                lot = new Lot("4", "Student Rec Center",
                              "2001 Rec Center Dr, Morgantown, WV 26506", 225);
                database.Lots.Add(lot);
                database.SaveChanges();

                lot = new Lot("7", "College of B&E",
                              "600 University Ave, Morgantown, WV 26506", 150);

                database.Lots.Add(lot);
                database.SaveChanges();

                lot = new Lot("10", "WVU Hospital",
                              "1 Medical Center Dr, Morgantown, WV 26506", 300);


                database.Lots.Add(lot);
                database.SaveChanges();

                lot = new Lot("12", "WVU Urgent Care", "301 Suncrest Towne Centre Drive, Morgantown, WV 26505", 200);
                database.Lots.Add(lot);
                database.SaveChanges();

                lot = new Lot("15", "WVU Medicine", "6040 University Town Centre Dr, Morgantown, WV 26501",
                              300);
                lot.CurrentOccupancy = 250;
                database.Lots.Add(lot);
                database.SaveChanges();
            }

            if (!database.LotTypes.Any())
            {
                LotType lotType = new LotType("Short Term Paid Lot");
                database.LotTypes.Add(lotType);
                database.SaveChanges();

                lotType = new LotType("Free");
                database.LotTypes.Add(lotType);
                database.SaveChanges();

                lotType = new LotType("Permit");
                database.LotTypes.Add(lotType);
                database.SaveChanges();
            }

            if (!database.LotStatuses.Any())
            {
                CultureInfo cultureInfo = new CultureInfo("en-US");

                DateTime startTime = DateTime.Parse("8:00 AM", cultureInfo, DateTimeStyles.NoCurrentDateDefault);
                DateTime endTime   = DateTime.Parse("4:00 PM", cultureInfo, DateTimeStyles.NoCurrentDateDefault);

                //First object/row  (weekday short term)
                LotStatus lotStatus = new LotStatus("Weekday", startTime, endTime, 0.50, 1, 1);
                database.LotStatuses.Add(lotStatus);
                database.SaveChanges();

                lotStatus = new LotStatus("Weekday", startTime, endTime, 0.50, 2, 1);
                database.LotStatuses.Add(lotStatus);
                database.SaveChanges();

                lotStatus = new LotStatus("Weekend", startTime, endTime, 0.00, 2, 2);
                database.LotStatuses.Add(lotStatus);
                database.SaveChanges();

                lotStatus = new LotStatus("Weekday", startTime, endTime, 0.00, 3, 3);
                database.LotStatuses.Add(lotStatus);
                database.SaveChanges();

                startTime = DateTime.Parse("4:01 PM", cultureInfo, DateTimeStyles.NoCurrentDateDefault);
                endTime   = DateTime.Parse("7:59 AM", cultureInfo, DateTimeStyles.NoCurrentDateDefault);

                //Second object/row (weekday free)
                lotStatus = new LotStatus("Weekday", startTime, endTime, 0.00, 1, 2);
                database.LotStatuses.Add(lotStatus);
                database.SaveChanges();

                lotStatus = new LotStatus("Weekday", startTime, endTime, 0.00, 2, 2);
                database.LotStatuses.Add(lotStatus);
                database.SaveChanges();

                lotStatus = new LotStatus("Weekday", startTime, endTime, 0.00, 3, 2);
                database.LotStatuses.Add(lotStatus);
                database.SaveChanges();
            }

            if (!database.Permits.Any())
            {
                DateTime permitStartDate = new DateTime(2020, 1, 1);
                DateTime permitEndDate   = new DateTime(2020, 12, 31);

                WVUEmployee parkingEmployee   = database.WVUEmployees.Where(e => e.Email == "*****@*****.**").FirstOrDefault();
                string      parkingEmployeeID = parkingEmployee.Id;

                WVUEmployee user   = database.WVUEmployees.Where(e => e.Email == "*****@*****.**").FirstOrDefault();
                string      userID = user.Id;

                Permit permit = new Permit(500.00, permitStartDate, permitEndDate, userID, parkingEmployeeID);
                database.Permits.Add(permit);
                database.SaveChanges();

                user.PermitID = permit.PermitID;
                database.WVUEmployees.Update(user);
                database.SaveChanges();


                //user = database.WVUEmployees.Where(e => e.Email == "*****@*****.**").FirstOrDefault();
                //userID = user.Id;

                //permit = new Permit(500.00, permitStartDate, permitEndDate, userID);
                //database.Permits.Add(permit);
                //database.SaveChanges();

                //user.PermitID = permit.PermitID;
                //database.WVUEmployees.Update(user);
                //database.SaveChanges();


                user   = database.WVUEmployees.Where(e => e.Email == "*****@*****.**").FirstOrDefault();
                userID = user.Id;

                permit = new Permit(500.00, permitStartDate, permitEndDate, userID, parkingEmployeeID);
                database.Permits.Add(permit);
                database.SaveChanges();

                user.PermitID = permit.PermitID;
                database.WVUEmployees.Update(user);
                database.SaveChanges();



                //user = database.WVUEmployees.Where(e => e.Email == "*****@*****.**").FirstOrDefault();
                //userID = user.Id;

                //permit = new Permit(500.00, permitStartDate, permitEndDate, userID);
                //database.Permits.Add(permit);
                //database.SaveChanges();

                //user.PermitID = permit.PermitID;
                //database.WVUEmployees.Update(user);
                //database.SaveChanges();
            }
        } //end method