public async Task <IActionResult> Edit(int id, [Bind("Id,InstructorId,CourseId,DateCreated,UserCreated,DateModified,UserModified")] InstructorCourse instructorCourse) { if (id != instructorCourse.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(instructorCourse); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InstructorCourseExists(instructorCourse.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CourseId"] = new SelectList(_context.AdmCourses, "CourseId", "CourseTitle", instructorCourse.CourseId); ViewData["InstructorId"] = new SelectList(_context.Instructor, "InstructorId", "FullName", instructorCourse.InstructorId); return(View(instructorCourse)); }
protected void StudentsGridView_BindGridView() { InstructorCourse course = GrouperMethods.GetInstructorCourse(InstructorCourseID); StudentsGridView.DataSource = course.Students; StudentsGridView.DataBind(); }
protected void SendWelcomeToAllStudentsLinkButton_Click(object sender, EventArgs e) { InstructorCourse course = GrouperMethods.GetInstructorCourse(InstructorCourseID); if (course.Students.Where(x => x.InitialNotificationSentDate == null).Count() == 0) { MessageBox("No Students to Notify", "All students have already been sent a welcome email. To resend, select <b>Send Welcome</b> for the individual student row.", "Okay"); } else { foreach (Student student in course.Students) { if (student.InitialNotificationSentDate == null) { SendSurveyLinkMessage(student); student.InitialNotificationSentDate = DateTime.Now; GrouperMethods.UpdateStudent(student); } } StudentsGridView_BindGridView(); MessageBox("Welcome Messages Sent", "Welcome messages have been sent to all previously unnotified students.", "Okay"); } }
private async Task <InstructorCourse> CreateCourseAsync(string instructorId, string name, string description, string imageUri, string about, TimeSpan duration, string[] skillsDescription, CourseType courseType) { // create course var course = new Course(skillsDescription.Count()); course.ImageUri = imageUri; course.Name = name; course.Descripton = description; course.About = about; course.Duration = duration; course.Type = courseType; await AddAndSaveAsync(course); var instructorCourse = new InstructorCourse(course.Id, instructorId); await AddAndSaveAsync(instructorCourse); return(instructorCourse); }
public List <InstructorCourse> GetInstructorCourseList(int instructorId, ref List <string> errors) { var conn = new SqlConnection(ConnectionString); var instructorCourseList = new List <InstructorCourse>(); try { var adapter = new SqlDataAdapter(GetInstructorCourseProcedure, conn) { SelectCommand = { CommandType = CommandType.StoredProcedure } }; adapter.SelectCommand.Parameters.Add(new SqlParameter("@instructor_id", SqlDbType.Int)); adapter.SelectCommand.Parameters["@instructor_id"].Value = instructorId; var dataSet = new DataSet(); adapter.Fill(dataSet); if (dataSet.Tables[0].Rows.Count == 0) { return(null); } for (var i = 0; i < dataSet.Tables[0].Rows.Count; i++) { var instructorCourse = new InstructorCourse { ScheduleId = (int)dataSet.Tables[0].Rows[i]["schedule_id"], CourseId = (int)dataSet.Tables[0].Rows[i]["course_id"], Year = (int)dataSet.Tables[0].Rows[i]["year"], Quarter = dataSet.Tables[0].Rows[i]["quarter"].ToString(), Session = dataSet.Tables[0].Rows[i]["session"].ToString(), ScheduleDayId = (int)dataSet.Tables[0].Rows[i]["schedule_day_id"], ScheduleTimeId = (int)dataSet.Tables[0].Rows[i]["schedule_time_id"], InstructorId = (int)dataSet.Tables[0].Rows[i]["instructor_id"], CourseTitle = dataSet.Tables[0].Rows[i]["course_title"].ToString() }; instructorCourseList.Add(instructorCourse); } } catch (Exception e) { errors.Add("Error: " + e); } finally { conn.Dispose(); } return(instructorCourseList); }
protected void DeleteAllGroupsLinkButton_Click(object sender, EventArgs e) { InstructorCourse course = GrouperMethods.GetInstructorCourse(InstructorCourseID); foreach (Group group in course.Groups) { GrouperMethods.DeleteGroup(group.GroupID); } StudentsGridView_BindGridView(); GroupsRepeater_BindRepeater(); }
protected void StudentsGridView_BindGridView() { InstructorCourse course = GrouperMethods.GetInstructorCourse(InstructorCourseID); if (course.Groups.Count > 0) { NumberOfGroupsDropDownList.SelectedValue = course.Groups.Count.ToString(); } StudentsGridView.DataSource = course.Students; StudentsGridView.DataBind(); }
public async Task <IActionResult> Create([Bind("Id,InstructorId,CourseId,DateCreated,UserCreated,DateModified,UserModified")] InstructorCourse instructorCourse) { if (ModelState.IsValid) { _context.Add(instructorCourse); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CourseId"] = new SelectList(_context.AdmCourses, "CourseId", "CourseTitle", instructorCourse.CourseId); ViewData["InstructorId"] = new SelectList(_context.Instructor, "InstructorId", "FullName", instructorCourse.InstructorId); return(View(instructorCourse)); }
protected void GroupsRepeater_BindRepeater() { InstructorCourse course = GrouperMethods.GetInstructorCourse(InstructorCourseID); if (course.Groups.Count > 0) { NoGroupsPanel.Visible = false; } else { NoGroupsPanel.Visible = true; } GroupsRepeater.DataSource = course.Groups; GroupsRepeater.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["ID"] != "" && Request.QueryString["ID"] != null) { int instructorCourseID = int.Parse(Request.QueryString["ID"]); InstructorCourseID = instructorCourseID; InstructorCourse course = GrouperMethods.GetInstructorCourse(instructorCourseID); CourseNameLabel.Text = course.Course.FullName; StudentsGridView_BindGridView(); } }
public ActionResult Create([Bind(Include = "Id,CourseId,InstructorId")] InstructorCourse instructorCourse) { if (ModelState.IsValid) { _instrcutorCourseRepository.Add(instructorCourse); // _instrcutorCourseRepository.Save(); return(RedirectToAction("Index")); } ViewBag.CourseId = new SelectList(_courseRepository.GetAll(), "Id", "CourseTitle", instructorCourse.CourseId); ViewBag.InstructorId = new SelectList(_instructorRepository.GetAll(), "Id", "InstructorName", instructorCourse.InstructorId); return(View(instructorCourse)); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["ID"] != "" && Request.QueryString["ID"] != null) { int instructorCourseID = int.Parse(Request.QueryString["ID"]); InstructorCourseID = instructorCourseID; InstructorCourse course = GrouperMethods.GetInstructorCourse(instructorCourseID); GroupsRepeater_BindRepeater(); } if (!IsPostBack) { StudentsGridView_BindGridView(); } }
private void UpdateStudentCourse(string[] selectedCourses, InstructorUser ApplicationUser) { if (selectedCourses == null) { ApplicationUser.InstructorCourse = new List <InstructorCourse>(); return; } var selectedCoursesHS = new HashSet <string>(selectedCourses); var StudentCourses = new HashSet <int> (ApplicationUser.InstructorCourse.Select(c => c.Course.CourseID)); foreach (var course in _context.Course) { if (selectedCoursesHS.Contains(course.CourseID.ToString())) { if (!StudentCourses.Contains(course.CourseID)) { ApplicationUser.InstructorCourse.Add(new InstructorCourse { CourseID = course.CourseID, InstructorUserId = ApplicationUser.Id, }); } } else { if (StudentCourses.Contains(course.CourseID)) { InstructorCourse courseToRemove = ApplicationUser.InstructorCourse.SingleOrDefault(i => i.CourseID == course.CourseID); _Instructorcontext.Remove(courseToRemove); } } } }
protected void SaveCourseLinkButton_Click(object sender, EventArgs e) { string userName = Context.User.Identity.GetUserName(); Instructor instructor = GrouperMethods.GetInstructor(userName); if (instructor != null) { InstructorCourse course = new InstructorCourse(); course.InstructorID = instructor.InstructorID; course.CourseID = int.Parse(CoursesDropDownList.SelectedValue); course.TermNumber = int.Parse(TermsDropDownList.SelectedValue); course.Year = int.Parse(YearsDropDownList.SelectedValue); switch (course.TermNumber) { case 1: course.TermName = "Fall " + course.Year.ToString(); break; case 2: course.TermName = "Winter " + course.Year.ToString(); break; case 3: course.TermName = "Spring " + course.Year.ToString(); break; case 4: course.TermName = "Summer " + course.Year.ToString(); break; } int instructorCourseID = GrouperMethods.InsertInstructorCourse(course); BindGridView(); } }
protected void MessageBoxCreateLinkButton_Click(object sender, EventArgs e) { int studentID = int.Parse(SelectedStudentIDHiddenField.Value); if (studentID == 0) { InstructorCourse course = GrouperMethods.GetInstructorCourse(InstructorCourseID); foreach (Student student in course.Students) { GrouperMethods.DeleteStudent(student.StudentID); } StudentsGridView_BindGridView(); MessageBox("Students Deleted", "All students have been deleted.", "Okay"); } else { GrouperMethods.DeleteStudent(studentID); MessageBox("Student Deleted", "The student record has been deleted.", "Okay"); StudentsGridView_BindGridView(); } }
public async Task<ActionResult> Create([Bind("LastName", "FirstMidName", "HireDate", "OfficeAssignment")] Instructor instructor, string[] selectedCourses) { if (ModelState.IsValid) { if (selectedCourses != null) { instructor.Courses = new List<InstructorCourse>(); foreach (var course in selectedCourses) { var courseToAdd = _db.Courses.First(c => c.CourseID == int.Parse(course)); var instructorCourse = new InstructorCourse { Course = courseToAdd, }; instructor.Courses.Add(instructorCourse); _db.Entry(instructorCourse).State = Microsoft.Data.Entity.EntityState.Added; } } _db.Entry(instructor.OfficeAssignment).State = Microsoft.Data.Entity.EntityState.Added; _db.Instructors.Add(instructor); await _db.SaveChangesAsync(); return RedirectToAction("Index"); } PopulateAssignedCourseData(instructor); return View(instructor); }
protected void SendSurveyLinkMessage(Student student) { InstructorCourse course = GrouperMethods.GetInstructorCourse(student.InstructorCourseID); string header = @" <html> <head> <style> body { font-size:15px; font-family:'Calibri',sans-serif; } p, ul, li { font-size:15px; font-family:'Calibri',sans-serif; } </style> </head> <body>"; string footer = @"</body> </html>"; string messageBody = header; messageBody += @"<table border='0' cellpadding='0' cellspacing='0' height='100%' width='100%' id='bodyTable'> <tr> <td> <table border='0' cellpadding='20' cellspacing='0' width='600' id='emailContainer'> <tr> <td valign='top'>"; messageBody += "<h3>" + course.Course.FullName + " - Welcome</h3>"; string link = ""; link = "https://groupbuilder.azurewebsites.net?id=" + (student.FirstName + student.LastName); messageBody += @"</td> </tr> <tr> <td> <p>Welcome to " + course.Course.FullName + @". This course requires you to complete a short survey to best match you to a group.</p> <p> At your earliest convenience, please visit <a href='" + link + "'>" + link + @"</a> and complete the survey. </p> </td> </tr>"; messageBody += @" <tr> <td> <p>Please contact <a href='mailto:[email protected]'>Chris Friedrich</a> with general questions.</p> </td> </tr> </table> </td> </tr> </table> "; messageBody += footer; SmtpClient client = new SmtpClient(); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress("*****@*****.**", course.Course.FullName); mailMessage.To.Add(student.DuckID + "@uoregon.edu"); mailMessage.Subject = "Welcome to " + course.Course.Code; mailMessage.Body = messageBody; mailMessage.IsBodyHtml = true; if (client.Host != null) { if (mailMessage.To.Count > 0) { try { client.Send(mailMessage); } catch (SmtpFailedRecipientException ex) { SmtpStatusCode statusCode = ex.StatusCode; if (statusCode == SmtpStatusCode.MailboxBusy || statusCode == SmtpStatusCode.MailboxUnavailable || statusCode == SmtpStatusCode.TransactionFailed) { Thread.Sleep(2000); client.Send(mailMessage); } else { throw; } } finally { mailMessage.Dispose(); } } } }
protected void ProgrammingLanguagesGridView_BindGridView() { InstructorCourse course = GrouperMethods.GetInstructorCourse(InstructorCourseID); }
public async Task InstructoCourseRepositoryAddsNewInstructoCourse() { #region Arrange: create new customer string customerEmail = $"{Guid.NewGuid().ToString()}@example.com"; Customer customer = await customerManager.FindByEmailAsync(customerEmail); if (customer == null) { customer = await customerManager.CreateAsync (new CustomerRegistrationRequest("John", "Fogerty", customerEmail, "RunningInTheJungle12@")); } Assert.True(customer != null, "Customer should be created"); #endregion #region Arrange: create new instructor and bind it to created customer var newInstructor = new Instructor(); newInstructor.CustomerId = customer.Id; await instructoRepository.AddOrUpdateAsync(newInstructor); var instructor = await instructoRepository.FindAsync(newInstructor.Id); Assert.True(instructor != null, "Instructor should be created"); #endregion #region Arrage: create new course and bind it to created instructor var newCourse = new Course(); newCourse.Name = "Molecular Biology"; newCourse.Descripton = "Molecular Biology Desription"; await courseRepository.AddOrUpdateAsync(newCourse); var course = await courseRepository.FindAsync(newCourse.Id); // Assert course created Assert.True(course != null, "Course should be persisted in DB"); Assert.True(course.Name == newCourse.Name, "Course.Name should be persisted in DB"); #endregion #region Act: create new instructorCourse var newInstructorCourse = new InstructorCourse(); newInstructorCourse.InstructorId = instructor.Id; newInstructorCourse.CourseId = course.Id; await instructorCourseRepository.AddOrUpdateAsync(newInstructorCourse); #endregion #region Assert: instructorCourse exists in DB var foundIntructorCourse = await instructorCourseRepository .AsQueryable() .Include(ic => ic.Instructor) .Include(ic => ic.Course) .FirstOrDefaultAsync(ic => ic.CourseId == newInstructorCourse.CourseId && ic.InstructorId == instructor.Id); Assert.True(foundIntructorCourse != null, "InstructorCourse should be created"); Assert.True(foundIntructorCourse.CourseId == course.Id, "InstructorCourse.CourseId should be equals to Course.Id"); Assert.True(foundIntructorCourse.InstructorId == instructor.Id, "InstructorCourse.InstructorId should be equals to Course.Id"); #endregion #region Assert: course & instructoCourse relations are saved bool courseRelationIsCorrect = await courseRepository.AnyAsync(c => c.Id == foundIntructorCourse.Course.Id); Assert.True(courseRelationIsCorrect, "Course should be in relation with InstructoCourse"); #endregion #region Assert: instructor & instructorCourse relation are saved bool intructorRelationIsCorrect = await instructoRepository.AnyAsync(c => c.Id == foundIntructorCourse.Instructor.Id); Assert.True(intructorRelationIsCorrect, "Instructor should be in relation with InstructoCourse"); #endregion }