Ejemplo n.º 1
0
        // GET: /Account/DetailtUser
        public ActionResult DetailUser(string id)
        {
            var model = new UserDetailsModel
            {
                Id = id,
                User = UserManager.FindById(id),
                Roles = UserManager.GetRoles(id)

            };
            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult DeleteUser(string id = null)
        {
            var model = new UserDetailsModel
            {
                Id = id,
                User = UserManager.FindById(id),
                Roles = UserManager.GetRoles(id)

            };
            if (model.User == null)
            {
                return HttpNotFound();
            }
            return View(model);
        }
Ejemplo n.º 3
0
        //
        // GET: /Account/ListUsers
        public ActionResult ListUsers(string sortBy, string currentFilter, string searchBy, int? page)
        {
            ViewBag.FirstNameSort = string.IsNullOrEmpty(sortBy) ? "FirstName desc" : "";
            ViewBag.LastNameSort = sortBy == "LastName" ? "LastName desc" : "LastName";
            ViewBag.CitySort = sortBy == "City" ? "City desc" : "City";
            ViewBag.StateSort = sortBy == "State" ? "State desc" : "State";
            ViewBag.UserNameSort = sortBy == "UserName" ? "UserName desc" : "UserName";
            ViewBag.GenderSort = sortBy == "Gender" ? "Gender desc" : "Gender";

            if (searchBy != null)
            {
                page = 1;
            }
            else
            {
                searchBy = currentFilter;
            }

            ViewBag.CurrentFilter = searchBy;

            var users = from s in UserManager.Users
                           select s;

            if (!String.IsNullOrEmpty(searchBy))
            {
                users = users.Where(s => s.FirstName.Contains(searchBy)
                                       || s.LastName.Contains(searchBy)
                                       || s.City.Contains(searchBy)
                                       || s.State.Contains(searchBy)
                                       || s.UserName.Contains(searchBy)
                                       || s.Gender.ToString().Contains(searchBy));
            }

            switch (sortBy)
            {
                case "FirstName desc":
                    users = users.OrderByDescending(s => s.FirstName);
                    break;
                case "FirstName":
                    users = users.OrderBy(s => s.FirstName);
                    break;
                case "LastName desc":
                    users = users.OrderByDescending(s => s.LastName);
                    break;
                case "LastName":
                    users = users.OrderBy(s => s.LastName);
                    break;
                case "City desc":
                    users = users.OrderByDescending(s => s.City);
                    break;
                case "City":
                    users = users.OrderBy(s => s.City);
                    break;
                case "State":
                    users = users.OrderBy(s => s.State);
                    break;
                case "State desc":
                    users = users.OrderByDescending(s => s.State);
                    break;
                case "UserName":
                    users = users.OrderBy(s => s.UserName);
                    break;
                case "UserName desc":
                    users = users.OrderByDescending(s => s.UserName);
                    break;
                case "Gender":
                    users = users.OrderBy(s => s.Gender);
                    break;
                case "Gender desc":
                    users = users.OrderByDescending(s => s.Gender);
                    break;
                default:
                    users = users.OrderBy(s => s.FirstName);
                    break;
            }

            int pageSize = 10;
            int pageNumber = (page ?? 1);

            List<UserDetailsModel> modelList = new List<UserDetailsModel>();
            foreach (var user in users.ToList())
            {
                UserDetailsModel model = new UserDetailsModel();
                model.User = user;
                model.Roles = UserManager.GetRoles(user.Id);
                modelList.Add(model);
            }
            return View(modelList.ToPagedList(pageNumber, pageSize));
            //return View(users.ToPagedList(pageNumber, pageSize));
           // return View(users.ToList());
        }