Exemple #1
0
        public async Task <IActionResult> Create([Bind("ChartName,Minutes,Seconds," +
                                                       "Composer,Arranger,RecordingUrl,Note,ShelfNumber")] Chart chart)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var defaultInstruments = Request.Form["ChartInstruments"];
                    chart.Instrumentation = new List <ChartInstrument>();

                    foreach (var item in defaultInstruments)
                    {
                        chart.Instrumentation.Add(new ChartInstrument
                        {
                            ChartID      = chart.ID,
                            InstrumentID = int.Parse(item)
                        });
                    }
                    _context.Add(chart);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Details), new { id = chart.ID }));
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            PopulateDefaultInstrumentationList();

            return(View(chart));
        }
        public async Task <IActionResult> Create([Bind("LastName,FirstName,Address,Email,Phone,Note,IsFullTime")]
                                                 Person person)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(person);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(person));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("VenueName,City,Contact,Comments")] Venue venue)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(venue);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception /*ex*/)
            {
                //Log the error (unkomment ex variable name and write a log.)
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(venue));
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("Name,Date,Comments,VenueID")] Performance performance)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(performance);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = performance.ID }));
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. Make sure your Performance Name is " +
                                         "not a double entry on the same date." +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            ViewData["VenueID"] = new SelectList(_context.Venues, "ID", "VenueName", performance.VenueID);

            return(View(performance));
        }