public List <Entity.Playlist> ShowMy(string performer)
        {
            List <Entity.Playlist> result = new List <Entity.Playlist>();

            FileStream   fs = new FileStream(this.filePath, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);

            try
            {
                while (!sr.EndOfStream)
                {
                    Entity.Playlist playlist = new Entity.Playlist();
                    playlist.Id           = Convert.ToInt32(sr.ReadLine());
                    playlist.ParentUserId = Convert.ToInt32(sr.ReadLine());
                    playlist.Name         = sr.ReadLine();
                    playlist.Description  = sr.ReadLine();
                    playlist.Songs        = sr.ReadLine();
                    playlist.IsPublic     = Convert.ToBoolean(sr.ReadLine());

                    if (playlist.performer == performer)
                    {
                        result.Add(playlist);
                    }
                }
            }
            finally
            {
                sr.Close();
                fs.Close();
            }

            return(result);
        }
        private int GetNextId()
        {
            FileStream   fs = new FileStream(this.filePath, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);

            int id = 1;

            try
            {
                while (!sr.EndOfStream)
                {
                    Entity.Playlist playlist = new Entity.Playlist();
                    playlist.Id           = Convert.ToInt32(sr.ReadLine());
                    playlist.ParentUserId = Convert.ToInt32(sr.ReadLine());
                    playlist.Name         = sr.ReadLine();
                    playlist.Description  = sr.ReadLine();

                    playlist.Songs    = sr.ReadLine();
                    playlist.IsPublic = Convert.ToBoolean(sr.ReadLine());

                    if (id <= playlist.Id)
                    {
                        id = playlist.Id + 1;
                    }
                }
            }
            finally
            {
                sr.Close();
                fs.Close();
            }

            return(id);
        }
        public Entity.Playlist GetById(int Id)
        {
            FileStream   fs = new FileStream(this.filePath, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);

            try
            {
                while (!sr.EndOfStream)
                {
                    Entity.Playlist playlist = new Entity.Playlist();
                    playlist.Id           = Convert.ToInt32(sr.ReadLine());
                    playlist.ParentUserId = Convert.ToInt32(sr.ReadLine());
                    playlist.Name         = sr.ReadLine();
                    playlist.Description  = sr.ReadLine();
                    playlist.Songs        = sr.ReadLine();
                    playlist.IsPublic     = Convert.ToBoolean(sr.ReadLine());

                    if (playlist.Id == Id)
                    {
                        return(playlist);
                    }
                }
            }
            finally
            {
                sr.Close();
                fs.Close();
            }

            return(null);
        }
 public void Save(Entity.Playlist item)
 {
     if (item.Id > 0)
     {
         Update(item);
     }
     else
     {
         Insert(item);
     }
 }
        private void Update(Entity.Playlist item)
        {
            string tempFilePath = "temp." + filePath;

            FileStream   ifs = new FileStream(filePath, FileMode.OpenOrCreate);
            StreamReader sr  = new StreamReader(ifs);

            FileStream   ofs = new FileStream(tempFilePath, FileMode.OpenOrCreate);
            StreamWriter sw  = new StreamWriter(ofs);

            try
            {
                while (!sr.EndOfStream)
                {
                    Entity.Playlist playlist = new Entity.Playlist();
                    playlist.Id           = Convert.ToInt32(sr.ReadLine());
                    playlist.ParentUserId = Convert.ToInt32(sr.ReadLine());
                    playlist.Name         = sr.ReadLine();
                    playlist.Description  = sr.ReadLine();
                    playlist.Songs        = sr.ReadLine();
                    playlist.IsPublic     = Convert.ToBoolean(sr.ReadLine());

                    if (playlist.Id != item.Id)
                    {
                        sw.WriteLine(playlist.Id);
                        sw.WriteLine(playlist.ParentUserId);
                        sw.WriteLine(playlist.Name);
                        sw.WriteLine(playlist.Description);
                        sw.WriteLine(playlist.Songs);
                        sw.WriteLine(playlist.IsPublic);
                    }
                    else
                    {
                        sw.WriteLine(item.Id);
                        sw.WriteLine(item.ParentUserId);
                        sw.WriteLine(item.Name);
                        sw.WriteLine(item.Description);
                        sw.WriteLine(item.Songs);
                        sw.WriteLine(item.IsPublic);
                    }
                }
            }
            finally
            {
                sw.Close();
                ofs.Close();
                sr.Close();
                ifs.Close();
            }

            File.Delete(filePath);
            File.Move(tempFilePath, filePath);
        }
Esempio n. 6
0
        private void Delete()
        {
            PlaylistRepository playlistRepository = new PlaylistRepository("playlist.txt");

            Console.Clear();

            Console.WriteLine("Delete Playlist:");
            Console.Write("Playlist Id: ");
            int playlistId = Convert.ToInt32(Console.ReadLine());

            Entity.Playlist playlist = playlistRepository.GetById(playlistId);
            if (playlist == null)
            {
                Console.WriteLine("Plylist not found!");
            }
            else
            {
                playlistRepository.Delete(playlist);
                Console.WriteLine("Playlist deleted successfully.");
            }
            Console.ReadKey(true);
        }
        private void Insert(Entity.Playlist item)
        {
            item.Id = GetNextId();

            FileStream   fs = new FileStream(filePath, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);

            try
            {
                sw.WriteLine(item.Id);
                sw.WriteLine(item.ParentUserId);
                sw.WriteLine(item.Name);
                sw.WriteLine(item.Description);
                sw.WriteLine(item.Songs);
                sw.WriteLine(item.IsPublic);
            }
            finally
            {
                sw.Close();
                fs.Close();
            }
        }
