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

                // Todo: this will throw an error if the password isn't correct.. hence ViewModel password regex validation
                if (result.Errors.Any())
                {
                    AddErrors(result);
                    return View(model);
                }


                UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, user.FirstName));

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, false, 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>");

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

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        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
                ExternalLoginInfo info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new SchedulerUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName };
                IdentityResult result = await UserManager.CreateAsync(user);

                UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, user.FirstName));
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, false, false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        public EventsController Arrange_Event_Controller()
        {
            var testEvent1 = new Event { Id = 1 };
            var testEvent2 = new Event { Id = 2 };

            var testUser = new SchedulerUser { Id = "99fd20b8-7194-31e1-945b-e6736c732499", Events = new List<Event> { testEvent1, testEvent2 } };

            var users = new List<SchedulerUser> { testUser }.AsQueryable();
            var service = new Service();


            var mockSet = new Mock<DbSet<SchedulerUser>>();
            mockSet.As<IQueryable<SchedulerUser>>().Setup(m => m.Provider).Returns(users.Provider);
            mockSet.As<IQueryable<SchedulerUser>>().Setup(m => m.Expression).Returns(users.Expression);
            mockSet.As<IQueryable<SchedulerUser>>().Setup(m => m.ElementType).Returns(users.ElementType);
            mockSet.As<IQueryable<SchedulerUser>>().Setup(m => m.GetEnumerator()).Returns(users.GetEnumerator);

            var context = new Mock<SchedulerDbContext>();
            context.Setup(c => c.Users).Returns(mockSet.Object);

            var controller = new EventsController(context.Object, service) { ControllerContext = MockContext() };

            return controller;
        }