public SearchResult<ProjectObj> Search(string query, int curPage, int pageSize) { var splitQuery = query.Split(' '); var filter = new ProjectFilter { QueryNames = splitQuery, QueryDescriptions = splitQuery, StartIndex = curPage * pageSize, MaxResults = pageSize + 1 //we do +1 so we can see if the next button will be enabled }; var objs = Repository.GetProjects(filter); SearchResult<ProjectObj> result = new SearchResult<ProjectObj>(); result.HasMore = objs.Count > pageSize; if (result.HasMore) { //we remove the last object because it was only fetched to see if has more is enabled objs.RemoveAt(objs.Count - 1); } result.HasPrevious = curPage > 0; result.Results = objs; return result; }
public IList<ProjectObj> GetByOwner(string username) { var filter = new ProjectFilter() { OwnersUserName = username }; return Repository.GetProjects(filter); }
public ProjectObj Get(int id) { var filter = new ProjectFilter { Id = id }; var obj = Repository.GetProjects(filter).SingleOrDefault(); if (obj != null) { var feedLogic = new FeedLogic(Repository); obj.Feeds = feedLogic.GetForProject(obj.Id.Value); var tagLogic = new TagLogic(Repository); obj.Tags = tagLogic.GetForProject(obj.Id.Value); } return obj; }
public IList<ProjectObj> GetProjects(ProjectFilter filter) { using (var db = GetInnerTrackContext()) { var items = db.Projects.AsQueryable(); if (filter.Id.HasValue) { items = items.Where(i => i.Id == filter.Id.Value); } if (!string.IsNullOrEmpty(filter.OwnersUserName)) { items = items.Where(i => i.Members.Any(m => m.Email == filter.OwnersUserName)); } if (filter.QueryNames != null) { items = items.Where(i => filter.QueryNames.Any(q => i.Name.Contains(q))); } if (filter.QueryDescriptions != null) { items = items.Where(i => filter.QueryDescriptions.Any(q => i.Name.Contains(q))); } if (filter.StartIndex.HasValue) { items = items.OrderBy(i => i.Id).Skip(filter.StartIndex.Value); } if (filter.MaxResults.HasValue) { items = items.Take(filter.MaxResults.Value); } return items.ToList(); } }
public IList<ProjectObj> GetAll() { var filter = new ProjectFilter(); return Repository.GetProjects(filter); }