public DataTablesResponse Get( [FromUri]int iDisplayStart, [FromUri]int iDisplayLength, [FromUri]int iColumns, [FromUri]string sSearch, [FromUri]int iSortCol_0, [FromUri]string sSortDir_0, [FromUri]string sEcho) { DataTablesResponse response = new DataTablesResponse(); Expression<Func<UserProfile, bool>> search = m => true; if (sSearch != null && sSearch.Length > 0) { search = search.And(m => m.Email.Contains(sSearch) || m.FirstName.Contains(sSearch) || m.LastName.Contains(sSearch) || m.JobTitle.Contains(sSearch)); } Func<UserProfileListItem, IComparable> orderBy; switch (iSortCol_0) { case 0: // id orderBy = o => o.Id; break; case 1: // email orderBy = o => o.Email; break; case 2: // last name orderBy = o => o.LastName; break; case 3: // first name orderBy = o => o.FirstName; break; case 4: // job title orderBy = o => o.JobTitle; break; case 5: // company id orderBy = o => o.CompanyId; break; case 6: // confirmed orderBy = o => o.Confirmed; break; default: orderBy = o => o.Id; break; } int sEchoCheck; if (int.TryParse(sEcho, out sEchoCheck)) { response.sEcho = sEcho; } else { throw new Exception("sEcho is invalid"); } response.iTotalRecords = _service.GetEnumerable().Count(); response.iTotalDisplayRecords = _service.GetEnumerable(search).Count(); UserProfileListItem[] data; switch (sSortDir_0) { case "asc": data = _service.GetEnumerable(search) .Select(s => new UserProfileListItem { CompanyId = s.CompanyId, Confirmed = _security.IsConfirmed(s.Email), Email = s.Email, FirstName = s.FirstName, Id = s.UserId, LastName = s.LastName, JobTitle = s.JobTitle }) .OrderBy(orderBy) .Skip(iDisplayStart) .Take(iDisplayLength) .ToArray(); break; case "desc": data = _service.GetEnumerable(search) .Select(s => new UserProfileListItem { CompanyId = s.CompanyId, Confirmed = _security.IsConfirmed(s.Email), Email = s.Email, FirstName = s.FirstName, Id = s.UserId, LastName = s.LastName, JobTitle = s.JobTitle }) .OrderByDescending(orderBy) .Skip(iDisplayStart) .Take(iDisplayLength) .ToArray(); break; default: throw new Exception("invalid sort direction"); } response.aaData = data; return response; }
public DataTablesResponse Get(HttpRequestMessage request, [FromUri]int iDisplayStart, [FromUri]int iDisplayLength, [FromUri]int iColumns, [FromUri]string sSearch, [FromUri]int iSortCol_0, [FromUri]string sSortDir_0, [FromUri]string sEcho) { DataTablesResponse response = new DataTablesResponse(); Expression<Func<CompanyProfile, bool>> predicate = m => true; if (sSearch != null && sSearch.Length > 0) { predicate.And(m => m.CompanyName.Contains(sSearch)); } Func<CompanyProfileListItem, IComparable> orderBy; switch (iSortCol_0) { case 0: // id orderBy = o => o.Id; break; case 1: // name orderBy = o => o.CompanyName; break; case 2: // type orderBy = o => o.BusinessType; break; case 3: // manager orderBy = o => o.Manager; break; case 4: // state orderBy = o => o.State; break; case 5: // postal code orderBy = o => o.PostalCode; break; case 6: // published orderBy = o => o.Published; break; default: orderBy = o => o.Id; break; } int sEchoCheck; if (int.TryParse(sEcho, out sEchoCheck)) { response.sEcho = sEcho; } else { throw new Exception("sEcho is invalid"); } response.iTotalDisplayRecords = _service.GetEnumerable(predicate).Count(); response.iTotalRecords = _service.GetEnumerable().Count(); CompanyProfileListItem[] data; switch (sSortDir_0) { case "asc": data = _service.GetEnumerable(predicate) .Where(x => x.Id != 1) .Select(s => new CompanyProfileListItem { BusinessType = s.BusinessType.ToDescription(), CompanyName = s.CompanyName, Id = s.Id, PostalCode = s.PostalCode == null ? "not set" : s.PostalCode, Published = s.Published, Subscribed = s.SubscriptionStatus.ToString(), State = s.State == null ? "not set" : s.State.Abbr, Manager = s.Users.Where(u => _security.IsUserInRole(u.Email, "Manager")).Count() == 0 ? "not set" : s.Users.Where(u => _security.IsUserInRole(u.Email, "Manager")).Select(u => u.LastName + ", " + u.FirstName).FirstOrDefault() }) .OrderBy(orderBy) .Skip(iDisplayStart) .Take(iDisplayLength) .ToArray(); break; case "desc": data = _service.GetEnumerable(predicate) .Where(x => x.Id != 1) .Select(s => new CompanyProfileListItem { BusinessType = s.BusinessType.ToDescription(), CompanyName = s.CompanyName, Id = s.Id, PostalCode = s.PostalCode, Published = s.Published, Subscribed = s.SubscriptionStatus.ToString(), State = s.State.Abbr, Manager = s.Users.Where(u => _security.IsUserInRole(u.Email, "Manager")).Count() == 0 ? "not set" : s.Users.Where(u => _security.IsUserInRole(u.Email, "Manager")).Select(u => u.LastName + ", " + u.FirstName).FirstOrDefault() }) .OrderByDescending(orderBy) .Skip(iDisplayStart) .Take(iDisplayLength) .ToArray(); break; default: throw new Exception("invalid sort direction"); } response.aaData = data; return response; }
public DataTablesResponse Get( [FromUri]int iDisplayStart, [FromUri]int iDisplayLength, [FromUri]int iColumns, [FromUri]string sSearch, [FromUri]int iSortCol_0, [FromUri]string sSortDir_0, [FromUri]string sEcho) { DataTablesResponse response = new DataTablesResponse(); Expression<Func<Project, bool>> predicate = m => true; if (sSearch != null && sSearch.Length > 0) { predicate = predicate.And(m => m.Architect.CompanyName.Contains(sSearch) || m.Title.Contains(sSearch) || m.Number.Contains(sSearch) || m.BuildingType.Name.Contains(sSearch) || m.ConstructionType.Name.Contains(sSearch)); } Func<ProjectListItem, IComparable> orderBy; switch (iSortCol_0) { case 0: // id orderBy = o => o.Id; break; case 1: // number orderBy = o => o.Number; break; case 2: // title orderBy = o => o.Title; break; case 3: // bid date orderBy = o => o.BidDate; break; case 4: // state orderBy = o => o.State; break; case 5: // created by orderBy = o => o.CreatedBy; break; case 6: // architect orderBy = o => o.Architect; break; case 7: // project type orderBy = o => o.ProjectType; break; case 8: // construction type orderBy = o => o.ConstructionType; break; case 9: // building type orderBy = o => o.BuildingType; break; default: orderBy = o => o.Id; break; } int sEchoInt; if (int.TryParse(sEcho, out sEchoInt)) { response.sEcho = sEcho; } else { throw new Exception("sEcho is invalid"); } response.iTotalRecords = _service.GetEnumerable().Count(); response.iTotalDisplayRecords = _service.GetEnumerable(predicate).Count(); ProjectListItem[] data; switch (sSortDir_0) { case "asc": data = _service.GetEnumerable(predicate) .Select(p => new ProjectListItem { Id = p.Id, Number = p.Number, Title = p.Title, BidDate = p.BidDateTime, BuildingType = p.BuildingType.Name, ConstructionType = p.ConstructionType.Name, ProjectType = p.ProjectType.ToDescription(), Architect = p.Architect.CompanyName, CreatedBy = p.CreatedBy.LastName + ", " + p.CreatedBy.FirstName, State = p.State.Abbr }) .OrderBy(orderBy) .Skip(iDisplayStart) .Take(iDisplayLength) .ToArray(); break; case "desc": data = _service.GetEnumerable(predicate) .Select(p => new ProjectListItem { Id = p.Id, Number = p.Number, Title = p.Title, BidDate = p.BidDateTime, BuildingType = p.BuildingType.Name, ConstructionType = p.ConstructionType.Name, ProjectType = p.ProjectType.ToDescription(), Architect = p.Architect.CompanyName, CreatedBy = p.CreatedBy.LastName + ", " + p.CreatedBy.FirstName, State = p.State.Abbr }) .OrderByDescending(orderBy) .Skip(iDisplayStart) .Take(iDisplayLength) .ToArray(); break; default: throw new Exception("invalid sort direction"); } response.aaData = data; return response; }