static public void RemoveData(FierceStukCloudDbContext context) { context.Songs.RemoveRange(context.Songs.AsEnumerable()); context.Authors.RemoveRange(context.Authors.AsEnumerable()); context.PlayLists.RemoveRange(context.PlayLists.AsEnumerable()); context.SaveChanges(); }
public async Task <IEnumerable <T> > GetAll(T entity) { using (FierceStukCloudDbContext context = _contextFactory.CreateDbContext(null)) { IEnumerable <T> entities; switch (entity.ToString()) { case "FierceStukCloud.Core.Song": //entities = await context.Songs.Include(x => x.DbAlbums).ThenInclude(x => x.Album) // .Include(x => x.DbAuthors).ThenInclude(x => x.Author) // .Include(x => x.DbPlayLists).ThenInclude(x => x.PlayList) // .ToListAsync(); break; case "FierceStukCloud.Core.Album": break; case "FierceStukCloud.Core.PlayList": break; case "FierceStukCloud.Core.LocalFolder": break; } //IEnumerable<T> entities = await context.Set<T>().ToListAsync(); //return entities; return(null); } }
public async Task <T> Get(Guid guid) { using (FierceStukCloudDbContext context = _contextFactory.CreateDbContext(null)) { T entity = await context.Set <T>().FirstOrDefaultAsync(e => e.Id == guid); return(entity); } }
public async Task <T> Create(T entity) { using (FierceStukCloudDbContext context = _contextFactory.CreateDbContext(null)) { EntityEntry <T> createdResult = await context.Set <T>().AddAsync(entity); await context.SaveChangesAsync(); return(createdResult.Entity); } }
public async Task <T> Update(Guid guid, T entity) { using (FierceStukCloudDbContext context = _contextFactory.CreateDbContext(null)) { entity.Id = guid; context.Set <T>().Update(entity); await context.SaveChangesAsync(); return(entity); } }
public async Task <bool> Delete(Guid guid) { using (FierceStukCloudDbContext context = _contextFactory.CreateDbContext(null)) { T entity = await context.Set <T>().FirstOrDefaultAsync(e => e.Id == guid); context.Set <T>().Remove(entity); await context.SaveChangesAsync(); return(true); } }
static public void LoadData(FierceStukCloudDbContext context) { //Songs = context.Songs.Include(x => x.DbAlbums).ThenInclude(x => x.Album) // .Include(x => x.DbAuthors).ThenInclude(x => x.Author) // .Include(x => x.DbPlayLists).ThenInclude(x => x.PlayList) // .ToList(); Songs = context.Songs.ToList(); //Authors = context.Authors.Include(x => x.DbSongs).ThenInclude(x => x.Song) // .Include(x => x.DbAlbums).ThenInclude(x => x.Album) // .ToList(); Authors = context.Authors.ToList(); //PlayLists = context.PlayLists.Include(x => x.DbSongs).ThenInclude(x => x.Song) // .ToList(); PlayLists = context.PlayLists.ToList(); }
static public void CreateData(FierceStukCloudDbContext context) { PlayLists = PlayListsFactory(); Authors = AuthorsFactory(); context.PlayLists.AddRange(PlayLists.AsEnumerable()); context.Authors.AddRange(Authors.AsEnumerable()); context.SaveChanges(); var s1 = new Song() { Id = Guid.NewGuid(), Title = "title0" }; s1.Authors.Add(Authors[0]); //s1.DbAuthors = new List<SongAuthor>() //{ // SongAuthorFactory(s1.Id, Authors[0].Id) //}; var s2 = new Song() { Id = Guid.NewGuid(), Title = "title2" }; s2.Authors.Add(Authors[0]); //s2.DbAuthors = new List<SongAuthor>() //{ // SongAuthorFactory(s2.Id, Authors[0].Id) //}; Songs = new List <Song>(); Songs.Add(s1); Songs.Add(s2); //PlayLists[0].DbSongs.Add(new SongPlayList() { Place = 0, PlayListId = PlayLists[0].Id, SongId = Songs[0].Id }); PlayLists[0].Songs.Add(Songs[0]); context.Songs.Add(s1); context.Songs.Add(s2); context.SaveChanges(); }
public FierceStukCloudHub(FierceStukCloudDbContext context, ILogger <FierceStukCloudHub> logger) { _context = context; _logger = logger; }
public SongsController(FierceStukCloudDbContext context) => _context = context;