Exemplo n.º 1
0
        //
        // GET: /User/List
        public ActionResult List()
        {
            if (!Request.IsAuthenticated || (string)(@Session["role"]) != "Admin")
            {
                return RedirectToAction("Error", "Home", new { msg = "You are not allowed to view this page..." });
            }

            System.Linq.IQueryable<user> list = userRepository.FindAllUsers();
            UserViewModel[] users = new UserViewModel[list.Count()];
            int i = 0;
            foreach (user u in list)
            {
                users[i] = new UserViewModel(u);
                i++;
            }

            UserListViewModel ulVM = new UserListViewModel();
            ulVM.users = users;

            return View(ulVM);
        }
Exemplo n.º 2
0
        public ActionResult Register(UserViewModel model)
        {
            if (ModelState.IsValid)
            {

                try
                {
                    model.ApplyChanges();

                    //if no exception was thrown, check if the user creation was successfuland redirect
                    user new_user = userRepository.GetByUsername(model.username);
                    if (new_user != null)
                    {
                        return RedirectToAction("FakeUnlockMail", "User", new { id = new_user.id });
                    }
                }
                catch (Exception)
                {
                    return RedirectToAction("Error", "Home", new { msg = "Exception adding user..." });
                }
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 3
0
        //
        // GET: /Account/FakeUnlockMail
        public ActionResult UnlockUser(int id)
        {
            user user = userRepository.Get(id);

            //handle error
            if (user == null)
            {
                return RedirectToAction("Error", "Home", new { msg = "User object was null..." });
            }

            UserViewModel model = new UserViewModel(user);
            //activate account
            try
            {
                model.is_active = true;
                model.ApplyChanges();
                userRepository.Save();
            }
            catch (Exception e)
            {
                return RedirectToAction("Error", "Home", new { msg = "Exception caught while saving data: " + e.Message });
            }

            ViewBag.user = model;

            return View();
        }
Exemplo n.º 4
0
        public ActionResult List(UserListViewModel ulVM)
        {
            if (!Request.IsAuthenticated || @Session["role"] != "Admin")
            {
                return RedirectToAction("Error", "Home", new { msg = "You are not allowed to view this page..." });
            }

            Debug.WriteLine("SEARCHT IS " + ulVM.UserName);
            System.Linq.IQueryable<user> list = userRepository.FindAllUsersWithWord(ulVM.UserName);
            UserViewModel[] users = new UserViewModel[list.Count()];
            int i = 0;
            foreach (user u in list)
            {
                users[i] = new UserViewModel(u);
                i++;
            }

            ulVM.users = users;

            return View(ulVM);
        }