// GET: api/Stories/range/1/5 public IQueryable <StorySearchVM> GetStoriesByRange(int start, int end) { IQueryable <Story> stories = from s in db.Stories where s.StoryStatus == 1 orderby s.StoryId descending select s; List <StorySearchVM> storyVMs = new List <StorySearchVM>(); StorySearchVM storySearchVM; int total = stories.Count(); if (start < 1 || (start > end && start < total) || start > total) { start = 1; end = 0; } if (end > total) { end = total; } int begin = start - 1; foreach (var story in stories.Skip(begin).Take(end - begin)) { storySearchVM = new StorySearchVM(story); storyVMs.Add(storySearchVM); } return(storyVMs.AsQueryable()); }
public IQueryable <StorySearchVM> GetStoriesByAuthor(string name, int start, int end) { IQueryable <Story> stories = from s in db.Stories where (s.Author.AuthorName.Equals(name) || s.Author.Slug.Equals(name)) && s.StoryStatus == 1 orderby s.StoryName select s; List <StorySearchVM> storyVMs = new List <StorySearchVM>(); StorySearchVM storySearchVM; int total = stories.Count(); if (start < 1 || (start > end && start < total) || start > total) { start = 1; end = 0; } if (end > total) { end = total; } int begin = start - 1; foreach (var story in stories.Skip(begin).Take(end - begin)) { storySearchVM = new StorySearchVM(story); storyVMs.Add(storySearchVM); } return(storyVMs.AsQueryable()); }
// GET: api/Stories/rank/20 public IQueryable <StorySearchVM> GetStoriesByRank(int top) { IQueryable <Story> stories = from s in db.Stories where s.StoryStatus == 1 orderby SqlFunctions.Exp(s.RateCount == 0? 0 : (double)s.Score / s.RateCount) descending select s; List <StorySearchVM> storyVMs = new List <StorySearchVM>(); StorySearchVM storySearchVM; if (top > stories.Count()) { top = stories.Count(); } foreach (var story in stories.Take(top)) { storySearchVM = new StorySearchVM(story); storyVMs.Add(storySearchVM); } return(storyVMs.AsQueryable()); }