public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:

                VoterDetail sess = db.VoterDetails.FirstOrDefault(x => x.emailId == model.Email);
                if (sess != null)
                {
                    Session.Add("vin", sess.voterId);
                }
                if (sess == null)
                {
                    RedirectToAction("About", "Home");
                }

                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                    //string small_alphabets = "abcdefghijklmnopqrstuvwxyz";
                    string numbers = "1234567890";

                    string characters = numbers;

                    characters += alphabets + numbers;
                    bool isalreadyexist;
                    int  length = 6;

                    //                Console.WriteLine("outside do while ");

                    string vin;
                    do
                    {
                        //Console.WriteLine("in outer do while ");
                        vin = string.Empty;
                        for (int i = 0; i < length; i++)
                        {
                            string character = string.Empty;
                            //                        Console.WriteLine("in for loop "+vin);
                            do
                            {
                                int index = new Random().Next(0, characters.Length);
                                character = characters.ToCharArray()[index].ToString();
                            } while (vin.IndexOf(character) != -1);
                            vin += character;
                            //                      Console.WriteLine("in outer do while  last for stmt "+vin);
                        }
                        isalreadyexist = db.VoterDetails.Any(x => x.voterId == vin);
                    } while (isalreadyexist == true);

                    VoterDetail voter = new VoterDetail();
                    //            Console.WriteLine("At last "+vin);



                    voter.voterId   = vin;
                    voter.emailId   = model.Email;
                    voter.age       = model.age;
                    voter.place     = model.place;
                    voter.voterName = model.voterName;


                    db.VoterDetails.Add(voter);

                    Session.Add("vin", vin);
                    db.SaveChanges();


                    UserManager.AddToRole(user.Id, "Users");

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://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));
        }