public async Task <ActionResult> CreateMessage([Bind(Include = "student_id,student_Name,message")] Models.StudentMessage message) { // Initialize the GraphServiceClient. GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient(); var userDetails = await eventsService.GetMyDetails(graphClient); StudentMessage msg = new StudentMessage(); msg.student_id = userDetails.Mail ?? userDetails.UserPrincipalName; msg.student_Name = userDetails.DisplayName; msg.message = Request.Form["message"]; msg.Date_Created = DateTime.Now; msg.is_archived = false; OfficeHoursContext officeHoursContext = new OfficeHoursContext(); List <Faculty> faculties = officeHoursContext.faculties.ToList(); msg.Email = Session["facultyMail"].ToString(); try { officeHoursContext.messages.Add(msg); officeHoursContext.SaveChanges(); } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } return(RedirectToAction("MessageView", "Student").Success("Message created and sent to faculty")); }
// GET: OfficeHours public ActionResult Index() { OfficeHoursContext officeHoursContext = new OfficeHoursContext(); List <Faculty> faculties = officeHoursContext.faculties.ToList(); List <OfficeSchedule> officeHours = faculties.First().Office_Hours.ToList(); return(View(officeHours)); }
public async Task <ActionResult> MessageView() { GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient(); User fac = await eventsService.GetMyDetails(graphClient); OfficeHoursContext officeHoursContext = new OfficeHoursContext(); List <StudentMessage> studentMessages = officeHoursContext.messages.ToList(); List <WebApp.Models.StudentMessage> messages = new List <StudentMessage>(); foreach (var st in studentMessages) { if (st.student_id.Equals(fac.Mail)) { messages.Add(st); } } return(View(messages)); }