public async Task<ActionResult> ConfirmEmail(int userId, string code)
        {
            if (userId == 0 || code == null)
            {
                TempData.Add("confirmEmail", "No se ha podido confirmar el email");
                return View("Login");
            }
            IdentityResult result;
            try
            {
                var provider = new MachineKeyProtectionProvider();
                UserManager<User, int> um = new UserManager<User, int>(ur);
                um.UserTokenProvider = new DataProtectorTokenProvider<User, int>(provider.Create("EmailConfirmation"));
                result = await um.ConfirmEmailAsync(userId, code);
            }
            catch (ArgumentNullException)
            {
                // ConfirmEmailAsync throws when the userId is not found.
                TempData.Add("confirmEmail", "Usuario no encontrado");
                return View("Login");
            }
            catch(ArgumentException)
            {
                TempData.Add("confirmEmail", "El email ya ha sido validado anteriormente");
                return View("Login");
            }

            if (result.Succeeded)
            {
                TempData.Add("confirmEmail", "Se ha confirmado su email correctamente");
                return View("Login");
            }

            TempData.Add("confirmEmail", result);
            return View("Login");
        }
        public void EmailConfirmed()
        {
            using (UserStore<IdentityUser> store = new UserStore<IdentityUser>())
            {
                using (UserManager<IdentityUser> manager = new UserManager<IdentityUser>(store))
                {
                    manager.UserTokenProvider = new EmailTokenProvider<IdentityUser>();
                    var user = CreateTestUser();

                    var taskUserSet = manager.GenerateEmailConfirmationTokenAsync(user.Id);
                    taskUserSet.Wait();
                    Assert.IsFalse(string.IsNullOrWhiteSpace(taskUserSet.Result), "GenerateEmailConfirmationToken failed.");
                    string token = taskUserSet.Result;

                    var taskConfirm = manager.ConfirmEmailAsync(user.Id, token);
                    taskConfirm.Wait();
                    Assert.IsTrue(taskConfirm.Result.Succeeded, string.Concat(taskConfirm.Result.Errors));

                    user = manager.FindByEmail(user.Email);
                    var taskConfirmGet = store.GetEmailConfirmedAsync(user);
                    taskConfirmGet.Wait();
                    Assert.IsTrue(taskConfirmGet.Result, "Email not confirmed");

                    try
                    {
                        var task = store.SetEmailConfirmedAsync(null, true);
                        task.Wait();
                    }
                    catch (Exception ex)
                    {
                        Assert.IsNotNull(ex, "Argument exception not raised");
                    }

                    try
                    {
                        var task = store.GetEmailConfirmedAsync(null);
                        task.Wait();
                    }
                    catch (Exception ex)
                    {
                        Assert.IsNotNull(ex, "Argument exception not raised");
                    }

                }
            }
        }