public PagedView <View.Beer.Beer> GetNewBeers(FilteredPagedBinding binding) { using (var context = GetMainContext()) { var oldBeerIds = binding.From.HasValue ? context.Consumations.WhereUser(UserId) .Where(new FilteredPagedBinding() { To = binding.From.Value.AddDays(-1) }) .Select(x => x.Beer.Id) : null; return(context.Consumations.WhereUser(UserId) .Include(x => x.Beer) .Where(binding) .GroupBy(x => new { x.Beer.Id, x.Beer.Name, x.Beer.ValueId }) .Select(x => new { Beer = x.Key, Date = x.Min(y => y.Date) }) .Where(x => oldBeerIds == null || !oldBeerIds.Any(y => x.Beer.Id == y)) .OrderByDescending(x => x.Date) .Select(x => new View.Beer.Beer() { Id = x.Beer.ValueId, Name = x.Beer.Name }) .ToPagedView(binding)); } }
public PagedView <View.Beer.BeerBrand> GetBrands(FilteredPagedBinding binding) { using (var context = GetMainContext()) { return(context.Consumations.WhereUser(UserId) .Where(binding) .Select(x => x.Beer.BeerBrand) .Distinct() .Select(x => new View.Beer.BeerBrand(x)) .ToPagedView(binding)); } }
public async Task <IEnumerable <Track> > GetTracks(FilteredPagedBinding binding) { using (var db = GetMainContext()) { string username = db.Users.SingleOrDefault(x => x.Id == UserId) .LastFmUsername; var tracks = await _userHelper.GetTracks(username, binding); return(tracks.Select(x => new Track(x))); } }
public async Task <IEnumerable <Track> > GetTracks(string username, FilteredPagedBinding filter) { using (var client = new HttpClient()) { var request = new UserGetRecentTracks(_url, _key, username) { Api_Key = _key, From = filter.From?.ToUnix().ToString(), User = username, To = filter.To?.ToUnix().ToString() }; var json = await client.GetStringAsync(request.ToUrl()); var tracks = JObject.Parse(json).SelectToken("recenttracks") .SelectToken("track"); return(tracks.ToObject <IEnumerable <Track> >()); } }
public static IQueryable <Consumation> Where(this IQueryable <Consumation> query, FilteredPagedBinding binding) { return(query.Include(x => x.Beer) .WhereIf(binding.From.HasValue, x => x.Date >= binding.From.Value) .WhereIf(binding.To.HasValue, x => x.Date <= binding.To.Value)); }
public IActionResult GetBrands(FilteredPagedBinding binding) => Ok(_consumationHandler.GetBrands(binding));
public IActionResult GetBeerNew(FilteredPagedBinding binding) => Ok(_consumationHandler.GetNewBeers(binding));