public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                ////var user = new ApplicationUser() { UserName = model.UserName };

                var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    //var db = new ApplicationDbContext();
                    ////Note 123456 seed number should be avoided or stored in config file. If I delete any account then I might end up duplicating the account number.
                    //var accountNumber = (123456 + db.Persons.Count()).ToString().PadLeft(10, '0');
                    //var person = new Person 
                    //{
                    //    AccountNumber = accountNumber,
                    //    //AccountNumber = "0000123456",
                    //    FirstName = model.FirstName, 
                    //    LastName = model.LastName,
                    //    MobileNo = "0422333444",
                    //    JoinDate = "12/11/2012",
                    //    IsActive = true,
                    //    ApplicationUserId = user.Id
                    //};
                    //db.Persons.Add(person);
                    //db.SaveChanges();

                    var service = new PersonService(HttpContext.GetOwinContext().Get<ApplicationDbContext>());
                    service.CreatePerson(model.FirstName, model.LastName, user.Id, "0422333444", "12/11/2012", true);

                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    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("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.UserName };
                
                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)
                    {
                        var service = new PersonService(HttpContext.GetOwinContext().Get<ApplicationDbContext>());
                        service.CreatePerson("Facebook", "User", user.Id, "0422333444", "12/11/2012", true);

                        await SignInAsync(user, isPersistent: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }