public void LoadUserPage() { if (LoggedUser.isAdmin) { ActiveItem = new UserGridViewModel(); } }
public JsonResult UserGetList(UserGridViewModel filter) { IQueryable <User> users = UserManager.Users.Where(u => (u.Deleted == false) && (filter.Id == null || u.Id == filter.Id) && (filter.UserName == null || u.UserName.Contains(filter.UserName)) && (filter.FirstName == null || u.FirstName.Contains(filter.FirstName)) && (filter.LastName == null || u.LastName.Contains(filter.LastName)) && (filter.Title == null || u.Title.Contains(filter.Title)) && (filter.Factory == null || u.Factory.Contains(filter.Factory)) && (filter.RoleId == null || u.Roles.Select(y => y.RoleId).Contains(filter.RoleId)) ).OrderBy(u => u.UserName); List <UserGridViewModel> usersList = users.Select(x => new UserGridViewModel { FirstName = x.FirstName, LastName = x.LastName, UserName = x.UserName, DepartmentId = 0, Email = x.Email, Factory = x.Factory, Id = x.Id, Title = x.Title }).ToList(); return(Json(usersList)); }
public JsonResult GetAll(GridFiltersViewModel gridFiltersViewModel) { var userGridViewModel = new UserGridViewModel { GridFilters = gridFiltersViewModel }; var users = _userService.GetAllWithFilters(WebSecurity.CurrentUserId, userGridViewModel.GridFilters.Search, userGridViewModel.GridFilters.SearchAdditional, userGridViewModel.GridFilters.SortColumn, userGridViewModel.GridFilters.SortDirectionIsAscending, userGridViewModel.GridFilters.Page, userGridViewModel.GridFilters.PageSize); userGridViewModel.Users = (from user in users where user.Id != WebSecurity.CurrentUserId select new UserViewModel { Id = user.Id, Email = user.Email, Name = user.Name, DateRegistered = user.DateRegistered, LastLoginAt = user.LastLoginAt, IsBanned = user.IsBanned, BanDate = user.BanDate, BanReason = user.BanReason, MembershipIsConfirmed = user.Membership.IsConfirmed }).ToList(); userGridViewModel.GridFilters.ItemCount = _userService.CountAllWithFilters(WebSecurity.CurrentUserId, userGridViewModel.GridFilters.Search, userGridViewModel.GridFilters.SearchAdditional); return(Json(_validationHelper.ModelStateToJsonResult(ModelState, userGridViewModel), JsonRequestBehavior.AllowGet)); }
public static UserGridViewModel MapToGridViewModel(this User user) { var model = new UserGridViewModel(); model.Id = user.Id; model.UserName = user.UserName; model.Email = user.Email; model.Name = user.Name; model.Surname = user.Surname; model.Role = user.Role; return(model); }
public JsonResult Users(string Keyword = "") { IEnumerable <User> _users = _userRepository.Users.Where(u => u.Enabled == true).OrderBy(u => u.FullName); if (Keyword != "") { _users = _users.Where(u => u.FullName.ToLower().Contains(Keyword.ToLower())).Union(_users.Where(u => u.LogonName.ToLower().Contains(Keyword.ToLower()))); } IEnumerable <Department> _departments = _departmentRepository.Departments.Where(d => d.Enabled == true); IEnumerable <Position> _positions = _posRepository.Positions.Where(p => p.Enabled == true); UserGridViewModel _viewModel = new UserGridViewModel(_users, _departments, _positions, _users.Count()); return(Json(_viewModel, JsonRequestBehavior.AllowGet)); }
public JsonResult UserDelete(UserGridViewModel item) { User user = UserManager.FindById(item.Id); if (user != null) { //user.Deleted = true; //UserManager.Update(user); UserManager.SetDeleted(user.Id); return(Json(1)); } return(Json(0)); }
public JsonResult UserUpdate(UserGridViewModel item) { User user = UserManager.FindById(item.Id); if (user == null) { string userId = UserManager.AddUser(item.UserName); user = UserManager.FindById(userId); if (user == null) { return(Json(0)); } } user.FirstName = item.FirstName; user.LastName = item.LastName; user.Email = item.Email; user.Factory = item.Factory; user.Title = item.Title; UserManager.Update(user); return(Json(user)); }
public void LoadUserPage() { ActiveItem = new UserGridViewModel(); }
public JsonResult UpdateUser([DataSourceRequest] DataSourceRequest request, UserGridViewModel user) { var existingUser = this.Data.Users.All().FirstOrDefault(u => u.Id == user.Id); ModelState["CreatedOn"].Errors.Clear(); if (user == null || !ModelState.IsValid || existingUser == null) { return Json((new[] { user }.ToDataSourceResult(request, ModelState)), JsonRequestBehavior.AllowGet); } var hasher = new PasswordHasher(); existingUser.Id = user.Id; existingUser.UserName = user.UserName; existingUser.FirstName = user.FirstName; existingUser.LastName = user.LastName; existingUser.Email = user.Email; existingUser.Gender = user.Gender; existingUser.Town = user.Town; existingUser.Country = user.Country; existingUser.AboutMe = user.AboutMe; existingUser.Website = user.Website; existingUser.School = user.School; existingUser.University = user.University; existingUser.ProfilePhotoId = user.ProfilePhotoId; existingUser.LastActionTime = user.LastActionTime; this.Data.SaveChanges(); return Json((new[] { user }.ToDataSourceResult(request, ModelState)), JsonRequestBehavior.AllowGet); }
public JsonResult DestroyUser([DataSourceRequest] DataSourceRequest request, UserGridViewModel user) { var existingUser = this.Data.Users.All().FirstOrDefault(u => u.Id == user.Id); this.Data.Users.Delete(existingUser); this.Data.SaveChanges(); return Json(new[] { user }, JsonRequestBehavior.AllowGet); }
public JsonResult CreateUser([DataSourceRequest] DataSourceRequest request, UserGridViewModel user) { ModelState["CreatedOn"].Errors.Clear(); if (user == null || !ModelState.IsValid) { return Json(new[] { user }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); } var newUser = new User { UserName = user.UserName, SecurityStamp = Guid.NewGuid().ToString(), FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Gender = user.Gender, Town = user.Town, Country = user.Country, AboutMe = user.AboutMe, Website = user.Website, School = user.School, University = user.University, LastActionTime = user.LastActionTime, CreatedOn = DateTime.Now, ApplyingFriends = new List<User>(), LockoutEnabled = true, ProfilePhoto = null, Albums = new List<Album>() }; if (user.PasswordHash != null) { var hasher = new PasswordHasher(); newUser.PasswordHash = hasher.HashPassword(user.PasswordHash); } this.Data.Users.Add(newUser); this.Data.SaveChanges(); user.Id = newUser.Id; return Json(new[] { user }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); }