2016-01-11 06:23:13 +08:00
|
|
|
|
using System;
|
2015-11-10 00:43:05 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-01-12 05:16:29 +08:00
|
|
|
|
using MongoDB.Bson;
|
|
|
|
|
using MongoDB.Driver;
|
2015-11-10 00:43:05 +08:00
|
|
|
|
|
2016-08-20 05:10:55 +08:00
|
|
|
|
namespace BuildFeed.Model
|
2015-11-10 00:43:05 +08:00
|
|
|
|
{
|
2016-08-21 07:09:56 +08:00
|
|
|
|
public partial class BuildRepository
|
2015-11-10 00:43:05 +08:00
|
|
|
|
{
|
2016-08-19 20:45:52 +08:00
|
|
|
|
public Task<TypeOfSource[]> SelectAllSources(int limit = -1, int skip = 0) => Task.Run(() => Enum.GetValues(typeof(TypeOfSource)) as TypeOfSource[]);
|
2015-11-10 00:43:05 +08:00
|
|
|
|
|
2016-08-19 20:45:52 +08:00
|
|
|
|
public Task<long> SelectAllSourcesCount() => Task.Run(() => Enum.GetValues(typeof(TypeOfSource)).LongLength);
|
2016-01-11 06:23:13 +08:00
|
|
|
|
|
2016-08-21 07:09:56 +08:00
|
|
|
|
public async Task<List<Build>> SelectSource(TypeOfSource source, int limit = -1, int skip = 0)
|
2016-01-12 05:16:29 +08:00
|
|
|
|
{
|
2016-08-21 07:09:56 +08:00
|
|
|
|
IFindFluent<Build, Build> query = _buildCollection.Find(new BsonDocument(nameof(Build.SourceType), source)).Sort(sortByOrder).Skip(skip);
|
2016-01-11 06:23:13 +08:00
|
|
|
|
|
2016-01-12 05:16:29 +08:00
|
|
|
|
if (limit > 0)
|
|
|
|
|
{
|
|
|
|
|
query = query.Limit(limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await query.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-21 07:09:56 +08:00
|
|
|
|
public async Task<long> SelectSourceCount(TypeOfSource source) => await _buildCollection.CountAsync(new BsonDocument(nameof(Build.SourceType), source));
|
2015-11-10 00:43:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|