コード例 #1
0
        public ActionResult EditUser(Guid userId)
        {
            UserListingViewModel viewModel = new UserListingViewModel();

            if (userId == Guid.Empty)
            {
            }
            else
            {
                User us = db.Users.ToList().Where(x => x.UserId == userId).FirstOrDefault();

                viewModel = new UserListingViewModel()
                {
                    UserId    = us.UserId,
                    LoginId   = us.LoginId,
                    FirstName = us.FirstName,
                    LastName  = us.LastName,
                    Mobile    = us.Mobile,
                    Email     = us.Email,
                    Password  = us.Password
                };
            }

            ViewData.Model = viewModel;

            if (Request.IsAjaxRequest())
            {
                return(PartialView());
            }
            else
            {
                return(View());
            }
        }
コード例 #2
0
ファイル: AdminController.cs プロジェクト: marysiami/OMDLE
        public JsonResult GetTeachers([FromQuery] int page, [FromQuery] int threadsPerPage = 10)
        {
            var model = _userService.GetTeachers(page, threadsPerPage);

            var result = new UserListingViewModel(model);

            return(Json(result));
        }
コード例 #3
0
        // GET: User1
        public ActionResult Index()
        {
            UserService          userService = new UserService();
            UserListingViewModel model       = new UserListingViewModel();

            model.dealDoubleUsers = userService.UsersWithRoles();
            return(View(model));
        }
コード例 #4
0
        public ActionResult User1()
        {
            UserService          userService = new UserService();
            UserListingViewModel model       = new UserListingViewModel();

            model.Roles = RoleManager.Roles.ToList();
            //model.dealDoubleUsers = userService.UsersWithRoles();
            model.dealDoubleUsers = UserManager.Users.ToList();
            return(View(model));
        }
コード例 #5
0
        public JsonResult UserCreateUpdate(UserListingViewModel viewModel)
        {
            bool            isSuccess   = false;
            AjaxReturnModel returnModel = new AjaxReturnModel();

            User user = new User();

            if (viewModel.UserId == Guid.Empty)
            {
                user = new User()
                {
                    UserId    = Guid.NewGuid(),
                    LoginId   = viewModel.LoginId,
                    FirstName = viewModel.FirstName,
                    LastName  = viewModel.LastName,
                    Mobile    = viewModel.Mobile,
                    Email     = viewModel.Email,
                    Password  = viewModel.Password
                };

                db.Users.Add(user);
                db.SaveChanges();
            }
            else
            {
                user = db.Users.ToList().Where(x => x.UserId == viewModel.UserId).FirstOrDefault();

                user.FirstName = viewModel.FirstName;
                user.LastName  = viewModel.LastName;
                user.Mobile    = viewModel.Mobile;
                user.Email     = viewModel.Email;
                user.Password  = viewModel.Password;

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
            }

            returnModel.recordId = user.UserId;
            isSuccess            = true;

            if (isSuccess)
            {
                returnModel.ReturnStatus = Enum.ReturnStatus.success;
            }
            else
            {
                returnModel.ReturnStatus = Enum.ReturnStatus.error;
                returnModel.ErrorMessages.Add("Failed for some reason");
            }

            return(Json(returnModel, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        public async Task <IActionResult> Index()
        {
            var model = new UserListingViewModel
            {
                Users = await this.users.AllAsync(),
                Roles = await this.roleManager
                        .Roles
                        .Select(r => new SelectListItem
                {
                    Text  = r.Name,
                    Value = r.Name
                })
                        .ToListAsync()
            };

            return(View(model));
        }
コード例 #7
0
        public async Task <IActionResult> Index()
        {
            var users = await this.adminUsersService.AllAsync();

            var roles = await this.roleManager
                        .Roles
                        .Select(r => new SelectListItem
            {
                Text  = r.Name,
                Value = r.Name
            })
                        .ToListAsync();

            var resultModel = new UserListingViewModel {
                Users = users, Roles = roles
            };

            return(View(resultModel));
        }
コード例 #8
0
        public async Task <ActionResult> Index(string searchTerm, string roleID, int?page)
        {
            int pageSize = 1;                                              //TODO: Set page size in Configuration

            page = page ?? 1;                                              // The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand

            int totalRecords = await SearchUsersCount(searchTerm, roleID); // get users count based on the params

            UserListingViewModel model = new UserListingViewModel
            {
                Users        = await SearchUsers(searchTerm, roleID, pageSize, page.Value), // get users  based on the params
                Roles        = RolesManager.Roles,                                          // show all roles
                RoleID       = roleID,
                Pager        = new Pager(totalRecords, page, pageSize),
                TotalRecords = totalRecords,
                SearchTerm   = searchTerm
            };


            return(View(model));
        }
コード例 #9
0
        public async Task <IActionResult> Index(string searchTerm, int page = 1)
        {
            page = Math.Max(1, page);
            var allUsers = this.userService.GetAll();

            if (!string.IsNullOrWhiteSpace(searchTerm))
            {
                allUsers = allUsers.Where(u => u.Email.ToLower().Contains(searchTerm.ToLower()));
            }

            var totalPages = (int)(Math.Ceiling(allUsers.Count() / (double)UsersListPageSize));

            page = Math.Min(page, Math.Max(1, totalPages));

            var usersToShow = allUsers
                              .Skip((page - 1) * UsersListPageSize)
                              .Take(UsersListPageSize)
                              .ToList();

            var allRoles = this.roleManager.Roles.Select(r => r.Name).ToList();

            foreach (var userModel in usersToShow)
            {
                var dbUser = await this.userManager.FindByEmailAsync(userModel.Email);

                var userRoles = await this.userManager.GetRolesAsync(dbUser);

                userModel.CurrentRoles    = userRoles;
                userModel.NonCurrentRoles = allRoles.Except(userRoles).ToList();
            }

            var model = new UserListingViewModel
            {
                SearchTerm = searchTerm,
                Users      = new PaginatedList <UserListingServiceModel>(usersToShow, page, totalPages),
            };

            return(View(model));
        }
コード例 #10
0
        public async Task <IActionResult> Index()
        {
            var users = await _adminUserService.AllAsync();

            var roles = await _roleManager
                        .Roles
                        .OrderBy(r => r.Name)
                        .Select(r => new SelectListItem
            {
                Text  = r.Name,
                Value = r.Name     // roleName => RoleExistsAsync
            })
                        .ToListAsync();

            var model = new UserListingViewModel
            {
                Users = users.OrderBy(u => u.Name).ThenBy(u => u.Username),
                Roles = roles
            };

            return(View(model));
        }
コード例 #11
0
        public async Task <IActionResult> Index(string searchTerm, string roleID, int?page)
        {
            int recordSize = 5;

            page = page ?? 1;
            //var abc = _signInManager.AuthenticationManager;
            UserListingViewModel model = new UserListingViewModel();

            model.SearchTerm = searchTerm;

            model.RoleID = roleID;
            //model.Roles = accomodationPackagesService.GetAllAccomodationPackages();

            model.Users = _userRepository.SearchUsers(searchTerm, page.Value, recordSize);



            var totalRecords = _userRepository.SearchUsersCount(searchTerm);

            //thuộc tính phân trang
            model.Pager = new Pager(totalRecords, page, recordSize);

            return(View(model));
        }