public List <User> GetUsers(int clientId, int active, string name) { IEnumerable <User> users; IUserClientRepository _userClientRepo = new UserClientRepository(); if (clientId != -1 || active != -1 || name != "") { users = _context.Users.Include(s => s.AccessLevel).Include(s => s.UserClients).Include(s => s.UserClients.Select(y => y.Client)).Include(s => s.Client).Include(s => s.UserLevels).Include(s => s.UserLevels.Select(y => y.Level)).ToList(); if (clientId != -1) { //users = users.Where(x => x.ClientID == clientId); users = users.Where(x => _userClientRepo.GetByClientID(clientId).Select(y => y.UserID).Contains(x.UserID)); } if (active != -1) { users = users.Where(x => x.Active == active); } if (name != "") { users = users.Where(x => (!string.IsNullOrEmpty(x.FirstName)? x.FirstName.ToLower().Contains(name.ToLower()):false) || (!string.IsNullOrEmpty(x.LastName)? x.LastName.ToLower().Contains(name.ToLower()):false) || (!string.IsNullOrEmpty(x.EMail)? x.EMail.ToLower().Contains(name.ToLower()):false) || (!string.IsNullOrEmpty(x.UserName) ? x.UserName.ToLower().Contains(name.ToLower()) : false) ); } } else { return(null); } return(users.ToList()); }
public IEnumerable <Form> GetFormList(int clientId, int formTypeId, int?userId)//, string searchKeyword) { //var sSearch = searchKeyword.ToLower(); IEnumerable <Form> documents; //if (clientId != -1 || formTypeId != -1)// || searchKeyword != "") //{ documents = _context.Forms.Include(x => x.Client).Include(x => x.FormType).Include(x => x.Requests); if (userId != null) { IUserClientRepository _UserClientRepo = new UserClientRepository(); var clientList = _UserClientRepo.GetByUserId(userId.Value).Select(x => x.Client.ID); documents = documents.Where(x => x.Client != null && clientList.Contains(x.Client.ID)); } if (clientId != -1) { documents = documents.Where(x => x.ClientID == clientId); } if (formTypeId != -1) { documents = documents.Where(x => x.FormTypeID == formTypeId); } //if (searchKeyword != "") //{ // documents = documents.Where(x => !string.IsNullOrEmpty(x.DocumentName) ? x.DocumentName.ToLower().Contains(sSearch) : false); //} //} //else //{ // return null; //} return(documents); }
public List <Document> GetDocumentList(int clientId, int documentTypeId, int practiceAreaId, int categoryId, int formTypeId, string searchKeyword, int?userId) { IDocumentClientsRepository _documentClientsRepo = new DocumentClientsRepository(); var sSearch = searchKeyword.ToLower(); IEnumerable <Document> documents; if (clientId != -1 || practiceAreaId != -1 || documentTypeId != -1 || categoryId != -1 || formTypeId != -1 || searchKeyword != "") { documents = _context.Documents.Include(s => s.PracticeArea).Include(s => s.Client).ToList(); if (userId != null) { IUserClientRepository _UserClientRepo = new UserClientRepository(); var clientList = _UserClientRepo.GetByUserId(userId.Value).Select(x => x.Client.ID); documents = documents.Where(x => x.Client != null && clientList.Contains(x.Client.ID)); } if (clientId != -1) { documents = documents.Where(x => _documentClientsRepo.GetByClientID(clientId).Select(y => y.documentID).Contains(x.ID)); } if (documentTypeId != -1) { documents = documents.Where(x => x.DocumentTypeID == documentTypeId); } if (practiceAreaId != -1) { documents = documents.Where(x => x.PracticeAreaID == practiceAreaId); } if (categoryId != -1) { documents = documents.Where(x => x.CategoryID == categoryId); } if (formTypeId != -1) { documents = documents.Where(x => x.FormTypeID == Convert.ToString(formTypeId)); } if (searchKeyword != "") { documents = documents.Where(x => !string.IsNullOrEmpty(x.DocumentName) ? x.DocumentName.ToLower().Contains(sSearch) : false); } } else { return(null); } return(documents.ToList()); }