public IActionResult Index() { var students = new List <Student>() { new Student() { Name = "Ahmet" }, new Student() { Name = "Ayşe" }, new Student() { Name = "Salih" }, new Student() { Name = "Hamza" } }; var course = new Course() { Id = 1, Name = "Udemy Öğretici Kursu" }; var viewModel = new CourseStudentViewModel() { Course = course, Students = students }; return(View(viewModel)); }
public void CanGetAndSetForCourseStudentViewModelTest() { // Arrange Course course = new Course(); course.ID = 1; course.Name = "DotNet"; course.Description = "Savor the flood"; Student student = new Student(); student.ID = 1; student.Name = "Jimmy"; student.CourseID = 1; student.CourseName = "DotNet"; CourseStudentViewModel courseStudent = new CourseStudentViewModel(); // Act courseStudent.Course = course; courseStudent.Student = student; // Assert Assert.Equal(course.Name, courseStudent.Course.Name); Assert.Equal(course.ID, courseStudent.Course.ID); Assert.Equal(course.Description, courseStudent.Course.Description); Assert.Equal(student.ID, courseStudent.Student.ID); Assert.Equal(student.Name, courseStudent.Student.Name); Assert.Equal(student.CourseID, courseStudent.Course.ID); Assert.Equal(student.CourseID, courseStudent.Student.CourseID); Assert.Equal(student.CourseName, courseStudent.Course.Name); Assert.Equal(student.CourseName, courseStudent.Student.CourseName); }
public async Task <IActionResult> Delete(int?id) { CourseStudentViewModel courseStudent = new CourseStudentViewModel(); courseStudent.Course = await _context.Courses.FindAsync(id); if (courseStudent.Course == null) { // If there is no course at the ID provided, the user is sent to the NotFound error page. return(NotFound()); } courseStudent.Student = await _context.Students.FirstOrDefaultAsync(s => s.CourseID == id); if (courseStudent.Student != null) { // If the course still has students in it, the user will be sent to this error page return(RedirectToAction("Error")); } _context.Courses.Remove(courseStudent.Course); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult AddStudent(CourseStudentViewModel model) { Student student = db.Students.Find(model.StudentID); if (student == null) { ModelState.AddModelError("", "No student with that id was found or could not be retrived at this moment."); } Course course = db.Courses.Find(model.CourseID); if (course == null) { return(HttpNotFound()); } if (ModelState.IsValid) { if (!course.EnrolledStudents.Any(s => s.StudentID == model.StudentID)) { course.EnrolledStudents.Add(student); db.SaveChanges(); return(RedirectToAction("Details", new { id = model.CourseID })); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "A student with that id is already assigned to the course.")); } } return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "A student with that id was not found.")); }
public async Task <IActionResult> Create() { CourseStudentViewModel courseStudent = new CourseStudentViewModel(); courseStudent.courses = await _context.Courses.ToListAsync(); return(View(courseStudent)); }
public ActionResult CourseStudent() { var courseStudent = new CourseStudentViewModel(); var studentList = context.Users.Where(m => m.StudentUserProfile != null).Select(m => m.StudentUserProfile).ToList <StudentUserProfile>(); courseStudent.StudentCollection = studentList; courseStudent.CourseCollection = context.Courses.ToList(); return(View(courseStudent)); }
public IActionResult Post(CourseStudentViewModel courseStudents) { var result = courseService.CreateAsync(courseStudents.course).Result; foreach (var std in courseStudents.students) { StudentService.CreateAsync(std); } return(null); }
public ActionResult AddStudent(int?id) { if (id != null) { var model = new CourseStudentViewModel { CourseID = (int)id }; return(View(model)); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Update(int?id) { if (id.HasValue) { CourseStudentViewModel courseStudent = new CourseStudentViewModel(); courseStudent.courses = await _context.Courses.ToListAsync(); courseStudent.Student = await _context.Students.FirstOrDefaultAsync(s => s.ID == id); return(View(courseStudent)); } // If the user gave the wrong id, this sends the user back to the home page return(RedirectToAction("Index", "Home")); }
public ActionResult CourseStudent(CourseStudentViewModel model) { if (ModelState.IsValid) { var course = context.Courses.Include(c => c.StudentUserProfile).Single(m => m.Id.ToString() == model.CourseID); var studentList = context.Users.Where(m => m.StudentUserProfile != null).Select(m => m.StudentUserProfile).ToList <StudentUserProfile>(); var student = studentList.Single(s => s.Id.ToString() == model.StudentID); course.StudentUserProfile.Add(student); context.SaveChanges(); return(RedirectToAction("Home", "Portal")); } return(View(model)); }
public async Task <IActionResult> Details(int?id) { if (id.HasValue) { CourseStudentViewModel courseStudent = new CourseStudentViewModel(); courseStudent.Course = await _context.Courses.FirstOrDefaultAsync(s => s.ID == id); courseStudent.students = await _context.Students .Where(x => x.CourseID == id) .ToListAsync(); return(View(courseStudent)); } // If the user put in an invalid course id, then they are sent back to the home page. return(RedirectToAction("Index", "Home")); }
/* * http://localhost:63390/Course/Index * http://localhost:63390/Course/IndexTest */ public IActionResult Index() { int saat = DateTime.Now.Hour; ViewBag.Greeting = saat > 12 ? "Iyı Gunler" : "Gunaydın"; ViewBag.UserName = "******"; var categories = new List <Category>() { new Category() { CategoryId = 1, CategoryName = "Matematik" }, new Category() { CategoryId = 2, CategoryName = "Fizik" } }; var course = new Course() { CourseId = 1, Name = "Matematik", CreateDate = DateTime.Now, Description = "Matematiksel Algoritmalar", IsPublish = true, PublishDate = DateTime.Now, TeacherId = 1 }; var student = new Student() { Name = "Miraç", SurName = "ÖZTÜRK", Confirm = true, Phone = "0444444444", Email = "*****@*****.**" }; var viewModel = new CourseStudentViewModel(); viewModel.Courses = course; viewModel.Students = student; viewModel.Categories = categories; // ACTION METHOD OBEKLERI. return(View(viewModel)); }
public async Task <IActionResult> Edit(int id, CourseStudentViewModel coursestudentviewmodel) { if (id != coursestudentviewmodel.Course.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(coursestudentviewmodel.Course); await _context.SaveChangesAsync(); IEnumerable <int> listStudents = coursestudentviewmodel.SelectedStudents; IQueryable <Enrollment> toBeRemoved = _context.Enrollment.Where(s => !listStudents.Contains(s.StudentId) && s.CourseId == id); _context.Enrollment.RemoveRange(toBeRemoved); IEnumerable <int> existStudents = _context.Enrollment.Where(s => listStudents.Contains(s.StudentId) && s.CourseId == id).Select(s => s.StudentId); IEnumerable <int> newStudents = listStudents.Where(s => !existStudents.Contains(s)); foreach (int studentId in newStudents) { _context.Enrollment.Add(new Enrollment { StudentId = studentId, CourseId = id }); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(coursestudentviewmodel.Course.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FirstTeacherId"] = new SelectList(_context.Teacher, "Id", "FullName", coursestudentviewmodel.Course.FirstTeacherId); ViewData["SecondTeacherId"] = new SelectList(_context.Teacher, "Id", "FullName", coursestudentviewmodel.Course.SecondTeacherId); return(View(coursestudentviewmodel)); }
// GET: Courses/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var course = _context.Course.Where(m => m.Id == id).Include(m => m.Students).First(); if (course == null) { return(NotFound()); } CourseStudentViewModel coursestudent = new CourseStudentViewModel { Course = course, StudentsList = new MultiSelectList(_context.Student.OrderBy(s => s.FirstName), "Id", "FullName"), SelectedStudents = course.Students.Select(sa => sa.StudentId) }; ViewData["FirstTeacherId"] = new SelectList(_context.Teacher, "Id", "FullName", course.FirstTeacherId); ViewData["SecondTeacherId"] = new SelectList(_context.Teacher, "Id", "FullName", course.SecondTeacherId); return(View(coursestudent)); }