Exemple #1
0
        public async Task <IActionResult> Edit(string id, [Bind("CourseID,CourseName,Credits,Online")] Courses courses)
        {
            // Checks if the "id" doesn't match the course ID
            if (id != courses.CourseID)
            {
                return(NotFound());
            }

            // Checks if no errors occurred
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(courses);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    // Checks if the course doesn't exist
                    if (!CoursesExists(courses.CourseID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(courses));
        }