public ActionResult ExternalLoginAndRegistration(CharityExternalRegister model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (MyDbContext db = new MyDbContext())
                {
                    User user = db.Users.FirstOrDefault(u => u.UserName.ToLower() == model.EEmailAddress.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        User newUser = db.Users.Add(new User
                        {
                            UserName = model.EEmailAddress.ToUpper(),
                            ContactFirstName = model.EContactFirstName,
                            ContactLastName = model.EContactLastName,
                            Title = model.ETitle,
                            PhoneNumber = model.EPhoneNumber,
                            PhoneNoExtension = model.EPhoneNoExtension,
                            EmailAddress = model.EEmailAddress,
                            UserType = 1
                        });

                        db.Charities.Add(new Charity
                        {
                            CharityName = model.ECharityName,
                            Mission = model.EMission,
                            LocationServed = model.ELocationServed,
                            EIN = model.EEIN,
                            StreetAddress = model.EStreetAddress,
                            StreetAddress2 = model.EStreetAddress2,
                            City = model.ECity,
                            State = model.EState,
                            ZipCode = model.EZipCode,
                            UId = newUser.UserId
                        });

                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.EEmailAddress.ToUpper());

                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        string EmailSubject = "Charity Join - Project Give I.T.";
                        SendEmailConfirmation(model.EEmailAddress, model.EEmailAddress.ToUpper(), EmailSubject);
                        return RedirectToAction("RegConfirmation", "Charity");
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (MyDbContext db = new MyDbContext())
                {
                    User user = db.Users.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.Users.Add(new User { UserName = model.UserName });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }