private void GetCurrentUserInfo()
 {
     if (User != null)
         {
             AccountRepository accountRepository = new AccountRepository();
             _user.Username = User.Identity.Name;
             _user.AccountID = accountRepository.GetAccountIDByUserName(_user.Username);
             _user.IsModerator = User.IsInRole("Moderator");
         }
 }
 // **************************************
 // URL: /Account/Activate/username/key
 // **************************************
 public ActionResult Activate(string username, string key)
 {
     AccountRepository _db = new AccountRepository();
     if (_db.ActivateUser(username, key) == false)
     {
         return RedirectToAction("Edit", "UserProfile", new { id = _db.GetAccountIDByUserName(username) });
     }
     else
     {
         return RedirectToAction("LogOn");
     }
 }
        public ActionResult Accounts(string currentFilter, string searchString)
        {
            AccountRepository _accountRepository = new AccountRepository();

            if (Request.HttpMethod == "GET")
            {
                searchString = currentFilter;
            }

            ViewData["CurrentFilter"] = searchString;

            return View(_accountRepository.GetAllAccounts(searchString));
        }
 public ViewResult Edit(int id)
 {
     AccountRepository _accountRepository = new AccountRepository();
     return View(_accountRepository.GetAccountByID(id));
 }
 public ActionResult DeleteAccountConfirmed(int id)
 {
     AccountRepository _accountrepository = new AccountRepository();
     _accountrepository.RemoveAccountByID(id);
     return RedirectToAction("Accounts");
 }
 public ActionResult Edit(Account account)
 {
     if (ModelState.IsValid)
     {
         AccountRepository _accountRepository = new AccountRepository();
         _accountRepository.SaveAccount(account);
     }
     return RedirectToAction("Accounts");
 }
        public MembershipCreateStatus CreateUser(string userName, string password, string email, string firstName, string lastName, bool isApproved)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");
            if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", "email");
            if (String.IsNullOrEmpty(firstName)) throw new ArgumentException("Value cannot be null or empty.", "firstName");
            if (String.IsNullOrEmpty(lastName)) throw new ArgumentException("Value cannot be null or empty.", "lastName");

            MembershipCreateStatus status;
            _provider.CreateUser(userName, password, email, null, null, isApproved, null, out status);

            if (status == MembershipCreateStatus.Success)
            {
                AccountRepository accountRepository = new AccountRepository();
                accountRepository.RegisterUserProfile(userName, firstName, lastName);
            }

            return status;
        }
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        //route moderator to moderatorpage
                        AccountRepository _db = new AccountRepository();

                        if (Roles.IsUserInRole(model.UserName,"Moderator"))
                        {

                            return RedirectToAction("Accounts", "Moderator");
                        }
                        else
                        {
                            return RedirectToAction("Index", "UserProfile", new { id = _db.GetAccountIDByUserName(model.UserName) });
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }