public static void UpdateCollection(Collection collection) { using (ApplicationDbContext context = new ApplicationDbContext()) { try { Collection col = context.Collections.FirstOrDefault(k => k.Id == collection.Id); if (col == null) { var newOne = new Collection(Guid.NewGuid().ToString(), collection.Name, false, 0, collection.ImagePath, collection.Description) { CreateTime = DateTime.Now }; context.Collections.Add(newOne); } else { col.Description = collection.Description; col.ImagePath = collection.ImagePath; col.Index = collection.Index; col.Name = collection.Name; } context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public static void RemoveMapFromCollection(MapIdentity id, Collection collection) { using (ApplicationDbContext context = new ApplicationDbContext()) { try { MapInfo map = InnerGetMapFromDb(id, context); context.Relations.RemoveRange(context.Relations.Where(k => k.CollectionId == collection.Id && k.MapId == map.Id)); context.SaveChanges(); //todo: not suitable position var currentInfo = InstanceManage.GetInstance <PlayerList>().CurrentInfo; if (currentInfo != null) { if (collection.Locked && currentInfo.Identity.Equals(id)) { currentInfo.IsFavorite = false; } } } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public static void AddMapToCollection(Beatmap beatmap, Collection collection) { using (ApplicationDbContext context = new ApplicationDbContext()) { try { MapInfo map = InnerGetMapFromDb(beatmap.GetIdentity(), context); context.Relations.Add(new CollectionRelation(Guid.NewGuid().ToString(), collection.Id, map.Id)); context.SaveChanges(); //todo: not suitable position var currentInfo = InstanceManage.GetInstance <PlayerList>().CurrentInfo; if (currentInfo != null) { if (collection.Locked && currentInfo.Identity.Equals(beatmap.GetIdentity())) { currentInfo.IsFavorite = true; } } } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public CollectionPage NavigateNewCollection(Collection collectionInfo) { ViewModel.CollectionInfo = collectionInfo; var infos = _appDbOperator.GetMapsFromCollection(collectionInfo); _entries = _beatmapDbOperator.GetBeatmapsByMapInfo(infos, TimeSortMode.AddTime); ViewModel.Beatmaps = new NumberableObservableCollection <BeatmapDataModel>(_entries.ToDataModelList(false)); return(this); }
public void AddCollection(string name, bool locked = false) { var newOne = new Collection(Guid.NewGuid().ToString(), name, locked, 0) { CreateTime = DateTime.Now }; Ctx.Collections.Add(newOne); Ctx.SaveChanges(); }
public void RemoveCollection(Collection collection) { var coll = Ctx.Collections.FirstOrDefault(k => k.Id == collection.Id); if (coll != null) { Ctx.Collections.Remove(coll); } Ctx.Relations.RemoveRange(Ctx.Relations.Where(k => k.CollectionId == collection.Id)); Ctx.SaveChanges(); }
public CollectionPage(MainWindow mainWindow, Collection collectionInfo) { InitializeComponent(); _mainWindow = mainWindow; ViewModel = (CollectionPageViewModel)this.DataContext; ViewModel.CollectionInfo = collectionInfo; var infos = (List <MapInfo>)DbOperate.GetMapsFromCollection(collectionInfo); _entries = BeatmapQuery.GetBeatmapsByIdentifiable(infos, false); ViewModel.Beatmaps = new NumberableObservableCollection <BeatmapDataModel>(_entries.ToDataModels(false)); }
public static void AddCollection(string name, bool locked = false) { using (ApplicationDbContext applicationDbContext = new ApplicationDbContext()) { try { var newOne = new Collection(Guid.NewGuid().ToString(), name, locked, 0) { CreateTime = DateTime.Now }; applicationDbContext.Collections.Add(newOne); applicationDbContext.SaveChanges(); } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public List <MapInfo> GetMapsFromCollection(Collection collection) { var mapRelations = Ctx.Relations.Where(k => k.CollectionId == collection.Id).ToList(); var mapIds = mapRelations.Select(k => k.MapId).ToList(); var maps = Ctx.MapInfos.Where(k => mapIds.Contains(k.Id)).ToList(); return(mapRelations.Join(maps, r => r.MapId, m => m.Id, (r, m) => new MapInfo( m.Id, m.Version, m.FolderName, m.Offset, m.LastPlayTime, m.ExportFile, r.AddTime) ) .ToList()); }
public void RemoveMapFromCollection(MapIdentity id, Collection collection) { MapInfo map = InnerGetMapFromDb(id, Ctx); Ctx.Relations.RemoveRange(Ctx.Relations.Where(k => k.CollectionId == collection.Id && k.MapId == map.Id)); Ctx.SaveChanges(); //todo: not suitable position var currentInfo = Services.Get <PlayerList>().CurrentInfo; if (currentInfo != null) { if (collection.Locked && currentInfo.Identity.Equals(id)) { currentInfo.IsFavorite = false; } } }
public static List <MapInfo> GetMapsFromCollection(Collection collection) { using (ApplicationDbContext context = new ApplicationDbContext()) { try { var mapRelations = context.Relations.Where(k => k.CollectionId == collection.Id).ToList(); var mapIds = mapRelations.Select(k => k.MapId).ToList(); var maps = context.MapInfos.Where(k => mapIds.Contains(k.Id)).ToList(); return((from r in mapRelations join m in maps on r.MapId equals m.Id select new MapInfo(m.Id, m.Version, m.FolderName, m.Offset, m.LastPlayTime, m.ExportFile, r.AddTime)) .ToList()); } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public void AddMapsToCollection(IList <Beatmap> beatmaps, Collection collection) { foreach (var beatmap in beatmaps) { MapInfo map = InnerGetMapFromDb(beatmap.GetIdentity(), Ctx); Ctx.Relations.Add(new CollectionRelation(Guid.NewGuid().ToString(), collection.Id, map.Id)); Ctx.SaveChanges(); //todo: not suitable position var currentInfo = Services.Get <PlayerList>().CurrentInfo; if (currentInfo != null) { if (collection.Locked && currentInfo.Identity.Equals(beatmap.GetIdentity())) { currentInfo.IsFavorite = true; } } } }
public static void RemoveCollection(Collection collection) { using (ApplicationDbContext context = new ApplicationDbContext()) { try { var coll = context.Collections.FirstOrDefault(k => k.Id == collection.Id); if (coll != null) { context.Collections.Remove(coll); } context.Relations.RemoveRange(context.Relations.Where(k => k.CollectionId == collection.Id)); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public void UpdateCollection(Collection collection) { Collection col = Ctx.Collections.FirstOrDefault(k => k.Id == collection.Id); if (col == null) { var newOne = new Collection(Guid.NewGuid().ToString(), collection.Name, false, 0, collection.ImagePath, collection.Description) { CreateTime = DateTime.Now }; Ctx.Collections.Add(newOne); } else { col.Description = collection.Description; col.ImagePath = collection.ImagePath; col.Index = collection.Index; col.Name = collection.Name; } Ctx.SaveChanges(); }
public static void RemoveMapFromCollection(Beatmap beatmap, Collection collection) { RemoveMapFromCollection(beatmap.GetIdentity(), collection); }