Example #1
0
 public IActionResult Create(Band band)
 {
     using (var db = new BandRegisterDbContext())
     {
         db.Bands.Add(band);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
Example #2
0
 public IActionResult Delete(Band band)
 {
     using (var db = new BandRegisterDbContext())
     {
         db.Bands.Remove(band);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Example #3
0
 public IActionResult Edit(Band band)
 {
     using (var db = new BandRegisterDbContext())
     {
         var bandToEdit = db.Bands.FirstOrDefault(t => t.Id == band.Id);
         bandToEdit.Name       = band.Name;
         bandToEdit.Members    = band.Members;
         bandToEdit.Honorarium = band.Honorarium;
         bandToEdit.Genre      = band.Genre;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Example #4
0
 public IActionResult Create(Band band)
 {
     if (string.IsNullOrEmpty(band.Name) || string.IsNullOrEmpty(band.Members))
     {
         return(RedirectToAction("Index"));
     }
     using (BandRegisterDbContext db = new BandRegisterDbContext())
     {
         db.Bands.Add(band);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
 public IActionResult Delete(Band band)
 {
     using (var db = new BandRegisterDbContext())
     {
         var bandToDelete = db.Bands.FirstOrDefault(t => t.Id == band.Id);
         if (bandToDelete == null)
         {
             RedirectToAction("Index");
         }
         db.Bands.Remove(bandToDelete);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Example #6
0
        public IActionResult Edit(Band band)
        {
            if (ModelState.IsValid == false)
            {
                return(RedirectToAction("Index"));
            }

            using (var db = new BandRegisterDbContext())
            {
                db.Bands.Update(band);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Example #7
0
        public IActionResult Create(string name, string members, double honorarium, string genre)
        {
            Band newBand = new Band
            {
                Name       = name,
                Members    = members,
                Honorarium = honorarium,
                Genre      = genre
            };

            using (var db = new BandRegisterDbContext())
            {
                db.Add(newBand);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Example #8
0
 public IActionResult Edit(Band band)
 {
     if (!ModelState.IsValid)
     {
         return(RedirectToAction("Index"));
     }
     using (var db = new BandRegisterDbContext())
     {
         var taskToEdit = db.Bands.FirstOrDefault(t => t.Id == band.Id);
         taskToEdit.Name       = band.Name;
         taskToEdit.Members    = band.Members;
         taskToEdit.Honorarium = band.Honorarium;
         taskToEdit.Genre      = band.Genre;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
Example #9
0
        public IActionResult Create(Band band)
        {
            Band newBand = new Band
            {
                Name       = band.Name,
                Members    = band.Members,
                Honorarium = band.Honorarium,
                Genre      = band.Genre
            };

            using (var db = new BandRegisterDbContext())
            {
                db.Bands.Add(newBand);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
        public IActionResult Create(Band band)
        {
            using (var db = new BandRegisterDbContext())
            {
                if (band != null)
                {
                    db.Bands.Add(band);
                    db.SaveChanges();
                }
                else
                {
                    return(View());
                }

                return(RedirectToAction("Index"));
            }
            return(null);
        }
Example #11
0
        public IActionResult Edit(Band band)
        {
            if (ModelState.IsValid)
            {
                using (var db = new BandRegisterDbContext())
                {
                    Band bandToEdint = db.Bands.FirstOrDefault(b => b.Id == band.Id);

                    bandToEdint.Name       = band.Name;
                    bandToEdint.Members    = band.Members;
                    bandToEdint.Honorarium = band.Honorarium;
                    bandToEdint.Genre      = band.Genre;

                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Example #12
0
        public IActionResult Edit(Band band)
        {
            using (var db = new BandRegisterDbContext())
            {
                Band toEdit = db.Bands.FirstOrDefault(x => x.Id == band.Id);
                if (toEdit == null)
                {
                    RedirectToAction("Index");
                }

                toEdit.Genre      = band.Genre;
                toEdit.Honorarium = band.Honorarium;
                toEdit.Members    = band.Members;
                toEdit.Name       = band.Name;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
        public IActionResult Create(string name, string members, double honorarium, string genre)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(members) || double.IsNaN(honorarium) || string.IsNullOrEmpty(genre))
            {
                return(RedirectToAction("Index"));
            }
            Band band = new Band
            {
                Name       = name,
                Members    = members,
                Honorarium = honorarium,
                Genre      = genre
            };

            using (var db = new BandRegisterDbContext())
            {
                db.Bands.Add(band);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }