예제 #1
0
        public async Task <IActionResult> Create([Bind("FirstMidName,HireDate,LastName,OfficeAssignment")] Lecturer lecturer, string[] selectedCourses)
        {
            if (selectedCourses != null)
            {
                lecturer.CourseAssignments = new List <CourseAssignment>();
                foreach (var course in selectedCourses)
                {
                    var courseToAdd = new CourseAssignment {
                        LecturerID = lecturer.ID, CourseID = int.Parse(course)
                    };

                    lecturer.CourseAssignments.Add(courseToAdd);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(lecturer);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            PopulateAssignedCourseData(lecturer);

            return(View(lecturer));
        }
예제 #2
0
        public async Task <IHttpActionResult> PutFaculty(int id, Faculty faculty)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != faculty.FacultyID)
            {
                return(BadRequest());
            }

            db.Entry(faculty).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FacultyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #3
0
        public async Task <JsonResult> Create([Bind(Include = "Name,Birthday,Salary")] Teacher teacher)
        {
            db.Teachers.Add(teacher);
            await db.SaveChangesAsync();

            return(Json(db.Teachers.ToList().LastOrDefault <Teacher>()));
        }
예제 #4
0
        public async Task <IActionResult> PutGroup(long id, Group @group)
        {
            if (id != @group.ID)
            {
                return(BadRequest());
            }

            _context.Entry(@group).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroupExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #5
0
        public async Task <JsonResult> Create([Bind(Include = "Id,Name,Birthday,RegNumber")] Student student)
        {
            db.Students.Add(student);
            await db.SaveChangesAsync();

            return(Json(db.Students.ToList().LastOrDefault <Student>()));
        }
        public async Task <Semester> CreateSemester(Semester semester)
        {
            await _context.Semesters.AddAsync(semester);

            await _context.SaveChangesAsync();

            return(semester);
        }
예제 #7
0
        public async Task <ApplicationStudent> Create(ApplicationStudent application1)
        {
            var createdClass = await _context.ApplicationStudents.AddAsync(application1);

            await _context.SaveChangesAsync();

            return(createdClass.Entity);
        }
예제 #8
0
        public async Task <JsonResult> Create([Bind(Include = "SubjectId,TeacherId,CourseId,Title")] Subject subject)
        {
            db.Subjects.Add(subject);
            await db.SaveChangesAsync();

            subject = await db.Subjects.FindAsync(subject.SubjectId);

            return(Json(subject));
        }
예제 #9
0
        public async Task <JsonResult> Create([Bind(Include = "CourseId,Title")] Course course)
        {
            db.Courses.Add(course);
            await db.SaveChangesAsync();

            course = await db.Courses.FindAsync(course.CourseId);

            return(Json(course));
        }
        public async Task <IActionResult> Create([Bind("ID,LastName,FirstMidName,EnrollmentDate")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
예제 #11
0
        public async Task <IActionResult> Create([Bind("ID,Forenames,Surname,Email,DateOfBirth")] Lecturer lecturer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lecturer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(lecturer));
        }
        public async Task <IActionResult> Create([Bind("CourseID,Title,Credits")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
예제 #13
0
        public async Task <IActionResult> Create([Bind("DegreeID,DegreeName,DegreeDuration,LecturerID")] Degree degree)
        {
            if (ModelState.IsValid)
            {
                _context.Add(degree);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LecturerID"] = new SelectList(_context.Lecturers, "ID", "Email", degree.LecturerID);
            return(View(degree));
        }
예제 #14
0
        public async Task <IActionResult> Create([Bind("CourseID,DegreeID,CourseName,CourseDuration")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DegreeID"] = new SelectList(_context.Degrees, "DegreeID", "DegreeID", course.DegreeID);
            return(View(course));
        }
예제 #15
0
        public async Task <IActionResult> Create([Bind("DegreeID,ID,Forenames,Surname,Email,DateOfBirth")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DegreeID"] = new SelectList(_context.Degrees, "DegreeID", "DegreeID", student.DegreeID);
            return(View(student));
        }
예제 #16
0
        public async Task <IActionResult> Create([Bind("CourseID,Credits,DepartmentID,Title")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            PopulateDepartmentsDropDownList(course.DepartmentID);
            return(View(course));
        }
예제 #17
0
        public async Task <IActionResult> Create([Bind("EnrollmentID,CourseID,StudentID,Grade")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseID"]  = new SelectList(_context.Courses, "CourseID", "CourseID", enrollment.CourseID);
            ViewData["StudentID"] = new SelectList(_context.Students, "ID", "ID", enrollment.StudentID);
            return(View(enrollment));
        }
예제 #18
0
        public async Task <IActionResult> Create([Bind("DepartmentID,Name,Budget,StartDate,LecturerID,RowVersion")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["LecturerID"] = new SelectList(_context.Lecturers, "ID", "FullName", department.LecturerID);

            return(View(department));
        }
예제 #19
0
        public async Task <JsonResult> Create([Bind(Include = "Id,SubjectId,StudentId,Grade")] Enrollment enrollment)
        {
            var student = db.Students.Where(s => s.Id == enrollment.StudentId).FirstOrDefault();
            var subject = db.Subjects.Where(s => s.SubjectId == enrollment.SubjectId).FirstOrDefault();
            var course  = db.Courses.Where(s => s.Subjects.Where(b => b.SubjectId == enrollment.SubjectId).Count() > 0).FirstOrDefault();

            db.Enrollments.Add(enrollment);
            await db.SaveChangesAsync();

            return(Json(new
            {
                Id = db.Enrollments.ToList().LastOrDefault <Enrollment>().Id,
                Student = student.Name,
                Subject = subject.SubjectId + "-" + subject.Title,
                Course = course.CourseId + "-" + course.Title,
                Grade = enrollment.Grade
            }));;
        }
예제 #20
0
        public async Task <IActionResult> Create([Bind("LastName,FirstMidName,EnrollmentDate,DOB")] Student student)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(student);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(student));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            var student = await _db.Students.FindAsync(Student.ID);

            if (student != null)
            {
                _db.Students.Remove(student);
                await _db.SaveChangesAsync();
            }

            return(RedirectToPage("ListStudents"));
        }
예제 #22
0
        public async Task <IActionResult> Edit(Student student)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var id = student.Id;

            if (db.Students.Any(s => s.Id == id))
            {
                db.Students.Update(student);
            }
            else
            {
                student.Id = null;          // because of Student.Id auto increment
                db.Students.Add(student);
            }

            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
예제 #23
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                _db.Students.Add(Student);
                await _db.SaveChangesAsync();

                return(RedirectToPage("ListStudents"));
            }
            else
            {
                return(Page());
            }
        }
예제 #24
0
        public async Task <IActionResult> OnPostAsync()
        {
            //if (Student.Email != Student.EmailConfirmation)
            //    ModelState.AddModelError("Student.Email", "emails don't match");

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _db.Students.Add(Student);
            await _db.SaveChangesAsync();

            return(RedirectToPage("ListStudents"));
        }
예제 #25
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (Student.Email != Student.EmailConfirm)
            {
                ModelState.AddModelError("Student.Email", "emails don't match");
            }

            if (ModelState.IsValid)
            {
                _db.Student.Add(Student);
                await _db.SaveChangesAsync();

                return(RedirectToPage("/ListStudents"));
            }
            else
            {
                return(Page());
            }
        }
예제 #26
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _db.Attach(Student).State = EntityState.Modified;

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw new Exception($"Student {Student.StudentID} not found!");
            }

            return(RedirectToPage("/ListStudents"));
        }