BuildFeed/BuildFeed.Model/BuildRepository-Source.cs

33 lines
1.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;
namespace BuildFeed.Model
{
2017-02-24 04:53:49 +08:00
public partial class BuildRepository
{
2018-02-07 06:16:37 +08:00
public Task<TypeOfSource[]> SelectAllSources(int limit = -1, int skip = 0)
=> Task.Run(() => Enum.GetValues(typeof(TypeOfSource)) as TypeOfSource[]);
2017-02-24 04:53:49 +08:00
public Task<long> SelectAllSourcesCount() => Task.Run(() => Enum.GetValues(typeof(TypeOfSource)).LongLength);
2017-02-24 04:53:49 +08:00
public async Task<List<Build>> SelectSource(TypeOfSource source, int limit = -1, int skip = 0)
{
2018-02-07 06:16:37 +08:00
var query = _buildCollection.Find(new BsonDocument(nameof(Build.SourceType), source))
.Sort(sortByOrder)
.Skip(skip);
2017-02-24 04:53:49 +08:00
if (limit > 0)
{
query = query.Limit(limit);
}
2017-02-24 04:53:49 +08:00
return await query.ToListAsync();
}
2018-02-07 06:16:37 +08:00
public async Task<long> SelectSourceCount(TypeOfSource source)
=> await _buildCollection.CountAsync(new BsonDocument(nameof(Build.SourceType), source));
2017-02-24 04:53:49 +08:00
}
}