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)); }
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)); }
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>())); }
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()); }
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); }
public async Task <ApplicationStudent> Create(ApplicationStudent application1) { var createdClass = await _context.ApplicationStudents.AddAsync(application1); await _context.SaveChangesAsync(); return(createdClass.Entity); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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 }));; }
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")); }
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")); }
public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { _db.Students.Add(Student); await _db.SaveChangesAsync(); return(RedirectToPage("ListStudents")); } else { return(Page()); } }
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")); }
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()); } }
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")); }