Example #1
0
        public ActionResult EditSong(CreateSongVM model, List<String> AssociatedReports)
        {
            var db = new ChwinockEntities();

            var targetSong = db.Songs.Single(r => r.SongID == model.Song.SongID);

            targetSong.Artist = model.Song.Artist;
            targetSong.Name = model.Song.Name;
            targetSong.Url = model.Song.Url;

            // Remove associated reports
            List<Report> reportsToRemove = new List<Report>();
            foreach (var r in targetSong.Reports)
            {
                reportsToRemove.Add(r);
            }
            foreach (var r in reportsToRemove)
            {
                targetSong.Reports.Remove(r);
            }

            if (AssociatedReports != null)
            {
                // Add new ones
                foreach (var r in AssociatedReports)
                {
                    var id = Guid.Parse(r);
                    targetSong.Reports.Add(db.Reports.Single(x => x.ReportID == id));
                }
            }

            db.SaveChanges();

            return RedirectToAction("Manage");
        }
Example #2
0
        public ActionResult CreateSong(CreateSongVM model, List<String> AssociatedReports)
        {
            var db = new ChwinockEntities();

            var newSong = new Song();
            newSong.SongID = Guid.NewGuid();
            newSong.Artist = model.Song.Artist;
            newSong.Name = model.Song.Name;
            newSong.Url = model.Song.Url;

            if (AssociatedReports != null)
            {
                foreach (var r in AssociatedReports)
                {
                    var id = Guid.Parse(r);
                    newSong.Reports.Add(db.Reports.Single(x => x.ReportID == id));
                }
            }

            db.Songs.AddObject(newSong);

            db.SaveChanges();

            return RedirectToAction("Manage");
        }