Exemplo n.º 1
0
 public static List<Song> Get()
 {
     using (var context = new RadioStationContext())
     {
         return context.Songs.ToList();
     }
 }
Exemplo n.º 2
0
        public void AddSong(string fullPath)
        {
            if (!File.Exists(fullPath))
                throw new FileNotFoundException("Cannot find file.", fullPath);

            var fileName = Path.GetFileName(fullPath);

            using (var context = new RadioStationContext())
            {
                if (context.Songs.Any(s => s.Name == fileName))
                    throw new InvalidOperationException("File has already been added");

                var newSong = new Song
                {
                    Name = fileName,
                    Folder = Path.GetDirectoryName(fullPath),
                    Extension = Path.GetExtension(fullPath)
                };
                context.Songs.Add(newSong);
                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
 public RadioStationRepo()
 {
     db = new RadioStationContext();
 }