Exemplo n.º 1
0
        public async Task DeleteBeatmapFromCollection(Beatmap beatmap, Collection collection)
        {
            if (beatmap.IsTemporary)
            {
                Logger.Warn("需确认加入自定义目录后才可继续");
                return;
            }

            var relation = await Relations
                           .FirstOrDefaultAsync(k => k.CollectionId == collection.Id && k.BeatmapId == beatmap.Id);

            Relations.Remove(relation);
            await SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task AddOrUpdateCollection(Collection collection)
        {
            var result = await GetCollection(collection.Id);

            if (result == null)
            {
                await AddCollection(collection.Name);
            }
            else
            {
                Collections.Update(collection);
                await SaveChangesAsync();
            }
        }
Exemplo n.º 3
0
        //todo: addorupdate
        public async Task AddBeatmapsToCollection(IList <Beatmap> beatmaps, Collection collection)
        {
            if (beatmaps.Count < 1)
            {
                return;
            }

            var maps = beatmaps.Where(k => !k.IsTemporary);

            collection = await Collections.FindAsync(collection.Id);

            collection.Beatmaps.AddRange(maps);

            await SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task AddCollection(string name, bool locked = false)
        {
            var count = await Collections.CountAsync();

            var maxIndex = count > 0 ? await Collections.MaxAsync(k => k.Index) : -1;

            var collection = new Collection
            {
                Id        = Guid.NewGuid(),
                Name      = name,
                IsDefault = locked,
                Index     = maxIndex + 1
            };

            Collections.Add(collection);
            await SaveChangesAsync();
        }
Exemplo n.º 5
0
        public async Task DeleteBeatmapsFromCollection(IEnumerable <Beatmap> beatmaps, Collection collection)
        {
            var ids = beatmaps.Select(k => k.Id).ToList();

            var relations = Relations
                            .Where(k => k.CollectionId == collection.Id && ids.Contains(k.BeatmapId));

            Relations.RemoveRange(relations);
            await SaveChangesAsync();
        }
Exemplo n.º 6
0
 public async Task DeleteCollection(Collection collection)
 {
     Relations.RemoveRange(Relations.Where(k => k.CollectionId == collection.Id));
     Collections.Remove(collection);
     await SaveChangesAsync();
 }
Exemplo n.º 7
0
        public async Task <PaginationQueryResult <Beatmap> > GetBeatmapsFromCollection(Collection collection,
                                                                                       int page                    = 0,
                                                                                       int countPerPage            = 50,
                                                                                       BeatmapOrderOptions options = BeatmapOrderOptions.CreateTime)
        {
            if (collection.Id == Guid.Empty)
            {
                Console.WriteLine("No collection found.");
                return(new PaginationQueryResult <Beatmap>(new List <Beatmap>(), 0));
            }

            collection = await Collections.FindAsync(collection.Id);

            if (collection == null)
            {
                Console.WriteLine("No collection found.");
                return(new PaginationQueryResult <Beatmap>(new List <Beatmap>(), 0));
            }

            var relations = Relations
                            .AsNoTracking()
                            .Where(k => k.CollectionId == collection.Id);

            var beatmaps = relations.Join(Beatmaps, k => k.BeatmapId, k => k.Id, (k, x) => x);

            var count = await beatmaps.CountAsync();

            var enumerable = options switch
            {
                BeatmapOrderOptions.UpdateTime => beatmaps.OrderByDescending(k => k.UpdateTime),
                BeatmapOrderOptions.CreateTime => beatmaps.OrderByDescending(k => k.CreateTime),
                _ => throw new ArgumentOutOfRangeException(nameof(options), options, null)
            };

            var result = await enumerable
                         .Skip(page *countPerPage)
                         .Take(countPerPage)
                         .ToListAsync();

            return(new PaginationQueryResult <Beatmap>(result, count));
        }