Example #1
0
        /// <summary>
        /// Load data to form
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult AjaxHandler(JQueryDataTableParamModel param)
        {
            var users = _accountService.GetAllUsers();
            IEnumerable <ApplicationUser> filteredUsers;

            //Check whether the Categories should be filtered by keyword
            if (!string.IsNullOrEmpty(param.sSearch))
            {
                //Used if particulare columns are filtered
                //var nameFilter = Convert.ToString(Request["sSearch_1"]);
                //var addressFilter = Convert.ToString(Request["sSearch_2"]);
                //var townFilter = Convert.ToString(Request["sSearch_3"]);

                //Optionally check whether the columns are searchable at all
                //var isNameSearchable = Convert.ToBoolean(Request["bSearchable_1"]);
                //var isAddressSearchable = Convert.ToBoolean(Request["bSearchable_2"]);
                //var isTownSearchable = Convert.ToBoolean(Request["bSearchable_3"]);

                filteredUsers = _accountService.GetAllUsers().Where(aa => aa.UserName.ToLower().Contains(param.sSearch.ToLower()));
                //   .Where(c => isNameSearchable && c.CategoriesName.ToLower().Contains(param.sSearch.ToLower()));
            }
            else
            {
                filteredUsers = users;
            }

            var isUsernameSort = Convert.ToBoolean(Request["bSortable_1"]);
            //var isAddressSortable = Convert.ToBoolean(Request["bSortable_2"]);
            //var isTownSortable = Convert.ToBoolean(Request["bSortable_3"]);
            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
            Func <ApplicationUser, string> orderingFunction = (c => c.UserName);

            var sortDirection = Request["sSortDir_0"]; // asc or desc

            if (sortDirection == "asc")
            {
                filteredUsers = filteredUsers.OrderBy(orderingFunction);
            }
            else
            {
                filteredUsers = filteredUsers.OrderByDescending(orderingFunction);
            }

            var displayedUsers = filteredUsers.Skip(param.iDisplayStart).Take(param.iDisplayLength);
            var result         = from c in displayedUsers select new[] { c.Id, c.UserName, c.Email, c.PhoneNumber };

            return(Json(new
            {
                sEcho = param.sEcho,
                iTotalRecords = users.Count(),
                iTotalDisplayRecords = filteredUsers.Count(),
                aaData = result
            },
                        JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public IActionResult GetAllUsers(int page = 1)
        {
            if (ModelState.IsValid)
            {
                return(Ok(_accountServices.GetAllUsers(page)));
            }

            return(NotFound());
        }
Example #3
0
        public ActionResult Add()
        {
            var ListUser = AccountService.GetAllUsers();
            var ListRole = AccountService.GetAllRoles();

            ViewBag.ListUser = ListUser;
            ViewBag.ListRole = ListRole;
            return(View());
        }
 public IEnumerable <UserShortViewModel> GetAllUsers()
 {
     return(_main.GetAllUsers().Select(i => new UserShortViewModel(i)));
 }