public static bool IsUserNameUnique(this User user, bool isUpdatedCheck) { var queryRepository = RepositoryFactory.CreateQueryRepository(); var constraints = new QueryConstraints <User>() .Where(x => x.UserName == user.UserName); if (isUpdatedCheck) { constraints = constraints.AndAlso(x => x.Id != user.Id); } return(queryRepository.SingleOrDefault(constraints) == null); }
public IQueryResult <User> Find(UserSearchCriteria userSearchCriteria) { if (userSearchCriteria == null) { throw new ArgumentNullException("userSearchCriteria", "must not be null."); } var constraints = new QueryConstraints <User>() .IncludePath(u => u.Roles) .Page(userSearchCriteria.PageNumber, userSearchCriteria.PageSize) .Where(c => true); if (userSearchCriteria.IsActive.HasValue) { constraints.AndAlso(c => c.IsActive == userSearchCriteria.IsActive.Value); } if (!string.IsNullOrEmpty(userSearchCriteria.FullName)) { constraints.AndAlso(c => c.FullName.Contains(userSearchCriteria.FullName)); } if (!string.IsNullOrEmpty(userSearchCriteria.Mobile)) { constraints.AndAlso(c => c.Mobile.Contains(userSearchCriteria.Mobile)); } if (!string.IsNullOrEmpty(userSearchCriteria.RoleName)) { constraints.AndAlso(c => c.Roles.Any(r => r.Name == userSearchCriteria.RoleName)); } if (!string.IsNullOrEmpty(userSearchCriteria.UserName)) { constraints.AndAlso(c => c.UserName.Contains(userSearchCriteria.UserName)); } if (!string.IsNullOrEmpty(userSearchCriteria.Email)) { constraints.AndAlso(c => c.Email.Contains(userSearchCriteria.Email)); } if (string.IsNullOrEmpty(userSearchCriteria.Sort)) { constraints.SortByDescending(c => c.CreatedAt); } //else if (userSearchCriteria.SortDirection == WebGridSortOrder.Ascending) // constraints.SortBy(userSearchCriteria.Sort); else { constraints.SortByDescending(userSearchCriteria.Sort); } return(queryRepository.Find(constraints)); }