public async Task <IActionResult> Edit(string id, [Bind("ListenerID,BandID,Note")] BandListener bandListener)
        {
            if (id != bandListener.BandID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bandListener);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BandListenerExists(bandListener.BandID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BandID"]     = new SelectList(_context.Bands, "BandID", "BandID", bandListener.BandID);
            ViewData["ListenerID"] = new SelectList(_context.Listeners, "ListenerID", "ListenerID", bandListener.ListenerID);
            return(View(bandListener));
        }
        public async Task <IActionResult> Create([Bind("ListenerID,BandID,Note")] BandListener bandListener)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bandListener);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BandID"]     = new SelectList(_context.Bands, "BandID", "BandID", bandListener.BandID);
            ViewData["ListenerID"] = new SelectList(_context.Listeners, "ListenerID", "ListenerID", bandListener.ListenerID);
            return(View(bandListener));
        }
Example #3
0
        public static void Initialize(MusicContext context)
        {
            context.Database.EnsureCreated();

            if (context.Listeners.Any())
            {
                return;
            }

            var listeners = new Listener[] {
                new Listener {
                    Name = "Ola", DateOfBirth = DateTime.Parse("1999-12-01")
                },
                new Listener {
                    Name = "Malgorzata", DateOfBirth = DateTime.Parse("1999-12-01")
                },
                new Listener {
                    Name = "Jan", DateOfBirth = DateTime.Parse("1999-12-01")
                },
                new Listener {
                    Name = "Julia", DateOfBirth = DateTime.Parse("1999-12-01")
                },
            };

            foreach (Listener l in listeners)
            {
                context.Listeners.Add(l);
            }
            context.SaveChanges();

            var bands = new Band[] {
                new Band {
                    BandID = "Tool", City = "New York", FormationDate = DateTime.Parse("2012-01-01"), Genre = Genre.art
                },
                new Band {
                    BandID = "Jamie xx", City = "London", FormationDate = DateTime.Parse("2017-01-01"), Genre = Genre.folk
                },
                new Band {
                    BandID = "Janes Addiciton", City = "Los Angeles", FormationDate = DateTime.Parse("1989-01-01"), Genre = Genre.pop
                },
                new Band {
                    BandID = "Aesop Rock", City = "Los Angeles", Genre = Genre.pop
                },
            };

            foreach (Band b in bands)
            {
                context.Bands.Add(b);
            }
            context.SaveChanges();

            var bandsListeners = new BandListener[] {
                new BandListener {
                    ListenerID = 1, BandID = "Tool", Note = 4
                },
                new BandListener {
                    ListenerID = 1, BandID = "Janes Addiciton", Note = 2
                },
                new BandListener {
                    ListenerID = 2, BandID = "Aesop Rock", Note = 4
                },
                new BandListener {
                    ListenerID = 3, BandID = "Jamie xx", Note = 5
                },
                new BandListener {
                    ListenerID = 4, BandID = "Aesop Rock", Note = 2
                },
            };

            foreach (BandListener bl in bandsListeners)
            {
                context.BandsListeners.Add(bl);
            }
            context.SaveChanges();

            var tours = new Tour[] {
                new Tour {
                    BandID = "Tool", City = "Gdynia", Date = DateTime.Parse("2017-06-01")
                },
                new Tour {
                    BandID = "Tool", City = "Warszawa", Date = DateTime.Parse("2017-07-01")
                },
                new Tour {
                    BandID = "Tool", City = "Katowice", Date = DateTime.Parse("2017-01-01")
                },
                new Tour {
                    BandID = "Jamie xx", City = "Berlin", Date = DateTime.Parse("2017-02-01")
                },
                new Tour {
                    BandID = "Jamie xx", City = "Moscow", Date = DateTime.Parse("2017-03-01")
                },
                new Tour {
                    BandID = "Aesop Rock", City = "Peking", Date = DateTime.Parse("2017-04-01")
                },
                new Tour {
                    BandID = "Aesop Rock", City = "Oslo", Date = DateTime.Parse("2017-05-01")
                },
            };

            foreach (var t in tours)
            {
                context.Tours.Add(t);
            }
            context.SaveChanges();
        }