public ActionResult Edit(Song song, HttpPostedFileBase image, HttpPostedFileBase MP3) { if (ModelState.IsValid) { if (image != null) { song.ImageMimeType = image.ContentType; song.ImageData = new byte[image.ContentLength]; image.InputStream.Read(song.ImageData, 0, image.ContentLength); } if (MP3 != null) { song.MP3MimeType = MP3.ContentType; song.MP3Data = new byte[MP3.ContentLength]; MP3.InputStream.Read(song.MP3Data, 0, MP3.ContentLength); } repository.SaveSong(song); TempData["message"] = string.Format("{0} has been saved", song.Title); return RedirectToAction("Index"); } else { // there is something wrong with values return View(song); } }
public void SaveSong(Song song) { if (song.SongID == 0) { context.Songs.Add(song); } else { Song dbEntry = context.Songs.Find(song.SongID); if (dbEntry != null) { dbEntry.Title = song.Title; dbEntry.Artist = song.Artist; dbEntry.Album = song.Album; dbEntry.Year = song.Year; dbEntry.Description = song.Description; dbEntry.Track = song.Track; dbEntry.Genre = song.Genre; dbEntry.ImageData = song.ImageData; dbEntry.ImageMimeType = song.ImageMimeType; dbEntry.MP3Data = song.MP3Data; dbEntry.MP3MimeType = song.MP3MimeType; } } context.SaveChanges(); }
public void AddSong(Song song) { CartLine line = lineCollection .Where(s => s.Song.SongID == song.SongID) .FirstOrDefault(); if (line == null) { lineCollection.Add(new CartLine { Song = song }); } }
public PartialViewResult ArtistSummary(Song song) { return PartialView(song); }
public void RemoveLine(Song song) { lineCollection.RemoveAll(l => l.Song.SongID == song.SongID); }