public void ThatFirstNameisAddedToANewInstanceOfMember()
        {
            var member = new ApplicationUser {  FirstName = "Paul", LastName = "Redshaw", EmailAddress="*****@*****.**"};

            Assert.AreEqual("Paul", member.FirstName);
        }
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "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");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        //Create default User roles and Admin user for login
        private void CreateRolesandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
            var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));

            // Creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("Admin"))
            {
                // Create Admin roll
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);
                // Create an Admin super user who will maintain the website

                        var user = new ApplicationUser();
                        user.UserName = "******";
                        user.FirstName = "Admin";
                        user.LastName = "RDCC";
                        user.EmailAddress = "*****@*****.**";

                        string userPWD = "Rdcc1234!";

                        var chkUser = userManager.Create(user, userPWD);
                        var adminRole = roleManager.FindByName("Admin");
                        //Add default User to Role Admin
                        if (chkUser.Succeeded)
                        {
                            var result1 = userManager.AddToRole(user.Id, "Admin");

                        }

            }

            // creating Creating Member role
            if (!roleManager.RoleExists("Member"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Member";
                roleManager.Create(role);

            }

            // creating Creating Chairman role
            if (!roleManager.RoleExists("Chairman"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Chairman";
                roleManager.Create(role);

            }
            // creating Creating Secretary role
            if (!roleManager.RoleExists("Secretary"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Secretary";
                roleManager.Create(role);

            }

            // creating Creating Programme Secretary role
            if (!roleManager.RoleExists("Programme Secretary"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Programme Secretary";
                roleManager.Create(role);

            }

            // creating Creating Treasurer role
            if (!roleManager.RoleExists("Treasurer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Treasurer";
                roleManager.Create(role);

            }
            // creating Creating Committee Member role
            if (!roleManager.RoleExists("Committee Member"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Committee Member";
                roleManager.Create(role);

            }

            // creating Creating Webmaster role
            if (!roleManager.RoleExists("Webmaster"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Webmaster";
                roleManager.Create(role);

            }

            if (!roleManager.RoleExists("Publicity Officer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Publicity Officer";
                roleManager.Create(role);

            }
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName = model.FirstName + " " + model.LastName,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: 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);
                    await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    //Assign Role to user Here     
                    //await this.UserManager.AddToRoleAsync(user.Id, model.UserRoles);   

                    return RedirectToAction("Index", "Home", new { area = "Member" });
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }