public ActionResult Index(Models.Login model)
        {
            if(ModelState.IsValid)
            {

                var UserManager = new Identity.AppUserManagerContainer().Get();

                var User = UserManager.FindByName(model.Username);
                if (User != null)
                {

                    if (!User.AccountEnabled)
                        ViewBag.ErrorMessage = "This account has been disabled.";
                    else
                    {
                        if (UserManager.IsLockedOut(User.Id))
                            ViewBag.ErrorMessage = "Account has been temporarily locked out.";
                        else
                        {

                            var validUser = UserManager.Find(model.Username, model.Password);
                            if (validUser != null)
                            {

                                //log the user in
                                var ident = new ClaimsIdentity(new[] {
                                    new Claim(ClaimTypes.Name, string.Concat(User.FirstName, " ", User.LastName)),
                                    new Claim(ClaimTypes.Email, User.Email)
                                }, "ApplicationCookie");
                                var ctx = Request.GetOwinContext();
                                var authManager = ctx.Authentication;
                                authManager.SignIn(ident);
                                authManager.SignIn(new AuthenticationProperties { IsPersistent = model.RememberMe }, ident);

                                //redirect to login
                                return RedirectToAction("", "Home");
                            }
                            else
                            {
                                //login failed
                                UserManager.AccessFailed(User.Id);
                                if (UserManager.IsLockedOut(User.Id))
                                    ViewBag.ErrorMessage = "Your account has now been temporarily locked out due to too many failed login attempts.";
                                else
                                    ViewBag.ErrorMessage = "Login failed.";

                            }
                        }
                    }
                }
                else//could not find user
                {
                    ViewBag.ErrorMessage = "Login failed.";
                }

            }
            return View(model);
        }
        public ActionResult index(Models.Register model)
        {
            if (ModelState.IsValid)
            {
                var UserManager = new Identity.AppUserManagerContainer().Get();

                //see if user already exists
                var existingUser = UserManager.FindByName(model.Username);
                if (existingUser != null)
                {
                    ViewBag.ErrorMessage = "A user with the given username already exists.";
                }
                else
                {
                    //create the user
                    var User = new Identity.AppUser()
                    {
                        UserName       = model.Username,
                        FirstName      = model.FirstName,
                        LastName       = model.LastName,
                        Email          = model.EmailAddress,
                        AccountEnabled = true
                    };

                    var result = UserManager.Create(User, model.Password);
                    if (result.Succeeded)
                    {
                        return(Redirect("Login"));
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "Failed to create an account an error occured.";
                    }
                }
            }
            return(View(model));
        }
        public ActionResult index(Models.Register model)
        {
            if(ModelState.IsValid)
            {
                var UserManager = new Identity.AppUserManagerContainer().Get();

                //see if user already exists
                var existingUser = UserManager.FindByName(model.Username);
                if (existingUser != null)
                {
                    ViewBag.ErrorMessage = "A user with the given username already exists.";
                }
                else
                {
                    //create the user
                    var User = new Identity.AppUser()
                    {
                        UserName = model.Username,
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        Email = model.EmailAddress,
                        AccountEnabled = true
                    };

                    var result = UserManager.Create(User, model.Password);
                    if (result.Succeeded)
                    {
                        return Redirect("Login");
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "Failed to create an account an error occured.";
                    }
                }
            }
            return View(model);
        }
        public ActionResult Index(Models.Login model)
        {
            if (ModelState.IsValid)
            {
                var UserManager = new Identity.AppUserManagerContainer().Get();

                var User = UserManager.FindByName(model.Username);
                if (User != null)
                {
                    if (!User.AccountEnabled)
                    {
                        ViewBag.ErrorMessage = "This account has been disabled.";
                    }
                    else
                    {
                        if (UserManager.IsLockedOut(User.Id))
                        {
                            ViewBag.ErrorMessage = "Account has been temporarily locked out.";
                        }
                        else
                        {
                            var validUser = UserManager.Find(model.Username, model.Password);
                            if (validUser != null)
                            {
                                //log the user in
                                var ident = new ClaimsIdentity(new[] {
                                    new Claim(ClaimTypes.Name, string.Concat(User.FirstName, " ", User.LastName)),
                                    new Claim(ClaimTypes.Email, User.Email)
                                }, "ApplicationCookie");
                                var ctx         = Request.GetOwinContext();
                                var authManager = ctx.Authentication;
                                authManager.SignIn(ident);
                                authManager.SignIn(new AuthenticationProperties {
                                    IsPersistent = model.RememberMe
                                }, ident);

                                //redirect to login
                                return(RedirectToAction("", "Home"));
                            }
                            else
                            {
                                //login failed
                                UserManager.AccessFailed(User.Id);
                                if (UserManager.IsLockedOut(User.Id))
                                {
                                    ViewBag.ErrorMessage = "Your account has now been temporarily locked out due to too many failed login attempts.";
                                }
                                else
                                {
                                    ViewBag.ErrorMessage = "Login failed.";
                                }
                            }
                        }
                    }
                }
                else//could not find user
                {
                    ViewBag.ErrorMessage = "Login failed.";
                }
            }
            return(View(model));
        }