// GET: AdminUsers/Edit/5 /// <summary>Returns view for specified <see cref="ApplicationUser"/> editing.</summary> /// <param name="id"><see cref="ApplicationUser"/> id.</param> public async Task <IActionResult> Edit(string id) { if (id == null || id.Trim().Length == 0) { return(NotFound()); } var userFromDb = await _db.ApplicationUsers.FindAsync(id); if (userFromDb == null) { return(RedirectToAction(nameof(Index))); } AdminUsersViewModel adminUsersVM = new AdminUsersViewModel(); adminUsersVM.ApplicationUser = userFromDb; string userRoleId = _db.UserRoles.Where(u => u.UserId == id).Select(r => r.RoleId).FirstOrDefault(); string userRoleName = _db.Roles.Where(r => r.Id == userRoleId).Select(n => n.Name).FirstOrDefault(); adminUsersVM.ApplicationUserRole = userRoleName; return(View(adminUsersVM)); }
public async Task <IActionResult> AdminUsersAsync(int?pageNumber) { //EF core var CurrentUserId = _userManager.GetUserId(User as ClaimsPrincipal); ArtGalleryContext context = new ArtGalleryContext(); IQueryable <UserViewModel> UsersData = (IQueryable <UserViewModel>)(from U in context.Account where U.IsUser == true select new UserViewModel { UserName = U.UserName, IsActive = U.IsActive, }); AdminUsersViewModel AdminUsersVM = new AdminUsersViewModel(); AdminUsersVM.UserPaginatedList = await PaginatedList <UserViewModel> .CreateAsunc((IQueryable <UserViewModel>) UsersData, pageNumber ?? 1, 4); AdminUsersVM.FullName = context.Account.Where(A => A.Id == CurrentUserId).Select(A => A.FirstName).FirstOrDefault(); AdminUsersVM.ProfilePicture = context.ProfileImage.Where(PI => PI.AccountId == CurrentUserId).Select(PI => PI.ImageName).FirstOrDefault(); return(View(AdminUsersVM)); }
public async Task <IActionResult> Index(int pageNumber = 1) { var cookies = this.HttpContext.Request.Cookies; var sortStrategyType = this.cookiesService .GetValueOrDefault <UserSortStrategyType>(cookies, WebConstants.CookieAdminUsersSortTypeKey); var sortDirection = this.cookiesService .GetValueOrDefault <SortStrategyDirection>(cookies, WebConstants.CookieAdminUsersSortDirectionKey); var sortStrategy = UserSortStrategyFactory.GetStrategy(sortStrategyType, sortDirection); var allUsers = this.userRepository.GetAll(); var totalPagesCount = await PaginationHelper.CountTotalPagesCountAsync(allUsers); var userServiceModels = await this.adminUsersService.GetSortedUsersAsync(sortStrategy, pageNumber); var userViewModels = await userServiceModels.To <UserAdminViewModel>().ToArrayAsync(); var model = new AdminUsersViewModel() { CurrentPage = pageNumber, SortStrategyDirection = sortDirection, SortStrategyType = sortStrategyType, TotalPagesCount = totalPagesCount, Users = userViewModels }; return(View(model)); }
public async Task <IActionResult> Edit(AdminUsersViewModel adminUsersVM) { if (ModelState.IsValid) { ApplicationUser userFromDb = _db.ApplicationUsers.Where(u => u.Id == adminUsersVM.ApplicationUser.Id).FirstOrDefault(); userFromDb.Name = adminUsersVM.ApplicationUser.Name; userFromDb.PhoneNumber = adminUsersVM.ApplicationUser.PhoneNumber; string userRoleId = _db.UserRoles.Where(u => u.UserId == adminUsersVM.ApplicationUser.Id).Select(r => r.RoleId).FirstOrDefault(); string userRoleName = _db.Roles.Where(r => r.Id == userRoleId).Select(n => n.Name).FirstOrDefault(); if (userRoleName != null) { IdentityResult deletionResult = await _userManager.RemoveFromRoleAsync(userFromDb, userRoleName); } string newRole = adminUsersVM.ApplicationUserRole; await _userManager.AddToRoleAsync(userFromDb, newRole); _db.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(adminUsersVM)); }
public ActionResult Users() { var model = new AdminUsersViewModel(); GetUsersAndRoles(model); return(View(model)); }
public IActionResult BannedUsers() { var viewModel = new AdminUsersViewModel { Users = this.usersService.GetBannedUsers <AdminUserViewModel>(), }; return(this.View(viewModel)); }
private void GetUsersAndRoles(AdminUsersViewModel model) { model.Users = UserManager.Users .Include(u => u.Roles) .Include(u => u.Member) .OrderBy(u => u.Member.Name.First) .ToList(); model.Roles = RoleManager.Roles.ToList(); }
public ActionResult Users() { var users = DataContext.Users.ToList(); var vm = new AdminUsersViewModel { Users = users }; return(View(vm)); }
public async Task <ActionResult> Users(AdminUsersViewModel user) { string Url = Request.UrlReferrer.AbsolutePath; BLL.DTO.UserDTO edit = await UserService.GetUserById(user.Id); edit.Role = user.Role; await UserService.EditUser(edit); return(Redirect(Url)); }
public IActionResult Users(AdminUsersViewModel model) { if (!IsAdmin()) { return(BadRequest("Not authenticated")); } if (!model.DoAction(_ctx, out var msg)) { return(BadRequest(msg)); } return(Ok(msg)); }
public IActionResult Users() { if (!IsAdmin()) { var statusModel = new StatusViewModel { IsError = true, Message = "Not authenticated" }; return(RedirectToAction("Status", "Home", statusModel)); } var model = new AdminUsersViewModel(); model.GetUsers(_ctx); return(View(model)); }
public ActionResult AdminUsers(String CompanyURL, int?EmployeeId) { var Model = new AdminUsersViewModel(); PopulateModel(Model); if (!ModelState.IsValid) { return(View(Model)); } Model.Employees = Context.Employees.Where(t => t.CompanyId == Model.CompanyId).ToList(); Model.Roles = new List <SelectListItem>(); foreach (var Role in Context.Roles) { SelectListItem selectList = new SelectListItem() { Text = Role.RoleType, Value = Role.RoleId.ToString() }; Model.Roles.Add(selectList); } if (EmployeeId == null) { Model.SelectedEmployee = new Data.Employee(); Model.SelectedEmployee.RoleId = 0; Model.SelectedEmployee.IsActive = true; Model.SelectedEmployee.IsOvertimeCalculated = true; Model.SelectedEmployee.IsAdmin = false; } else { Model.SelectedEmployee = Context.Employees.Where(t => t.EmployeeId == EmployeeId).FirstOrDefault(); if (Model.SelectedEmployee.RoleId == null) { Model.SelectedEmployee.RoleId = 0; } } return(View(Model)); }
public ActionResult Index() { var model = new AdminUsersViewModel(); var users = userManager.Users .OrderBy(x => x.ShortName) .ToList(); foreach (var user in users) { var roles = userManager.GetRolesAsync(user); roles.Wait(); var viewUser = UserListViewModel.FromUser(user); viewUser.Roles = roles.Result.ToArray(); model.Users.Add(viewUser); } return(View(model)); }
public IActionResult Users() { List <User> users = new List <User>(); if (User.IsInRole("Admin")) { users = _userService.GetAll(); } else { users = _userService.GetUsersByRoleId(3); //Members } var model = new AdminUsersViewModel { Users = users }; return(View(model)); }
/// <summary> /// Index page for admin, lists all users for easy access and editability /// </summary> public ActionResult Users() { List <AdminCourseViewModel> allCourses = _courseService.GetAllCourseInstances(); List <SelectListItem> allCourseItems = new List <SelectListItem>(); foreach (var course in allCourses) { allCourseItems.Add(new SelectListItem { Text = course.Name + " - " + course.Year + " - " + course.Semester, Value = course.Id.ToString() }); } AdminUsersViewModel model = new AdminUsersViewModel(); model.Users = _userService.GetAllUsers(); model.AvailableCourses = allCourseItems; ViewBag.UserName = User.Identity.Name; return(View(model)); }
public ActionResult AdminUsers(String CompanyURL, AdminUsersViewModel Model) { PopulateModel(Model); if (!ModelState.IsValid) { return(View(Model)); } if (!ModelState.IsValid) { Model.Employees = Context.Employees.Where(t => t.CompanyId == Model.CompanyId).ToList(); return(View(Model)); } var Employee = new Data.Employee(); Employee.EmployeeId = Model.SelectedEmployee.EmployeeId; Employee.CompanyId = Model.CompanyId; Employee.FirstName = Model.SelectedEmployee.FirstName; Employee.LastName = Model.SelectedEmployee.LastName; Employee.EmailAddress = Model.SelectedEmployee.EmailAddress; Employee.Phonenumber = Model.SelectedEmployee.Phonenumber; Employee.SSN = Model.SelectedEmployee.SSN; Employee.UserName = Model.SelectedEmployee.UserName; Employee.Password = Model.SelectedEmployee.Password; Employee.EmployeeNumber = Model.SelectedEmployee.EmployeeNumber; Employee.RoleId = Model.SelectedEmployee.RoleId; Employee.IsOvertimeCalculated = Model.SelectedEmployee.IsOvertimeCalculated; Employee.IsActive = Model.SelectedEmployee.IsActive; Employee.UpdatedById = Model.LoginId; Employee.UpdatedOn = DateTime.UtcNow; Context.Entry(Employee).State = Model.SelectedEmployee.EmployeeId == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified; Context.SaveChanges(); return(RedirectPermanent("/" + CompanyURL + "/adminusers")); }
public async Task <IActionResult> CreatePOST(AdminUsersViewModel adminUsersVM) { ApplicationUser userCheck = _db.ApplicationUsers.Where(u => u.Email == adminUsersVM.ApplicationUser.Email).FirstOrDefault(); if (userCheck != null) { ModelState.AddModelError("", "This user already exists!"); } if (!ModelState.IsValid) { return(View(adminUsersVM)); } var user = new ApplicationUser { UserName = adminUsersVM.ApplicationUser.Email, Email = adminUsersVM.ApplicationUser.Email, Name = adminUsersVM.ApplicationUser.Name, PhoneNumber = adminUsersVM.ApplicationUser.PhoneNumber, EmailConfirmed = true }; var result = await _userManager.CreateAsync(user, "Pass123*"); if (result.Succeeded) { string roleName = adminUsersVM.ApplicationUserRole; await _userManager.AddToRoleAsync(user, roleName); } _db.ApplicationUsers.Add(user); return(RedirectToAction(nameof(Index))); }
public IActionResult Users(int page = 1) { if (page < 1) { page = 1; } int countPerPage = 25; var model = new AdminUsersViewModel(); int lastPage = _userManager.Users.Count() / countPerPage; model.Users = _userManager.Users .Skip((page - 1) * countPerPage) .Take(countPerPage) .ToList(); model.CurrentPage = page; model.LastPage = lastPage; return(View(model)); }
public async Task <ActionResult> Users(AdminUsersViewModel model, string[] SelectedRoles, string Command) { GetUsersAndRoles(model); if (Command == "Save") { foreach (var role in model.Roles) { if (SelectedRoles != null && SelectedRoles.Contains(role.Name)) { if (!UserManager.IsInRole(model.SelectedUserId, role.Name)) { UserManager.AddToRole(model.SelectedUserId, role.Name); } } else if (UserManager.IsInRole(model.SelectedUserId, role.Name)) { UserManager.RemoveFromRole(model.SelectedUserId, role.Name); if (role.Name == AdminConstants.Roles.CommitteeChair) { var user = model.Users.First(u => u.Id == model.SelectedUserId); CommitteeRepository.RemoveMemberFromCommittes(user.Member); CommitteeRepository.Save(); } } } } if (ModelState.IsValid) { return(View(model)); } else { return(View(model)); } }
public IActionResult Users(int id) { var users = this.userService.GetAll <UserDetailsViewModel>(); var bannedPlayersCount = this.userService.GetAll <BannedUsersViewModel>(x => x.IsBanned) .Count(); var inactiveUsersCount = this.userService.GetInactiveUsers <UserDetailsViewModel>(InactivityDays) .Count(); var newUsersCount = this.userService.GetAll <UserDetailsViewModel>() .Count(x => (DateTime.UtcNow - x.CreatedOn).TotalDays <= NewbiePeriodInDays); id = Math.Max(1, id); var skip = (id - 1) * AdminUsersViewModel.ItemsPerPage; var filteredItems = users.Skip(skip). Take(AdminUsersViewModel.ItemsPerPage) .ToList(); var usersCount = users.Count(); var pagesCount = (int)Math.Ceiling(usersCount / (decimal)AdminUsersViewModel.ItemsPerPage); var model = new AdminUsersViewModel { Items = filteredItems, InactiveUsersCount = inactiveUsersCount, BannedUsersCount = bannedPlayersCount, NewUsersCount = newUsersCount, CurrentPage = id, PagesCount = pagesCount, ItemsCount = usersCount }; return(this.View(model)); }
public LoadUserForEditionCommand(AdminUsersViewModel vm) { VM = vm; }
public IActionResult Index() { AdminUsersViewModel model = _userWebService.GetAllUsers(); return(View($"{UsersViewFolder}/Index.cshtml", model)); }
public CancelAndClearUserActionCommand(AdminUsersViewModel vm) { VM = vm; }
public AddSelectedUserGroupCommand(AdminUsersViewModel vm) { VM = vm; }
public RemoveUserCommand(AdminUsersViewModel vm) { VM = vm; }
public CreateNewOrEditExistingUserCommand(AdminUsersViewModel vm) { VM = vm; }