public ActionResult Login(UserEntity userModel, string returnUrl)
        {
            PasswordHasher hasher = new PasswordHasher();

            if (ModelState.IsValid)
            {
                //User user = unitOfWork.UserRepository.Get(u => u.Username == userModel.Username).SingleOrDefault();
                UserEntity userEntity = _userService.GetSingleUserByUsername(userModel.Username);

                if (userEntity != null)
                {
                    //PasswordVerificationResult result = hasher.VerifyHashedPassword(user.Password, userModel.Password);
                    PasswordVerificationResult result = hasher.VerifyHashedPassword(userEntity.Password, userModel.Password);
                    if (result != PasswordVerificationResult.Failed)
                    {
                        //FormsAuthentication.SetAuthCookie(user.Username, false);
                        FormsAuthentication.SetAuthCookie(userEntity.Username, false);

                        if (Url.IsLocalUrl(returnUrl))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            return RedirectToAction("Index", "Home", new { area = "" });
                        }

                    }
                    else
                    {
                        //failed password
                        ModelState.AddModelError("Password", "The password provided was incorrect");
                    }
                }
                else
                {
                    //none valid username
                    ModelState.AddModelError("Username", "The username provided was incorrect");
                }

            }

            return View("Login", userModel);
        }
        public int CreateUser(UserEntity userEntity)
        {
            using (var scope = new TransactionScope())
            {
                User user = new User();
                //
                user.Username = userEntity.Username;
                user.Password = userEntity.Password;
                // What about userID?

                _unitOfWork.UserRepository.Insert(user);
                _unitOfWork.Save();
                scope.Complete();

                return user.UserId;
            }
        }
        public ActionResult Create([Bind(Include ="Username,Password,RepeatPassword")]NewUserViewModel newUserModel)
        {
            if (ModelState.IsValid)
            {
                if (newUserModel.Password.Equals(newUserModel.RepeatPassword))
                {

                    //List<User> users = unitOfWork.UserRepository.Get(u => u.Username == newUserModel.Username).ToList();
                    //bool userNameTaken = (users.Count > 0) ? true : false;

                    if (_userService.UserExists(newUserModel.Username))
                    {
                        ModelState.AddModelError("Username", "Username already being used");
                        return View(newUserModel);
                    }
                    else
                    {
                        //User user = new User();
                        //user.Username = newUserModel.Username;
                        //PasswordHasher hasher = new PasswordHasher();
                        //user.Password = hasher.HashPassword(newUserModel.Password);

                        //unitOfWork.UserRepository.Insert(user);
                        //unitOfWork.Save();

                        UserEntity userEntity = new UserEntity();
                        userEntity.Username = newUserModel.Username;
                        PasswordHasher hasher = new PasswordHasher();
                        userEntity.Password = hasher.HashPassword(newUserModel.Password);

                        _userService.CreateUser(userEntity);
                    }
                }
                else
                {
                    ModelState.AddModelError("Password", "Passwords do not match");
                    ModelState.AddModelError("RepeatPassword", "Passwords do not match");
                    return View(newUserModel);
                }

                return RedirectToAction("Index");
            }

            return View(newUserModel);
        }
        public bool UpdateUser(int userId, UserEntity userEntity)
        {
            var success = false;
            if (userEntity != null)
            {
                using (var scope = new TransactionScope())
                {
                    User user = _unitOfWork.UserRepository.GetByID(userId);
                    if (user != null)
                    {
                        //
                        user.UserId = userEntity.UserId;
                        user.Username = userEntity.Username;
                        user.Password = userEntity.Password;
                        //

                        _unitOfWork.UserRepository.Update(user);
                        _unitOfWork.Save();
                        scope.Complete();
                        success = true;
                    }
                }
            }
            return success;
        }