コード例 #1
0
        public static void HandleInput(string input)
        {
            if (!ValidateInput(input))
            {
                return;
            }

            input = input.ToLower();

            if (input == "help")
            {
                DisplayHelp();
                return;
            }

            if (int.TryParse(input, out var n))
            {
                AlbumBLL.DisplayAlbumPhotos(n);
                Console.WriteLine("");
                Console.WriteLine("Please enter another command or album Id:");
            }
            else
            {
                Console.WriteLine("Sorry you did not enter a valid command or album Id. Please try again.");
            }
        }
コード例 #2
0
        public void CreateAlbum(AlbumBLL albumBLL, AuthorBLL authorBLL,
                                IEnumerable <GenreBLL> genresBLL, IEnumerable <TrackBLL> tracksBLL)
        {
            Mapper.Initialize(cfg => cfg.CreateMap <AlbumBLL, Album>());
            Album album = Mapper.Map <AlbumBLL, Album>(albumBLL);

            if (genresBLL != null)
            {
                Mapper.Initialize(cfg => cfg.CreateMap <GenreBLL, Genre>());
                album.Genres = Mapper.Map <IEnumerable <GenreBLL>, IEnumerable <Genre> >(genresBLL).ToList();
            }

            if (authorBLL != null)
            {
                Mapper.Initialize(cfg => cfg.CreateMap <AuthorBLL, Author>());
                album.Author = Mapper.Map <AuthorBLL, Author>(authorBLL);
            }
            if (tracksBLL != null)
            {
                Mapper.Initialize(cfg => cfg.CreateMap <TrackBLL, Track>());
                album.Tracks = Mapper.Map <IEnumerable <TrackBLL>, IEnumerable <Track> >(tracksBLL).ToList();
            }
        }
コード例 #3
0
        public ActionResult Upload(IEnumerable <HttpPostedFileBase> upload, string genreName)
        {
            if (upload != null)
            {
                byte[] b = new byte[128];
                string titleFromStream;
                string authorFromStream;
                string albumFromStream;


                foreach (var track in upload)
                {
                    byte[] trackByteArray = new byte[track.ContentLength];
                    track.InputStream.Read(trackByteArray, 0, trackByteArray.Length);

                    track.InputStream.Seek(-128, SeekOrigin.End);

                    track.InputStream.Read(b, 0, 128);
                    bool   isSet = false;
                    String sFlag = System.Text.Encoding.Default.GetString(b, 0, 3);
                    if (sFlag.CompareTo("TAG") == 0)
                    {
                        isSet = true;
                    }
                    if (isSet)
                    {
                        titleFromStream = System.Text.Encoding.Default.GetString(b, 3, 30);
                        titleFromStream = titleFromStream.Replace("\0", string.Empty);
                        var uniqueFilePath = string.Format(@"/files/{0}.mp3", DateTime.Now.Ticks);
                        try
                        {
                            track.SaveAs(Server.MapPath(uniqueFilePath));
                        }
                        catch (Exception ex)
                        {
                            Console.Write(ex.Message);
                            break;
                        }

                        authorFromStream = System.Text.Encoding.Default.GetString(b, 33, 30);
                        authorFromStream = authorFromStream.Replace("\0", string.Empty);

                        albumFromStream = System.Text.Encoding.Default.GetString(b, 63, 30);
                        albumFromStream = albumFromStream.Replace("\0", string.Empty);

                        TrackBLL newTrack = new TrackBLL {
                            TrackName = titleFromStream, TrackLocation = uniqueFilePath
                        };
                        AuthorBLL author = new AuthorBLL {
                            AuthorName = authorFromStream
                        };
                        AlbumBLL album = new AlbumBLL()
                        {
                            AlbumName = albumFromStream
                        };
                        List <GenreBLL> genres = new List <GenreBLL>();
                        GenreBLL        genre  = new GenreBLL()
                        {
                            GenreName = genreName
                        };
                        genres.Add(genre);
                        try
                        {
                            dbMod.CreateTrack(newTrack, author, genres, album);
                            RedirectToAction("Upload");
                        }
                        catch

                        {
                            System.IO.File.Delete(Server.MapPath(uniqueFilePath));
                        }
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public void CreateTrack(TrackBLL trackBLL, AuthorBLL authorBLL, IEnumerable <GenreBLL> genresBLL, AlbumBLL albumBLL)
        {
            Mapper.Initialize(cfg => cfg.CreateMap <TrackBLL, Track>());
            Track track = Mapper.Map <TrackBLL, Track>(trackBLL);

            if (authorBLL != null)
            {
                Mapper.Initialize(cfg => cfg.CreateMap <AuthorBLL, Author>());
                track.Author = Mapper.Map <AuthorBLL, Author>(authorBLL);
            }
            if (genresBLL != null)
            {
                Mapper.Initialize(cfg => cfg.CreateMap <GenreBLL, Genre>());
                track.Genres = Mapper.Map <IEnumerable <GenreBLL>, IEnumerable <Genre> >(genresBLL).ToList();
            }

            if (albumBLL != null)
            {
                Mapper.Initialize(cfg => cfg.CreateMap <AlbumBLL, Album>());
                track.Album = Mapper.Map <AlbumBLL, Album>(albumBLL);
            }
            TracksDB.Tracks.Create(track);
        }
コード例 #5
0
 public AlbumController()
 {
     albumBLL = new AlbumBLL();
 }