public ActionResult Details(int Id) { TrackBLL dbTrack = dbGet.GetTrack(Id); Mapper.Initialize(cfg => cfg.CreateMap <TrackBLL, TrackViewModel>()); TrackViewModel track = Mapper.Map <TrackBLL, TrackViewModel>(dbTrack); IEnumerable <TrackRateBLL> trackRates = dbGet.GetTrackRate(dbTrack.TrackName); ViewBag.TrackRates = trackRates; if (dbTrack.AuthorID != null) { AuthorBLL authorBLL = dbGet.GetAuthor((int)dbTrack.AuthorID); Mapper.Initialize(cfg => cfg.CreateMap <AuthorBLL, AuthorViewModel>()); AuthorViewModel author = Mapper.Map <AuthorBLL, AuthorViewModel> (authorBLL); ViewBag.Author = author; return(PartialView(track)); } else { return(PartialView("Details2", track)); } }
public void UpdateTrack(TrackBLL trackBLL, AuthorBLL authorBLL, IEnumerable <GenreBLL> genresBLL, AlbumBLL albumBLL) { Mapper.Initialize(cfg => cfg.CreateMap <TrackBLL, Track>()); Track track = Mapper.Map <TrackBLL, Track>(trackBLL); 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.Update(track); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(404)); } TrackBLL dbTrack = dbGet.GetTrack((int)id); { if (dbTrack == null) { return(HttpNotFound()); } } Mapper.Initialize(cfg => cfg.CreateMap <TrackBLL, TrackViewModel>()); TrackViewModel track = Mapper.Map <TrackBLL, TrackViewModel>(dbTrack); return(PartialView(track)); }
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")); }