Esempio n. 1
0
        public int InsertNewBand(Band band)
        {
            _context.Bands.Add(band);
            var result = _context.SaveChanges();

            return(result);
        }
Esempio n. 2
0
        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());
            }
        }
Esempio n. 3
0
        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"));
        }
Esempio n. 5
0
        public SongMember MakeJoin(Member member, Song song)
        {
            var songMember = new SongMember
            {
                SongId   = song.Id,
                MemberId = member.Id
            };

            _context.Add(songMember);
            _context.SaveChanges();
            return(songMember);
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
 public ActionResult Create(Band band)
 {
     if (Request.HttpMethod == "POST")
     {
         db.Bands.Add(band);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View());
     }
 }
Esempio n. 8
0
 public ActionResult Create(Band band)
 {
     using (var db = new BandContext())
     {
         db.Bands.Add(band);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 9
0
 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();
     }
 }
Esempio n. 10
0
        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);
            }
        }
Esempio n. 11
0
        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"));
        }