public ActionResult AddAlbumReview([Bind(Include = "RatingID,RatingNumber,Review")] MusicRating AlbumRating, int AlbumID) { if (ModelState.IsValid) { AppUser userLoggedIn = db.Users.Find(User.Identity.GetUserId()); AlbumRating.ReviewedAlbum = db.Albums.Find(AlbumID); // check to see that there are no duplicates first of all foreach (var item in userLoggedIn.Ratings) { if (item.ReviewedAlbum != null && item.ReviewedAlbum.AlbumID == AlbumID) { ViewBag.ErrorMessage = "You can only review an album once."; return(View("AddAlbumReview")); } } userLoggedIn.Ratings.Add(AlbumRating); db.Ratings.Add(AlbumRating); db.SaveChanges(); return(RedirectToAction("Details", "Albums", new { id = AlbumRating.ReviewedAlbum.AlbumID })); } else { ViewBag.AlbumID = AlbumID; return(View(AlbumRating)); } }
public ActionResult AddSongReview([Bind(Include = "RatingID,RatingNumber,Review")] MusicRating SongRating, int SongID) { if (ModelState.IsValid) { AppUser userLoggedIn = db.Users.Find(User.Identity.GetUserId()); SongRating.ReviewedSong = db.Songs.Find(SongID); // check to see that there are no duplicates first of all foreach (var item in userLoggedIn.Ratings) { if (item.ReviewedSong != null && item.ReviewedSong.SongID == SongID) { ViewBag.ErrorMessage = "You can only review a song once."; return(View("AddSongReview")); } } userLoggedIn.Ratings.Add(SongRating); db.Ratings.Add(SongRating); db.SaveChanges(); //SongRating.ReviewedSong.AverageSongRating = Decimal.Round(GetSongAverage(SongID),1); //db.SaveChanges(); return(RedirectToAction("Details", "Songs", new { id = SongRating.ReviewedSong.SongID })); } else { ViewBag.SongID = SongID; return(View(SongRating)); } }
public ActionResult DeleteConfirmed(int id) { MusicRating musicRating = db.Ratings.Find(id); musicRating.Review = null; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "MusicRatingID,RatingNumber,Review")] MusicRating musicRating) { if (ModelState.IsValid) { db.Entry(musicRating).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(musicRating)); }
public ActionResult Create([Bind(Include = "MusicRatingID,RatingNumber,Review")] MusicRating musicRating) { if (ModelState.IsValid) { db.Ratings.Add(musicRating); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(musicRating)); }
// GET: Ratings/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MusicRating musicRating = db.Ratings.Find(id); if (musicRating == null) { return(HttpNotFound()); } return(View(musicRating)); }
// GET: Ratings/AddArtistReview public ActionResult AddArtistReview(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MusicRating ArtistRating = new MusicRating(); ArtistRating.ReviewedArtist = db.Artists.Find(id); ViewBag.ArtistID = id; return(View(ArtistRating)); }
// GET: Ratings/AddSongReview public ActionResult AddSongReview(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MusicRating SongRating = new MusicRating(); SongRating.ReviewedSong = db.Songs.Find(id); ViewBag.SongID = id; return(View(SongRating)); }