public int InsertNewBand(Band band) { _context.Bands.Add(band); var result = _context.SaveChanges(); return(result); }
public IActionResult Update(int id, [FromBody] Band item) { if (item == null || item.Id != id) { return(BadRequest()); } var band = _context.Band.FirstOrDefault(t => t.Id == id); if (band == null) { return(NotFound()); } try { band.BandName = item.BandName; band.Style = item.Style; band.FormationYear = item.FormationYear; band.Members = item.Members; _context.Band.Update(band); _context.SaveChanges(); return(new NoContentResult()); } catch (Exception e) { Console.WriteLine("Something happenned: {0}", e); return(BadRequest()); } }
public int Add(Band band) { _context.Bands.Add(band); int id = _context.SaveChanges(); return(id); }
public ActionResult Create(Band band) { db.Bands.Add(band); db.SaveChanges(); return(RedirectToAction("Index")); }
public SongMember MakeJoin(Member member, Song song) { var songMember = new SongMember { SongId = song.Id, MemberId = member.Id }; _context.Add(songMember); _context.SaveChanges(); return(songMember); }
public ActionResult Create([Bind(Include = "Id,AlbumTitle,Released,TrackList,Genre,BandId")] Album album) { if (ModelState.IsValid) { db.Albums.Add(album); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BandId = new SelectList(db.Bands, "Id", "BandName", album.BandId); return(View(album)); }
public ActionResult Create(Band band) { if (Request.HttpMethod == "POST") { db.Bands.Add(band); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(View()); } }
public ActionResult Create(Band band) { using (var db = new BandContext()) { db.Bands.Add(band); db.SaveChanges(); } return(RedirectToAction("Index")); }
public BandController(BandContext context) { _context = context; if (_context.Band.Count() == 0) { _context.Band.Add(new Band { BandName = "ROTNS", FormationYear = 2008, Members = 5, Style = "HxC" }); _context.SaveChanges(); } }
public void TestMethod1() { using (var context = new BandContext()) { //context.Database.EnsureDeleted(); //context.Database.EnsureCreated(); var band = new Band(); context.Bands.Add(band); Debug.WriteLine($"Before save: {band.Id}"); context.SaveChanges(); Debug.WriteLine($"After save: {band.Id}"); Assert.AreNotEqual(0, band.Id); } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Band band = db.Bands.Find(id); if (band == null) { return(HttpNotFound()); } db.Bands.Remove(band); db.SaveChanges(); return(RedirectToAction("Index")); }