public bool addRider(Rider rider)
 {
     bool isAdded = false;
     var db = new MXEugeneDBContext();
     Rider fRider = (from r in db.Riders
                     where r.FName == rider.FName &&
                     r.LName == rider.LName
                     select r).FirstOrDefault<Rider>();
     if (fRider == null)
     {
         db.Riders.Add(rider);
         db.SaveChanges();
         isAdded = true;
     }
     return isAdded;
 }
        public void Rider_Class()
        {
            const int RIDERID = 100;
            const string FNAME = "Fist";
            const string LNAME = "Last";
            const string EMAIL = "*****@*****.**";
            const string ADDRESS = "1111 Test Street";
            const string CITY = "Test City";
            const string STATE = "Test State";
            const int ZIP = 10000;
            const string PHONE = "541-111-0000";
            DateTime DATEOFBIRTH = DateTime.Parse("1/14/2000");
            const int AGE = 21;
            const bool RELEASE = true;
            const bool PARENT = false;

            Rider TestRider = new Rider();
            TestRider.RiderID = RIDERID;
            TestRider.FName = FNAME;
            TestRider.LName = LNAME;
            TestRider.EMail = EMAIL;
            TestRider.Address = ADDRESS;
            TestRider.City = CITY;
            TestRider.State = STATE;
            TestRider.Zip = ZIP;
            TestRider.Phone = PHONE;
            TestRider.DOB = DATEOFBIRTH;
            TestRider.Age = AGE;
            TestRider.ReleaseSigned = RELEASE;
            TestRider.ParentReleaseSigned = PARENT;

            Assert.AreEqual(RIDERID, TestRider.RiderID);
            Assert.AreEqual(FNAME, TestRider.FName);
            Assert.AreEqual(LNAME, TestRider.LName);
            Assert.AreEqual(EMAIL, TestRider.EMail);
            Assert.AreEqual(ADDRESS, TestRider.Address);
            Assert.AreEqual(CITY, TestRider.City);
            Assert.AreEqual(STATE, TestRider.State);
            Assert.AreEqual(ZIP, TestRider.Zip);
            Assert.AreEqual(PHONE, TestRider.Phone);
            Assert.AreEqual(DATEOFBIRTH, TestRider.DOB);
            Assert.AreEqual(AGE, TestRider.Age);
            Assert.AreEqual(RELEASE, TestRider.ReleaseSigned);
            Assert.AreEqual(PARENT, TestRider.ParentReleaseSigned);
        }
 public ActionResult AddRider(Rider newRider)
 {
     if (Session[MvcApplication.USER] != "Admin")
         return View("Login", "Account");
     else
     {
         if (ModelState.IsValid)
         {
             // DateTime.Parse("1/1/2011")
             Rider rider1 = new Rider() { FName = newRider.FName, LName = newRider.LName, DOB = newRider.DOB, Address = newRider.Address, Age = newRider.Age, City = newRider.City, EMail = newRider.EMail, Phone = newRider.Phone, ParentReleaseSigned = false, State = newRider.State, Zip = newRider.Zip, ReleaseSigned = true };
             if (RiderRepo.addRider(rider1) == true)
             {
                 // Once a new user is added then is it stored in the session.
                 Session[MvcApplication.USER] = (from r in RiderRepo.Rider
                                                 where r.FName == rider1.FName &&
                                                 r.LName == newRider.LName
                                                 select r.RiderID).FirstOrDefault<int>();
                 //for testing
                 Session[MvcApplication.MESSAGE] = "User was added";
                 // GOTO: Dashboard
                 return RedirectToAction("Index");
             }
         }
         // GOTO: Log-in
         Session[MvcApplication.MESSAGE] = "Error Rider was not added.";
         return RedirectToAction("Index");
     }
 }
 public ActionResult EditRider(Rider rider)
 {
     if (Session[MvcApplication.USER] == null)
         return View("Login", "Account");
     else
     {
         if (ModelState.IsValid)
         {
             if (RiderRepo.editRider(rider))
             {
                 //GOTO: Dashboard
                 Session[MvcApplication.MESSAGE] = "Your informaion was updated.";
                 return RedirectToAction("Index");
             }
         }
         // GOTO: Update Informaion
         Session[MvcApplication.MESSAGE] = "You informain was not updated.";
         return RedirectToAction("Index");
     }
 }
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }

                Rider nRider = new Rider() { EMail = model.Email };
                RiderRepo.addRider(nRider);
                Rider fRider = RiderRepo.Rider.Where(r => r.EMail == model.Email).FirstOrDefault<Rider>();
                var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, RiderID = fRider.RiderID };

                IdentityResult result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent: false);
                        
                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // SendEmail(user.Email, callbackUrl, "Confirm your account", "Please confirm your account by clicking this link");
                        
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                
                Rider nRider = new Rider() { EMail = model.Email, FName = model.FName, LName = model.LName, Address = model.Address, City = model.City, State = model.State, Zip = model.Zip, Phone = model.Phone, DOB = DateTime.Parse(model.DOB.Date.ToString()) };
                RiderRepo.addRider(nRider);
                Rider fRider = RiderRepo.Rider.Where(r => r.EMail == model.Email).FirstOrDefault<Rider>();
                var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, RiderID = fRider.RiderID };
                
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    Session[MvcApplication.USER] = RiderRepo.Rider.Where(r => r.RiderID == user.RiderID).FirstOrDefault<Rider>();
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public bool editRider(Rider rider)
        {
            bool isUpdated = false;
            var db = new MXEugeneDBContext();
            Rider fRider = db.Riders.Where(r => r.RiderID == rider.RiderID).FirstOrDefault<Rider>();
            if (fRider != null)
            {
                fRider.FName = rider.FName;
                fRider.LName = rider.LName;
                fRider.EMail = rider.EMail;
                fRider.City = rider.City;
                fRider.State = rider.State;
                fRider.Zip = rider.Zip;
                fRider.Phone = rider.Phone;
                fRider.DOB = rider.DOB;
                fRider.Age = rider.Age;
                fRider.ReleaseSigned = rider.ReleaseSigned;
                fRider.ParentReleaseSigned = rider.ParentReleaseSigned;

                db.SaveChanges();
                isUpdated = true;
            }
            return isUpdated;
        }