public JsonResult SaveSong(Song song) { int compID = Convert.ToInt32(System.Web.HttpContext.Current.Session["CompositionID"] as string); using (var db = new CompositionContext()) { Composition c; if (compID == 0) { c = new Composition(); } else { c = db.Compositions.Find(compID); } song.getMetaData(c); c.Content = song.getContent(); c.TabContent = song.getTabContent(); c.User = User.Identity.Name; if (compID == 0) { db.Compositions.Add(c); } db.SaveChanges(); song.setMetaData(c); song.SongId = c.CompositionID; } foreach (var p in song.Pages) { while (p.Measures.Count() < 28) { p.Measures.Add(new Measure()); } } return(Json(song, JsonRequestBehavior.AllowGet)); }