Esempio n. 8
0
        private void Add()
        {
            Console.Clear();

            Entity.Playlist playlist = new Entity.Playlist();
            playlist.ParentUserId = AuthenticationService.LoggedUser.Id;
            PlaylistRepository playlistRepository = new PlaylistRepository("playlist.txt");

            Console.WriteLine("Add new Playlist:");
            Console.Write("Name: ");
            playlist.Name = Console.ReadLine();
            Console.Write("Description: ");
            playlist.Description = Console.ReadLine();
            Console.Write("Add Song by Song ID :");
            int songId = Convert.ToInt32(Console.ReadLine());

            SongsRepository songsRepository = new SongsRepository("songs.txt");

            Entity.Song song = songsRepository.GetById(songId);
            if (song == null)
            {
                Console.Clear();
                Console.WriteLine("Song not found.");
                Console.ReadKey(true);
                return;
            }
            playlist.Songs = song.Title + ", " + song.ArtistName + ", " + song.Year + " y.";

            Console.Write("IsPublic: ");
            playlist.IsPublic = Convert.ToBoolean(Console.ReadLine());

            playlistRepository.Save(playlist);

            Console.WriteLine("Playlist saved successfully.");
            Console.ReadKey(true);

            Console.WriteLine("-------------------------------------------");
        }
Esempio n. 9
0
        private void View()
        {
            Console.Clear();

            Console.Write("Playlist ID: ");
            int playlistId = Convert.ToInt32(Console.ReadLine());
            PlaylistRepository playlistRepository = new PlaylistRepository("playlist.txt");

            Entity.Playlist playlist = playlistRepository.GetById(playlistId);
            int             lognat   = AuthenticationService.LoggedUser.Id;


            if (playlist == null)
            {
                Console.Clear();
                Console.WriteLine("Playlist not found.");
                Console.ReadKey(true);
                return;
            }
            if (playlist.IsPublic == true || playlist.ParentUserId == lognat)
            {
                Console.WriteLine("ID:" + playlist.Id);
                Console.WriteLine("Name :" + playlist.Name);
                Console.WriteLine("Description :" + playlist.Description);
                Console.WriteLine("Songs :" + playlist.Songs);
                Console.WriteLine("IsPublic :" + playlist.IsPublic);

                Console.WriteLine("------------------------------------");
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("This playlist is not public!");
            }

            Console.ReadKey(true);
        }
Esempio n. 10
0
        private void Update()
        {
            Console.Clear();

            Console.Write("Playlist ID: ");
            int playlistId = Convert.ToInt32(Console.ReadLine());

            PlaylistRepository playlistRepository = new PlaylistRepository("playlist.txt");

            Entity.Playlist playlist = playlistRepository.GetById(playlistId);


            if (playlist == null)
            {
                Console.Clear();
                Console.WriteLine("Playlist not found.");
                Console.ReadKey(true);
                return;
            }

            Console.WriteLine("Editing Playlist (" + playlist.Name + ")");
            Console.WriteLine("ID:" + playlist.Id);

            Console.WriteLine("Name :" + playlist.Name);
            Console.Write("New Name:");
            string Name = Console.ReadLine();

            Console.WriteLine("Description :" + playlist.Description);
            Console.Write("New Description :");
            string Description = Console.ReadLine();

            Console.WriteLine("IsPublic :" + playlist.IsPublic);
            Console.Write("New IsPublic :");
            string IsPublic = Console.ReadLine();


            Console.WriteLine("Add or Remove songs ?");
            string answer = Console.ReadLine();

            if (answer.ToLower() == "add")
            {
                Console.Write("Add Song by Song ID :");
                int songId = Convert.ToInt32(Console.ReadLine());

                SongsRepository songsRepository = new SongsRepository("songs.txt");
                Entity.Song     song            = songsRepository.GetById(songId);
                if (song == null)
                {
                    Console.Clear();
                    Console.WriteLine("Song not found.");
                    Console.ReadKey(true);
                    return;
                }
                playlist.Songs += "  /  " + song.Title + ", " + song.ArtistName + ", " + song.Year + " y.";
                Console.WriteLine("You add the song : " + song.Title + ", " + song.ArtistName + ", " + song.Year + " y. to your playlist!");
            }
            else if (answer.ToLower() == "remove")
            {
                Console.Write("Remove Song by Song Index in Playlist :");
                int songId = Convert.ToInt32(Console.ReadLine());
                //playlist.Songs;
            }


            if (!string.IsNullOrEmpty(Name))
            {
                playlist.Name = Name;
            }
            if (!string.IsNullOrEmpty(Description))
            {
                playlist.Description = Description;
            }

            playlistRepository.Save(playlist);

            Console.WriteLine("Playlist saved successfully.");
            Console.ReadKey(true);
        }