public IActionResult Index() { IndexUserViewModel model = new IndexUserViewModel { Users = userManager.Users.ToList() }; model.Roles = new List <string>(); model.AmountOfRoles = new List <int>(); foreach (var item in roleManager.Roles.ToList()) { model.Roles.Add(item.Name); model.AmountOfRoles.Add(0); } foreach (var user in model.Users) { for (int i = 0; i < model.Roles.Count; i++) { if (model.Roles[i] == user.UserRole) { model.AmountOfRoles[i]++; break; } } } return(View(model)); }
public IActionResult SearchUser(string searchTerm, int?page) { if (string.IsNullOrEmpty(searchTerm)) { return(RedirectToAction("Index")); } List <UserListViewModel> users = userManager.Users .Where(x => x.Email.ToString().ToLower().Contains(searchTerm.ToLower())) .Select(u => new UserListViewModel { Id = u.Id, Email = u.Email //RoleName = roleManager.Roles.FirstOrDefault(r => r.Id == u.).Name //RoleName = userManager.GetRolesAsync(u).Result.Single().ToString() }) .ToList(); Pager pager = new Pager(users.Count(), page); IndexUserViewModel viewPageIndexModel = new IndexUserViewModel { Items = users.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize).ToList(), Pager = pager }; ViewData["searchTerm"] = searchTerm; return(View(viewPageIndexModel)); }
// GET: Users/?page=3 public ActionResult Index(int page = 1) { int totalUsers = _userService.GetAllUsers().Count(); var users = _userService.GetNUsers(usersPerPage, (page - 1) * usersPerPage); PageInfo pageInfo = new PageInfo { PageNumber = page, PageSize = usersPerPage, TotalItems = totalUsers }; var iuvm = new IndexUserViewModel { PageInfo = pageInfo, Users = users }; return View(iuvm); }
public async Task <ActionResult> IndexAsync() { var user = await userManager.FindByIdAsync(UserId); var vm = new IndexUserViewModel() { Users = await GetUsersListViewModelsPaged(new PagingParameters(1, 9), user.CompanyId) }; return(View("Index", vm)); }
public IndexUserViewModel PreparedPage(string userId) { IndexUserViewModel indexUserViewModel = new IndexUserViewModel() { CountReadedBooks = this.CountReadedBooks(userId), CountTakenBooks = this.CountTakenBooks(userId), CountLibrary = this.CountLibrary(userId), LoveGenre = this.LoveGenre(userId), }; return(indexUserViewModel); }
public async Task <IActionResult> Index() { var userId = this.userManager.GetUserId(this.User); var model = new IndexUserViewModel() { Appoitments = await this.appointmentsService.GetClientsUpcomingAppointmentsAsync <BaseAppoitmentViewModel>(userId), IsNewAnswer = await this.answersService.CheckNewAnswerAsync(userId), HasToReview = await this.appointmentsService.CheckPastProceduresAsync(userId), }; return(this.View(model)); }
public async Task ThrowsBadRequestWithNotFoundException() { var userServiceMock = new Mock <IUserService>(); var sut = new UsersController(userServiceMock.Object); userServiceMock.Setup(x => x.GetUserByIdAsync(TestHelpersNoteController.TestUserDTO1().Id)).ThrowsAsync(new NotFoundException()); var model = new IndexUserViewModel(); //model.User = TestHelpersUsersController.TestUserViewModel1(); var actionResult = await sut.Details(TestHelpersNoteController.TestUserDTO1().Id); Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult)); }
public async Task <IActionResult> UpdateUserRole(IndexUserViewModel model) { var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == model.UserID); if (user != null) { await _userManager.AddToRoleAsync(user, model.Role); await _userManager.RemoveFromRoleAsync(user, model.OldRole); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> ReactivateAccount(IndexUserViewModel model) { var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == model.UserID); if (user != null) { user.IsActive = true; _context.Entry(user).State = EntityState.Modified; await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }
public ActionResult Index() { var Db = new ApplicationDbContext(); var users = Db.Users; var model = new List <IndexUserViewModel>(); foreach (var user in users) { var u = new IndexUserViewModel(user); model.Add(u); } return(View(model)); }
public async Task Succeed() { var userServiceMock = new Mock <IUserService>(); var sut = new UsersController(userServiceMock.Object); userServiceMock.Setup(x => x.GetUserByIdAsync(TestHelpersNoteController.TestUserDTO1().Id)).ReturnsAsync(TestHelpersNoteController.TestUserDTO1()); var model = new IndexUserViewModel(); //model.User = TestHelpersUsersController.TestUserViewModel1(); var actionResult = await sut.Details(TestHelpersNoteController.TestUserDTO1().Id); Assert.IsInstanceOfType(actionResult, typeof(ViewResult)); }
// GET: Admin/User public ActionResult Index(bool onlyBlocked = false, bool onlyUnlock = false, int page = 1) { onlyBlocked = onlyBlocked == false ? onlyUnlock : onlyBlocked; var users = _userManager.GetUsers(onlyBlocked); var userList = users.Select(Mapper.Map <User, UserViewModel>).Skip((page - 1) * _pageSize).Take(_pageSize).ToList(); var pager = new Pager(page, users.Count(), _pageSize); var model = new IndexUserViewModel { Pager = pager, Users = userList, Blocked = onlyBlocked }; return(View(model)); }
public IActionResult Index() { var users = _userManager.Users.ToList(); List <IndexUserViewModel> indexUsers = new List <IndexUserViewModel>(); IndexUserViewModel model = new IndexUserViewModel(); foreach (var user in users) { var RestName = _context.RestaurantsList.Where(u => u.ID == user.RestaurantID).FirstOrDefault(); model = new IndexUserViewModel { Id = user.Id, Email = user.Email, FullName = user.FullName, RestaurantName = RestName != null?RestName.Name:"", PersonPhone = user.PersonPhone }; indexUsers.Add(model); } return(View(indexUsers)); }
public async Task Returns_RedirectToAction() { var userServiceMock = new Mock <IUserService>(); var sut = new UsersController(userServiceMock.Object); userServiceMock.Setup(x => x.GetUserByIdAsync(TestHelpersNoteController.TestUserDTO1().Id)).ThrowsAsync(new Exception()); var model = new IndexUserViewModel(); var actionResult = await sut.Details(TestHelpersNoteController.TestUserDTO1().Id); var result = (RedirectToActionResult)actionResult; Assert.AreEqual("Error", result.ActionName); Assert.AreEqual("Home", result.ControllerName); Assert.IsInstanceOfType(result, typeof(RedirectToActionResult)); }
public async Task <IActionResult> Index() { var users = await _context.Users.ToListAsync(); var vm = new IndexUserViewModel(); vm.Users = new List <ApplicationUserDetails>(); if (users != null) { foreach (var u in users) { var role = await _userManager.GetRolesAsync(u); string roles = ""; if (role != null) { foreach (var r in role) { roles += r; } } ApplicationUserDetails details = new ApplicationUserDetails { FirstName = u.FirstName, LastName = u.LastName, UserGender = u.UserGender, Role = roles, Email = u.Email, Id = u.Id, IsActive = u.IsActive, Mobile = u.Mobile, Phone = u.Phone }; vm.Users.Add(details); } } return(View(vm)); }
public async Task <IActionResult> Details(string id) { try { var user = await this.userService.GetUserByIdAsync(id); var model = new IndexUserViewModel(); model.User = user.MapFrom(); return(View(model)); } catch (NotFoundException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { log.Error("Unexpected exception occured:", ex); return(RedirectToAction("Error", "Home")); } }
public IActionResult Index(int page = 1) { try { IndexUserViewModel model = new IndexUserViewModel { Users = _userLogic.List() .OrderBy(g => g.Id) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = _userLogic.List().Count } }; return(View(model)); } catch (ConnectionException ex) { _logger.Log(LogLevel.Error, $"The following error occurred: {ex.Message} @ {GetType().Name}"); ViewBag.ErrorMessage = ex.Message; } catch (NotFoundException ex) { _logger.Log(LogLevel.Error, $"The following error occurred: {ex.Message} @ {GetType().Name}"); ViewBag.ErrorMessage = ex.Message; } catch (Exception ex) { _logger.Log(LogLevel.Error, $"A general exception occurred: {ex.Message} @ {GetType().Name}"); ViewBag.ErrorMessage = ex.Message; } return(View(null)); }
// // GET: /Manage/Index public async Task <ActionResult> Index(ManageMessageId?message) { ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set." : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set." : message == ManageMessageId.Error ? "An error has occurred." : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added." : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed." : ""; var userId = User.Identity.GetUserId(); var indexViewModel = new IndexViewModel { HasPassword = HasPassword(), PhoneNumber = await UserManager.GetPhoneNumberAsync(userId), TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId), Logins = await UserManager.GetLoginsAsync(userId), BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId) }; ApplicationDbContext AppDb = new ApplicationDbContext(); WebShopMobileDb WebDb = new WebShopMobileDb(); var user = AppDb.Users.FirstOrDefault(x => x.Id == userId); var customer = WebDb.Customers.Include("Orders").FirstOrDefault(x => x.EmailAdress == user.Email); var userViewModel = new UserViewModel(user, customer); var model = new IndexUserViewModel(indexViewModel, userViewModel); if (Request.IsAjaxRequest()) { return(PartialView(model)); } return(View(model)); }
public async Task <IndexUserViewModel> GetUsers(UserFilterViewModel indexUser, int page) { if (indexUser == null) { return(new IndexUserViewModel() { PageViewModel = new PageViewModel(0, 1, 3), UserInfo = new List <UserInfo>(), UserFilterViewModel = indexUser }); } indexUser.SearchValue = indexUser.SearchValue == null ? "Any" : indexUser.SearchValue; indexUser.SearchFilter = indexUser.SearchFilter == null ? "" : indexUser.SearchFilter; indexUser.SortItem = indexUser.SortItem == null ? "" : indexUser.SortItem; IEnumerable <UserInfo> item = new List <UserInfo>(); item = GetSortUser(await GetSearchingUser(indexUser), indexUser.SortItem); var count = item.Count(); var skipCells = item.Skip((page - 1) * 3).Take(3).ToList(); if (skipCells.Count == 0 && page != 1) { skipCells = item.Skip((page - 2) * 3).Take(3).ToList(); page -= 1; } PageViewModel pageViewModel = new PageViewModel(count, page, 3); IndexUserViewModel viewModel = new IndexUserViewModel { PageViewModel = pageViewModel, UserInfo = skipCells, UserFilterViewModel = indexUser }; return(viewModel); }
public IActionResult Index(int?page) { List <UserListViewModel> users = new List <UserListViewModel>(); users = userManager.Users .Select(u => new UserListViewModel { Id = u.Id, Email = u.Email //RoleName = roleManager.Roles.FirstOrDefault(r => r.Id == u.).Name //RoleName = userManager.GetRolesAsync(u).Result.Single().ToString() }) .ToList(); Pager pager = new Pager(users.Count(), page); IndexUserViewModel viewPageIndexModel = new IndexUserViewModel { Items = users.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize).ToList(), Pager = pager }; return(View(viewPageIndexModel)); }
// GET: User public ActionResult Index() { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { return(HttpNotFound()); } //get all the users var users = db.Users.ToList(); //get all the user roles var roles = GetRolesFromUsers(users); //create the view model var viewModel = new IndexUserViewModel() { Users = users.ToArray(), UserRoles = roles.ToArray() }; return(View(viewModel)); }
public async Task <IActionResult> Index() { var viewModel = new IndexViewModel(); var currentUserId = this.userManager.GetUserId(this.User); if (this.User.IsInRole(GlobalConstants.ClientRoleName)) { var currentClientId = await this.clientsServices.GetClientIdByUserIdAsync(currentUserId); var clientViewModel = new IndexClientViewModel { ProjectsCount = this.projectsService.AllCountByClientId(currentClientId), ProjectsApprovedCount = this.projectsService.AllApprovedCountByClientId(currentClientId), ProjectsNotApprovedCount = this.projectsService.AllNotApprovedCountByClientId(currentClientId), TotalBudget = this.projectsService.CalculateApprovedProjectsBudgetByClientId(currentClientId), }; viewModel.ClientDashboard = clientViewModel; } if (this.User.IsInRole(GlobalConstants.CompanyOwnerRoleName) || this.User.IsInRole(GlobalConstants.AdministratorRoleName)) { var administrationViewModel = new IndexAdministrationViewModel { InvitesCount = this.invitesService.GetAllCount(), InvitesApprovedCount = this.invitesService.GetAllApprovedCount(), InvitesInvitedExpiredOnCount = this.invitesService.GetAllInvitedExpiredOnCount(), InvitesRequestExpiredOnCount = this.invitesService.GetAllRequestExpiredOnCount(), UsersWithDeletedCount = this.usersService.GetAllWithDeletedCount(), UsersCount = this.usersService.GetAllCount(), UsersDeletedCount = this.usersService.GetAllDeletedCount(), ClientsCount = this.clientsServices.GetAllCount(), }; viewModel.AdministrationDashboard = administrationViewModel; } if (this.User.IsInRole(GlobalConstants.CompanyOwnerRoleName) || this.User.IsInRole(GlobalConstants.ProjectManagerRoleName)) { var userRole = await this.roleManager.FindByNameAsync(GlobalConstants.UserRoleName); var userRoleId = userRole.Id; var managementViewModel = new IndexManagementViewModel { AllProjectsCount = this.projectsService .AllCount(), AllApprovedProjectsCount = this.projectsService .AllApprovedCount(), AllCompletedProjectsCount = this.projectsService .AllCompletedCount(), AssignedManagersCount = this.userManager .Users .Where(u => u.Projects.Count != 0) .Count(), AssignedUsersCount = this.userManager .Users .Where(u => u.UserProblems.Count != 0) .Count(), FreeUsersCount = this.userManager .Users .Where(u => u.UserProblems.Count == 0 && u.Roles.Select(r => r.RoleId).Contains(userRoleId)) .Count(), TotalBudgetApprovedProjects = this.projectsService .TotalBudgetApproved(), TotalBudgetCompletedProjects = this.projectsService .TotalBudgetCompleted(), TotalCostsCompletedProjects = this.projectsService.TotalCostsCompleted(), }; viewModel.ManagementDashboard = managementViewModel; } if (this.User.IsInRole(GlobalConstants.CompanyOwnerRoleName) || this.User.IsInRole(GlobalConstants.ProjectManagerRoleName) || this.User.IsInRole(GlobalConstants.UserRoleName)) { var userViewModel = new IndexUserViewModel { MyProjectsCount = this.projectsService.AllCountByManagerId(currentUserId), MyCompletedProjectsCount = this.projectsService.AllCompletedCountByManagerId(currentUserId), MyTasksCount = this.problemsService.AllTasksCountByUserId(currentUserId), MyCompletedTasksCount = this.problemsService.AllCompletedTasksCountByUserId(currentUserId), TotalBudgetMyProjects = this.projectsService.TotalBudgetByManagerId(currentUserId), TotalBudgetMyCompletedProjects = this.projectsService .CompletedTotalBudgetByManagerId(currentUserId), SumAdditionalCostsMyCompletedProjects = this.additionalCostsService .SumAdditionalCostsCompletedProjectsByManagerId(currentUserId), SumCostsMyCompletedProjects = this.problemsService .SumCostsCompleteProjectsByManagerId(currentUserId), }; viewModel.UserDashboard = userViewModel; } return(this.View(viewModel)); }