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 CollectionPage(MainWindow mainWindow, Collection collectionInfo) { InitializeComponent(); _mainWindow = mainWindow; ViewModel = (CollectionPageViewModel)this.DataContext; ViewModel.CollectionInfo = collectionInfo; var infos = (List <MapInfo>)DbOperate.GetMapsFromCollection(collectionInfo); _entries = infos.ToBeatmapEntries(InstanceManage.GetInstance <OsuDbInst>().Beatmaps, false); ViewModel.Beatmaps = new NumberableObservableCollection <BeatmapDataModel>(_entries.ToDataModels(false)); }
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(); } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
public static void AddMapToCollection(BeatmapEntry entry, Collection collection) { using (ApplicationDbContext context = new ApplicationDbContext()) { try { MapInfo map = InnerGetMapFromDb(entry.GetIdentity(), context); context.Relations.Add(new CollectionRelation(Guid.NewGuid().ToString(), collection.Id, map.Id)); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(@"Failed: " + ex); throw; } } }
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 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 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 static void RemoveMapFromCollection(BeatmapEntry entry, Collection collection) { RemoveMapFromCollection(entry.GetIdentity(), collection); }