public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var student = await _context.Student
                          .AsNoTracking()
                          .FirstOrDefaultAsync(m => m.ID == id);

            if (student == null)
            {
                return(NotFound());
            }

            try
            {
                _context.Student.Remove(student);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateException)
            {
                return(RedirectToAction("./Delete", new { id, saveChangesError = true }));
            }
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Departments.Add(Department);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            Instructor instructor = await _context.Instructors
                                    .Include(i => i.CourseAssignments)
                                    .SingleAsync(i => i.ID == id);

            var departments = await _context.Departments
                              .Where(d => d.InstructorID == id)
                              .ToListAsync();

            departments.ForEach(d => d.InstructorID = null);

            _context.Instructors.Remove(instructor);

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemple #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Course = await _context.Course
                     .AsNoTracking()
                     .FirstOrDefaultAsync(m => m.CourseID == id);

            if (Course != null)
            {
                _context.Course.Remove(Course);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var studentToUpdate = await _context.Student.FindAsync(id);

            if (await TryUpdateModelAsync <Student>(studentToUpdate,
                                                    "student",
                                                    s => s.FirstMidName, s => s.LastName, s => s.EnrollmentDate))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            return(Page());
        }
Exemple #6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var emptyStudent = new Student();

            if (await TryUpdateModelAsync <Student>(emptyStudent, "student",
                                                    s => s.FirstMidName, s => s.LastName, s => s.EnrollmentDate))
            {
                _context.Student.Add(emptyStudent);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            return(null);
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var courseToUpdate = await _context.Course.FindAsync(id);

            if (await TryUpdateModelAsync <Course>(
                    courseToUpdate,
                    "course",
                    c => c.Credits, c => c.DepartmentID, c => c.Title))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            PopulateDepartmentDropDownList(_context, courseToUpdate.DepartmentID);
            return(Page());
        }