Exemple #1
0
        public async Task <IActionResult> Create([Bind("Id,Title,Artist,ReleaseDate,Genre,ImagePath,Price")] Song song, IFormFile file)
        {
            long size = file.Length;
            var  path = @"\Content\Images\NoAlbumImage.png";

            if (size > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                path = _env.WebRootPath + "\\uploads\\albums\\" + fileName;

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }

                //update song path
                song.ImagePath = "uploads/albums/" + fileName;
            }


            if (ModelState.IsValid)
            {
                _songsRepo.AddSong(song);
                _songsRepo.Save();
                return(RedirectToAction(nameof(Index)));
            }
            return(View(song));
        }
        private void Add()
        {
            Console.Clear();

            Song song = new Song();

            Console.WriteLine("\tAdd new Song : ");
            Console.Write("\tTitle : ");
            string title = Console.ReadLine();

            IsEmptyValidation(ref title);
            song.Title = title;

            Console.Write("\tArtist Name : ");
            string artistName = Console.ReadLine();

            IsEmptyValidation(ref artistName);
            song.ArtistName = artistName;

            Console.Write("\tYear : ");
            int year = Convert.ToInt32(Console.ReadLine());

            IsEmptyValidation(ref year);
            song.Year = year;

            _songsRepository.Save(song);

            Console.WriteLine("\tSong saved successfully.");
            Console.ReadKey(true);
        }
        private void Add()
        {
            Console.Clear();

            Entity.Song song = new Entity.Song();
            song.ParentUserId = AuthenticationService.LoggedUser.Id;

            Console.WriteLine("Add new Song:");
            Console.Write("Title: ");
            song.Title = Console.ReadLine();
            Console.Write("Atist Name: ");
            song.ArtistName = Console.ReadLine();
            Console.Write("Year :");
            song.Year = Console.ReadLine();


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

            songRepository.Save(song);

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

            Console.WriteLine("-------------------------------------------");
        }
        private void Update()
        {
            Console.Clear();

            Console.Write("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;
            }

            Console.WriteLine("Editing Song (" + song.Title + ")");
            Console.WriteLine("ID:" + song.Id);

            Console.WriteLine("Title :" + song.Title);
            Console.Write("New Title:");
            string Title = Console.ReadLine();

            Console.WriteLine("Artist Name :" + song.ArtistName);
            Console.Write("New Artist Name :");
            string ArtistName = Console.ReadLine();

            Console.WriteLine("Year :" + song.Year);
            Console.Write("New Year :");
            string Year = Console.ReadLine();


            if (!string.IsNullOrEmpty(Title))
            {
                song.Title = Title;
            }
            if (!string.IsNullOrEmpty(ArtistName))
            {
                song.ArtistName = ArtistName;
            }
            if (!string.IsNullOrEmpty(Year))
            {
                song.Year = Year;
            }

            songsRepository.Save(song);

            Console.WriteLine("Song saved successfully.");
            Console.ReadKey(true);
        }
