Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("ID,Name,YearProduced,Price,GenreID")] Album album)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(album);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.Contains("IX_Albums_Name_YearProduced"))
                {
                    ModelState.AddModelError("YearProduced", "An album called " + album.Name + " already exists from " + album.YearProduced.ToString());
                }
                else
                {
                    ModelState.AddModelError("", ex.Message.ToString());
                }
            }

            PopulateGenreDropdown(album);
            return(View(album));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("ID,Name")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                _context.Add(genre);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(genre));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("ID,Title,GenreID,AlbumID")] Song song)
        {
            if (ModelState.IsValid)
            {
                _context.Add(song);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateAlbumDropdown(song);
            PopulateGenreDropdown(song);
            return(View(song));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("ID,StageName,FName,MName,LName,Phone,DOB,SIN,InstrumentID")] Musician musician, string[] selectedInstruments)
        {
            try
            {
                if (selectedInstruments != null)
                {
                    musician.Plays = new List <Plays>();
                    foreach (var inst in selectedInstruments)
                    {
                        var instToAdd = new Plays {
                            MusicianID = musician.ID, InstrumentID = int.Parse(inst)
                        };
                        musician.Plays.Add(instToAdd);
                    }
                }


                if (ModelState.IsValid)
                {
                    _context.Add(musician);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException dex)
            {
                if (dex.InnerException.Message.Contains("IX_Musicians_SIN"))
                {
                    ModelState.AddModelError("SIN", "Please ensure SIN numbers are unique");
                }
                else
                {
                    ModelState.AddModelError("", "Unable to save changes. Please try again later.");
                }
            }

            PopulateAssignedInstrumentData(musician);
            PopulateInstrumentDropdown(musician);

            return(View(musician));
        }