コード例 #1
0
        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));
            }
        }
コード例 #2
0
 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));
     }
 }
コード例 #3
0
        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)));
            }
        }
コード例 #4
0
        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> >());
            }
        }
コード例 #5
0
 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));
 }
コード例 #6
0
 public IActionResult GetBrands(FilteredPagedBinding binding) => Ok(_consumationHandler.GetBrands(binding));
コード例 #7
0
 public IActionResult GetBeerNew(FilteredPagedBinding binding) => Ok(_consumationHandler.GetNewBeers(binding));