예제 #1
0
 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();
 }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
 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();
 }
예제 #8
0
        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();
        }
예제 #9
0
 public FierceStukCloudHub(FierceStukCloudDbContext context, ILogger <FierceStukCloudHub> logger)
 {
     _context = context;
     _logger  = logger;
 }
예제 #10
0
 public SongsController(FierceStukCloudDbContext context)
 => _context = context;