Exemplo n.º 1
0
        public async System.Threading.Tasks.Task <IActionResult> LoginSubmitAsync(string email, string pwd)
        {
            var user = await _db.GetUser(email);

            //Specify on next view what the error was using ViewBag to send message
            if (user == null || ShaHash.ComputeSha256Hash(pwd) != user.Pwd)
            {
                ViewBag.UserLoginStatus = "failed";
                return(View("../Login/Login"));
            }

            ViewBag.UserLoginStatus = "success";

            HttpContext.Session.SetString("username", email);
            HttpContext.Session.SetString("name", user.Name);
            HttpContext.Session.SetInt32("isAdmin", user.IsAdmin ? 1 : 0);

            return(View("../Home/Index"));
        }
        public async Task TestPilotGetUser()
        {
            /// ARRANGE

            // setup PilotRepo to be tested
            var repo = new PilotRepo(_context);
            // setup pilot with name, email, aircraft and a password
            var pilot = CreatePilot("*****@*****.**");

            /// ACT

            await AddForTest(pilot);

            var foundPilot = repo.GetUser(pilot.EmailId).Result;

            /// ASSERT

            Assert.IsNotNull(foundPilot);
        }
Exemplo n.º 3
0
        public async System.Threading.Tasks.Task <IActionResult> ScheduleSubmitAsync(DateTime currentDate,
                                                                                     int hours,
                                                                                     int minutes,
                                                                                     string Route,
                                                                                     string Callsign,
                                                                                     float flightSpeed,
                                                                                     string pilotEmail)
        {
            if (pilotEmail == null)
            {
                pilotEmail = HttpContext.Session.GetString("username");
            }
            var getPilot = _db_pilots.GetUser(pilotEmail);

            try
            {
                Flight flight = new Flight
                {
                    FlightSpeed  = flightSpeed,
                    RouteId      = Route,
                    TimeOfFlight = currentDate.AddHours(hours).AddMinutes(minutes),
                    PilotEmailId = pilotEmail,
                    Pilot        = (Pilot)await getPilot,
                    Route        = (Route)await _db_route.GetRoute(Route)
                };
                await _db_flights.Add(flight);

                return(await UpdateScheduleViewFlightsAsync(flight.TimeOfFlight, Route, pilotEmail));
            }
            catch (DbUpdateException) {
                return(Content("debug 1"));
            }
            catch (InvalidOperationException) {
                return(await UpdateScheduleViewFlightsAsync(currentDate, Route, pilotEmail, true));
            }
        }