public PartialViewResult PreFillCourse(string selectedCourse) { CourseTemplates selectedTemplate = db.CourseTemplates.FirstOrDefault(o => o.Title == selectedCourse); ViewBag.selectedString = selectedCourse; if (selectedTemplate != null) { var preFill = new ApplyCourseViewModel { Title = selectedTemplate.Title, Credits = selectedTemplate.Credits, Elective = selectedTemplate.Elective, AttendingDays = selectedTemplate.AttendingDays, AttendanceCap = selectedTemplate.AttendanceCap, Location = selectedTemplate.Location, Parish = selectedTemplate.Parish, Description = selectedTemplate.Description, Cost = selectedTemplate.Cost, StartDate = DateTime.Now, EndDate = DateTime.Now.AddMonths(1) }; return(PartialView("_CourseForm", preFill)); } return(null); }
private Course BuildCourseData(ApplyCourseViewModel appliedCourse, Instructor instructorAgain) { Debug.Write(appliedCourse.Cost); var newCourse = new Course { Title = appliedCourse.Title, Credits = appliedCourse.Credits, Elective = appliedCourse.Elective, InstructorID = instructorAgain.InstructorID, Year = appliedCourse.StartDate.Year, AttendingDays = appliedCourse.AttendingDays, AttendanceCap = appliedCourse.AttendanceCap, StartDate = appliedCourse.StartDate, EndDate = appliedCourse.EndDate, Location = appliedCourse.Location, Parish = appliedCourse.Parish, Description = appliedCourse.Description, Cost = appliedCourse.Cost, Approved = false, Completed = false, Archived = false }; db.Courses.Add(newCourse); return(newCourse); }
public ActionResult ApplyToTeach() { DbSet <CourseTemplates> course = db.CourseTemplates; var model = new ApplyCourseViewModel { Courses = course.Select(x => new SelectListItem { Value = x.Title, Text = x.Title, }), StartDate = DateTime.Now, EndDate = DateTime.Now }; return(View(model)); }
private void BuildNotificationData( ApplyCourseViewModel appliedCourse, Instructor instructorAgain, Course newCourse) { var newNotification = new Notification { Time = DateTime.Now, Details = "An Instructor by the name of " + instructorAgain.LastName + " has applied to teach " + appliedCourse.Title, Link = Url.Action("Details", "Course", new { id = newCourse.CourseID }), ViewableBy = "Admin", Complete = false }; db.Notification.Add(newNotification); }
public ActionResult ApplyToTeach(ApplyCourseViewModel appliedCourse) { if (ModelState.IsValid) { Debug.Write(appliedCourse.Cost); Instructor instructor = db.Instructors.FirstOrDefault(o => o.UserName == User.Identity.Name); if (instructor == null) { // If the user is currently not an Instructor, make them one Student currentUser = db.Students.FirstOrDefault(o => o.UserName == User.Identity.Name); // "currentUser" needed to have user's information ( every user should have data in the Student table, // so their information is stored there) // Creates a new Instructor in the Instructor Table // using the User's information CreatesInstructorDataAndAssignsRole(currentUser); } Instructor instructorAgain = db.Instructors.FirstOrDefault(o => o.UserName == User.Identity.Name); // Have to check the instructor again because if we just created // the instructor there will be "null" in the "instructor" variable Course newCourse = BuildCourseData(appliedCourse, instructorAgain); Debug.Write(appliedCourse.Cost); db.SaveChanges(); BuildNotificationData(appliedCourse, instructorAgain, newCourse); db.SaveChanges(); TempData["tempMessage"] = "You have successfully applied to teach this course. A notification has been sent to an administrator so they can review the application. You will receive a notification when an administrator takes action on your application to teach, this typically takes 1 - 3 business days."; return(RedirectToAction("Details", new { id = newCourse.CourseID })); } return(View("Error")); }
private void BuildNotificationData( ApplyCourseViewModel appliedCourse, Instructor instructorAgain, Course newCourse) { var newNotification = new Notification { Time = DateTime.Now, Details = "An Instructor by the name of " + instructorAgain.LastName + " has applied to teach " + appliedCourse.Title, Link = Url.Action("Details", "Course", new { id = newCourse.CourseID }), ViewableBy = "Admin", Complete = false }; db.Notification.Add(newNotification); }
private Course BuildCourseData(ApplyCourseViewModel appliedCourse, Instructor instructorAgain) { Debug.Write(appliedCourse.Cost); var newCourse = new Course { Title = appliedCourse.Title, Credits = appliedCourse.Credits, Elective = appliedCourse.Elective, InstructorID = instructorAgain.InstructorID, Year = appliedCourse.StartDate.Year, AttendingDays = appliedCourse.AttendingDays, AttendanceCap = appliedCourse.AttendanceCap, StartDate = appliedCourse.StartDate, EndDate = appliedCourse.EndDate, Location = appliedCourse.Location, Parish = appliedCourse.Parish, Description = appliedCourse.Description, Cost = appliedCourse.Cost, Approved = false, Completed = false, Archived = false }; db.Courses.Add(newCourse); return newCourse; }
public PartialViewResult PreFillCourse(string selectedCourse) { CourseTemplates selectedTemplate = db.CourseTemplates.FirstOrDefault(o => o.Title == selectedCourse); ViewBag.selectedString = selectedCourse; if (selectedTemplate != null) { var preFill = new ApplyCourseViewModel { Title = selectedTemplate.Title, Credits = selectedTemplate.Credits, Elective = selectedTemplate.Elective, AttendingDays = selectedTemplate.AttendingDays, AttendanceCap = selectedTemplate.AttendanceCap, Location = selectedTemplate.Location, Parish = selectedTemplate.Parish, Description = selectedTemplate.Description, Cost = selectedTemplate.Cost, StartDate = DateTime.Now, EndDate = DateTime.Now.AddMonths(1) }; return PartialView("_CourseForm", preFill); } return null; }
public ActionResult ApplyToTeach(ApplyCourseViewModel appliedCourse) { if (ModelState.IsValid) { Debug.Write(appliedCourse.Cost); Instructor instructor = db.Instructors.FirstOrDefault(o => o.UserName == User.Identity.Name); if (instructor == null) { // If the user is currently not an Instructor, make them one Student currentUser = db.Students.FirstOrDefault(o => o.UserName == User.Identity.Name); // "currentUser" needed to have user's information ( every user should have data in the Student table, // so their information is stored there) // Creates a new Instructor in the Instructor Table // using the User's information CreatesInstructorDataAndAssignsRole(currentUser); } Instructor instructorAgain = db.Instructors.FirstOrDefault(o => o.UserName == User.Identity.Name); // Have to check the instructor again because if we just created // the instructor there will be "null" in the "instructor" variable Course newCourse = BuildCourseData(appliedCourse, instructorAgain); Debug.Write(appliedCourse.Cost); db.SaveChanges(); BuildNotificationData(appliedCourse, instructorAgain, newCourse); db.SaveChanges(); TempData["tempMessage"] = "You have successfully applied to teach this course. A notification has been sent to an administrator so they can review the application. You will receive a notification when an administrator takes action on your application to teach, this typically takes 1 - 3 business days."; return RedirectToAction("Details", new { id = newCourse.CourseID }); } return View("Error"); }
public ActionResult ApplyToTeach() { DbSet<CourseTemplates> course = db.CourseTemplates; var model = new ApplyCourseViewModel { Courses = course.Select(x => new SelectListItem { Value = x.Title, Text = x.Title, }), StartDate = DateTime.Now, EndDate = DateTime.Now }; return View(model); }