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

            Instructor instructor = await _context.Instructors
                                    .Include(i => i.CourseAssignments)
                                    .SingleAsync(i => i.ID == id);

            if (instructor == null)
            {
                return(RedirectToPage("./Index"));
            }

            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"));
        }
Example #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

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

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

            // Select DepartmentID if TryUpdateModelAsync fails.
            PopulateDepartmentsDropDownList(_context, courseToUpdate.DepartmentID);
            return(Page());
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Student = await _context.Students.FindAsync(id);

            if (Student == null)
            {
                return(NotFound());
            }
            try
            {
                _context.Students.Remove(Student);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateException)
            {
                return(RedirectToAction("./Delete", new { id, saveChangesError = true }));
            }
        }
Example #4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Department).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentExists(Department.DepartmentID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Example #5
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

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

            Department = await _context.Departments.FindAsync(id);

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

            return(RedirectToPage("./Index"));
        }
Example #7
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            var emptyStudent = new Student();

            if (await TryUpdateModelAsync <Student>(
                    emptyStudent,
                    "student", // Prefix for form value.
                    s => s.LastName, s => s.FirstName, s => s.EnrollmentDate))
            {
                _context.Students.Add(emptyStudent);
                await _context.SaveChangesAsync();

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

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

            Course = await _context.Courses.FindAsync(id);

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

            return(RedirectToPage("./Index"));
        }
Example #9
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            var emptyCourse = new Course();

            if (await TryUpdateModelAsync <Course>(
                    emptyCourse,
                    "course", // Prefix for form value.
                    s => s.CourseID, s => s.DepartmentID, s => s.Title, s => s.Credits))
            {
                _context.Courses.Add(emptyCourse);
                await _context.SaveChangesAsync();

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

            // Select DepartmentID if TryUpdateModelAsync fails.
            PopulateDepartmentsDropDownList(_context, emptyCourse.DepartmentID);
            return(Page());
        }
Example #10
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedCourses)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var instructorToUpdate = await _context.Instructors
                                     .Include(i => i.OfficeAssignment)
                                     .Include(i => i.CourseAssignments)
                                     .ThenInclude(i => i.Course)
                                     .FirstOrDefaultAsync(s => s.ID == id);

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

            if (await TryUpdateModelAsync <Instructor>(
                    instructorToUpdate,
                    "Instructor",
                    i => i.FirstName, i => i.LastName,
                    i => i.HireDate, i => i.OfficeAssignment))
            {
                if (String.IsNullOrWhiteSpace(
                        instructorToUpdate.OfficeAssignment?.Location))
                {
                    instructorToUpdate.OfficeAssignment = null;
                }
                UpdateInstructorCourses(_context, selectedCourses, instructorToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            UpdateInstructorCourses(_context, selectedCourses, instructorToUpdate);
            PopulateAssignedCourseData(_context, instructorToUpdate);
            return(Page());
        }