Exemple #5
0
        public void CreateSong()
        {
            Console.Clear();
CreateSong:
            Song newSong = new Song();

            Console.Write("Enter new song's title: ");
            string inputSongTitle = Console.ReadLine();

            if (inputSongTitle.Length == 0)
            {
                Console.WriteLine("Song title cannot be empty. Try again!!");
                Console.ReadKey(true);
                goto CreateSong;
            }
            newSong.Title = inputSongTitle;
            Console.Write("Enter song release year: ");
            short inputYear;
            bool  isShort = short.TryParse(Console.ReadLine(), out inputYear);

            while (isShort == false)
            {
                Console.WriteLine("Year should be a digit. Try again!!");
                Console.Write("Enter song release year: ");
                isShort = short.TryParse(Console.ReadLine(), out inputYear);
            }

            if ((short)DateTime.Now.Year < inputYear || inputYear < 1850)
            {
                Console.WriteLine("Input year cannot be before 1500 or after the current year. Try again!!");
                Console.Write("Enter song release year: ");
                isShort = short.TryParse(Console.ReadLine(), out inputYear);
            }

            newSong.Year = inputYear;
            SongsRepository songsRepo = new SongsRepository(Constants.SongsPath);

            songsRepo.Save(newSong);
            Console.WriteLine("Song saved successfully!!");
            Console.ReadKey(true);
        }
        public void AddSong()
        {
            string inputSongTitle;
            bool   isEmptyName = false;

            do
            {
                Console.Clear();
                Console.Write("Enter new song name: ");
                inputSongTitle = Console.ReadLine();
                isEmptyName    = (String.IsNullOrWhiteSpace(inputSongTitle));
                if (isEmptyName == true)
                {
                    Console.WriteLine("Song title cannot be empty. Try again!!");
                    Console.ReadKey(true);
                }
            }while (isEmptyName == true);

            short inputSongReleaseYear;
            bool  isShortYear;
            bool  isBeforeCurrentYear = false;

            do
            {
                Console.Write("Enter song's release year: ");
                isShortYear = short.TryParse(Console.ReadLine(), out inputSongReleaseYear);
                if (DateTime.Now.Year >= inputSongReleaseYear)
                {
                    isBeforeCurrentYear = true;
                }
                if (isShortYear == false)
                {
                    Console.WriteLine("Year can only be an integer number. Try again!!");
                    Console.ReadKey(true);
                }

                if (isBeforeCurrentYear == false)
                {
                    Console.WriteLine("Year should not be after the current year.");
                }
            } while (isShortYear == false || isBeforeCurrentYear == false);

            Song newSong = new Song();

            newSong.Title = inputSongTitle;
            newSong.Year  = inputSongReleaseYear;
            SongsRepository songsRepo = new SongsRepository(Constants.SongsPath);

            if (songsRepo.EntityExists(s => s.Title == inputSongTitle && s.Year == inputSongReleaseYear))
            {
                Console.WriteLine("The song already exists in the database!");
                Console.ReadKey(true);
            }
            int songId = songsRepo.Save(newSong);
            ArtistsRepository artistsRepo = new ArtistsRepository(Constants.ArtistsPath);
            List <Artist>     artists     = artistsRepo.GetAll();

            Console.Clear();
            int artistId;

            if (artists.Count == 0)
            {
                artistId = ArtistsView.AddArtist();
            }
            else
            {
                foreach (Artist artistEntity in artists)
                {
                    Console.WriteLine("************************************");
                    Console.WriteLine("Id: {0}", artistEntity.Id);
                    Console.WriteLine("Artist name: {0}", artistEntity.Name);
                    Console.WriteLine("************************************");
                }

                Console.WriteLine();
EnterArtistId:
                Console.Write("Enter new song's artist id (type \"0\" if not in the list): ");
                bool isInt = int.TryParse(Console.ReadLine(), out artistId);
                while (isInt == false)
                {
                    Console.WriteLine("IDs can only be integer numbers. Try Again!!");
                    Console.ReadKey(true);
                    goto EnterArtistId;
                }

                if (artistId == 0)
                {
                    artistId = ArtistsView.AddArtist();
                }
            }
            SongsArtists songArtistEntity = new SongsArtists();

            songArtistEntity.SongId   = songId;
            songArtistEntity.ArtistId = artistId;
            SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath);

            songsArtistsRepo.Save(songArtistEntity);
            Console.WriteLine("Song saved successfully!");
            Console.ReadKey(true);
        }
        public void EditSong()
        {
            bool hasSongs = ViewSongs();

            if (hasSongs == false)
            {
                return;
            }
            Console.WriteLine();
            int  editId;
            bool isIntId;

            do
            {
                Console.Write("Enter song id to edit: ");
                isIntId = int.TryParse(Console.ReadLine(), out editId);
                if (isIntId == false)
                {
                    Console.WriteLine("IDs can only be integer numbers. Try again!!");
                    Console.ReadKey(true);
                }
            }while (isIntId == false);

            SongsRepository songRepo = new SongsRepository(Constants.SongsPath);
            Song            song     = songRepo.GetAll(s => s.Id == editId).FirstOrDefault();

            if (song == null)
            {
                Console.WriteLine("No song with that Id exists!");
                Console.ReadKey(true);
                return;
            }
            Console.Clear();
            Console.WriteLine("Old song title: {0}", song.Title);
            string newSongTitle;
            bool   isEmptyName;

            do
            {
                Console.Write("New song title: ");
                newSongTitle = Console.ReadLine();
                isEmptyName  = string.IsNullOrWhiteSpace(newSongTitle);
                if (isEmptyName)
                {
                    Console.WriteLine("Song name cannot be empty. Try again!!");
                    Console.ReadKey();
                }
            } while (isEmptyName == true);

            song.Title = newSongTitle;

            short newSongReleaseYear;
            bool  isIntYear           = false;
            bool  isCurrentOrPastYear = false;

            Console.WriteLine("Old song release year: {0}", song.Year);
            do
            {
                Console.Write("New song release year: ");
                isIntYear = short.TryParse(Console.ReadLine(), out newSongReleaseYear);
                if (isIntYear == false)
                {
                    Console.WriteLine("Song release year can only be an integer number. Try Again!!");
                    Console.ReadKey();
                }

                if (DateTime.Now.Year >= newSongReleaseYear)
                {
                    isCurrentOrPastYear = true;
                }

                if (isCurrentOrPastYear == false)
                {
                    Console.WriteLine("Song release year cannot be after the current year. Try again!!");
                    Console.ReadKey(true);
                }
            } while (isIntYear == false || isCurrentOrPastYear == false);

            song.Year = newSongReleaseYear;
            songRepo.Save(song);
            Console.WriteLine("Song edited successfully!");
            Console.ReadKey(true);
        }