public ActionResult Install(UserViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
                return View(model);

            try
            {
                User user = new User
                {
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Username = model.Username,
                    Password = PasswordHash.CreateHash(model.Password),
                    Email = model.Email,
                    Phone = model.Phone,
                    Address = model.Address,
                    AccessLevel = 10,
                    IsAdmin = true,
                    IsMultiUser = false,
                    IsSubUser = false,
                    OwnerID = -1,
                };

                dbContext.Instance.Users.InsertOnSubmit(user);
                dbContext.Instance.SubmitChanges();

                return View("LogIn");
            }
            catch (Exception ex)
            {
                return View(model);
            }
        }
        public ActionResult DeleteUser(User user)
        {
            dbContext.Instance.Users.DeleteAllOnSubmit(dbContext.Instance.Users.Where(x => x.OwnerID == user.UserID));
            dbContext.Instance.Users.DeleteAllOnSubmit(dbContext.Instance.Users.Where(x => x.UserID == user.UserID));
            dbContext.Instance.SubmitChanges();

            return View("UserList", GetUserViewModel());
        }
        public UserViewModel(User user)
        {
            Username = user.Username;
            FirstName = user.FirstName;
            LastName = user.LastName;

            Email = user.Email;
            Address = user.Address;
            Phone = user.Phone;

            AccessLevel = user.AccessLevel;

            IsAdmin = user.IsAdmin;
            IsMultiUser = user.IsMultiUser;
            IsSubUser = user.IsSubUser;

            UserID = user.UserID;
            OwnerID = user.OwnerID;
        }
        public ActionResult EditUser(UserViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
                return View(model);

            User user;
            if (model.UserID > 0)
            {
                user = dbContext.Instance.Users.FirstOrDefault(x => x.UserID == model.UserID);
            }
            else
            {
                user = new User
                {
                    IsAdmin = false,
                    IsMultiUser = false,
                    IsSubUser = true
                };
            }

            if (user == null)
                return View("UserList");

            user.FirstName = model.FirstName;
            user.LastName = model.LastName;
            user.Username = model.Username;
            user.Password = PasswordHash.CreateHash(model.Password);
            user.Email = model.Email;
            user.Phone = model.Phone;
            user.Address = model.Address;

            if (SessionManager.Instance.UserRights == UserRights.Admin || (SessionManager.Instance.UserRights == UserRights.MultiUser && model.IsSubUser))
                user.AccessLevel = model.AccessLevel;

            if (SessionManager.Instance.UserRights == UserRights.Admin)
            {
                user.IsAdmin = model.IsAdmin;
                user.IsMultiUser = model.IsMultiUser;
                user.IsSubUser = model.IsSubUser;
            }

            if (user.UserID == 0)
            {
                user.OwnerID = model.OwnerID;
                dbContext.Instance.Users.InsertOnSubmit(user);
            }

            dbContext.Instance.SubmitChanges();

            return View("UserList", GetUserViewModel());

            /*
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result =  SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    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);
            }
            */
        }
 partial void DeleteUser(User instance);
 partial void UpdateUser(User instance);
 partial void InsertUser(User instance);