public ActionResult BookTeacherHelpTimeSelectOrDelete(TeacherCalendarSelectOrDeleteViewModel bookingTimeViewModel) { ViewBag.Message = "Book Teacher Time."; GetUIDropdownLists(); var viewResult = SetCalendarValues(bookingTimeViewModel); if (ModelState.IsValid) { var setModel = bookingTimeViewModel; if (!string.IsNullOrEmpty(bookingTimeViewModel.Select)) { return(SetCalendarValues(setModel)); } else if (!string.IsNullOrEmpty(bookingTimeViewModel.Delete)) { var viewResult1 = SetCalendarValues(setModel); if (ModelState.IsValid) { var teacherCalendar = _teacherRepository.GetTeacherCalendarByBookingId(bookingTimeViewModel.CalendarBookingId); _teacherRepository.DeleteTeacherCalendarByBooking(teacherCalendar); return(View("SuccessfullCreation")); } return(viewResult1); } } return(viewResult); }
public ActionResult BookTeacherHelpTime(TeacherCalendarUpdateViewModel bookingTimeViewModel) { ViewBag.Message = "Book Teacher Time."; GetUIDropdownLists(); if (ModelState.IsValid) { if (bookingTimeViewModel.Delete != null) { var teacherCalendar = _teacherRepository.GetTeacherCalendarByBookingId(bookingTimeViewModel.CalendarBookingId); _teacherRepository.DeleteTeacherCalendarByBooking(teacherCalendar); return(View("_SuccessfullCreation")); } Teacher teacher = _teacherRepository.GetTeacherByName(User.Identity.Name); Student student = _teacherRepository.GetStudentByName(bookingTimeViewModel.StudentFullName); Subject subject = _teacherRepository.GetSubjectById(bookingTimeViewModel.SubjectId); foreach (var bookingTime in bookingTimeViewModel.BookingTimes) { _teacherRepository.SaveOrUpdateBooking(teacher, student, subject, new BookingTime { BookingTimeId = bookingTime.BookingTimeId, StartTime = DateTime.Parse(bookingTime.StartTime, new DateTimeFormatInfo { FullDateTimePattern = "yyyy-MM-dd HH:mm" }), EndTime = DateTime.Parse(bookingTime.EndTime, new DateTimeFormatInfo { FullDateTimePattern = "yyyy-MM-dd HH:mm" }) }, bookingTimeViewModel.Description); } var emailService = new EmailServices.EmailService(ConfigurationManager.AppSettings["smtpServer"], ConfigurationManager.AppSettings["smtpServerUser"], ConfigurationManager.AppSettings["smtpServerPassword"]); var emailMessage = new System.Net.Mail.MailMessage(); var fileInfo = new FileInfo(Server.MapPath("~/Infrastructure/EmailTemplates/TeacherBookingTime.html")); var html = fileInfo.OpenText().ReadToEnd(); html.Replace("{TeacherName}", teacher.EmailAddress); html.Replace("{StudentName}", student.EmailAddress); html.Replace("{SubjectName}", subject.SubjectName); html.Replace("{StartTime}", bookingTimeViewModel.BookingTimes[0].StartTime); html.Replace("{EndTime}", bookingTimeViewModel.BookingTimes[0].EndTime); emailService.EmailType = EmailType.Html; //emailService.SendEmail(new TicketMasterEmailMessage {EmailFrom= student.EmailAddress, EmailMessage = html,EmailTo = new List<string> {student.EmailAddress}, Subject = "Teacher Assistant's Booking Time Schedule"}); var message = new TicketMasterEmailMessage { EmailFrom = ConfigurationManager.AppSettings["BusinessEmail"], EmailTo = new List <string> { student.EmailAddress }, Subject = "Teacher Assistant's Booking Time Schedule", EmailMessage = html }; emailService.SendEmail(message); return(View("_SuccessfullCreation")); } return(View("BookTeacherHelpTime", bookingTimeViewModel)); }
public ActionResult BookTeacherHelpTime(TeacherCalendarViewModel bookingTimeViewModel) { ViewBag.Message = "Book Teacher Time."; GetUIDropdownLists(); if (ModelState.IsValid) { if (bookingTimeViewModel.Delete != null) { var teacherCalendar = _teacherRepository.GetTeacherCalendarByBookingId(bookingTimeViewModel.CalendarBookingId); _teacherRepository.DeleteTeacherCalendarByBooking(teacherCalendar); return(View("SuccssessfullCreation")); } Teacher teacher = _teacherRepository.GetTeacherByName(User.Identity.Name); Student student = _teacherRepository.GetStudentByName(bookingTimeViewModel.StudentFullName); Subject subject = _teacherRepository.GetSubjectById(bookingTimeViewModel.SubjectId); foreach (var bookingTime in bookingTimeViewModel.BookingTimes) { _teacherRepository.SaveOrUpdateBooking(teacher, student, subject, bookingTime, bookingTimeViewModel.Description); } return(View("SucssessfullCreation")); } return(View("BookTeacherHelpTime", bookingTimeViewModel)); }
public ActionResult BookTeacherHelpTime(TeacherCalendarViewModel bookingTimeViewModel) { ViewBag.Message = "Book Teacher Time."; GetUIDropdownLists(); if (bookingTimeViewModel.CalendarBookingId < 1) { ModelState.AddModelError("Select", "Calendar BookingId required"); } if (bookingTimeViewModel.Select != null) { if (ModelState.IsValid) { var calendarBookingViewModels = new List <CalendarBookingViewModel>(); var calendar = _teacherRepository.GetTeacherCalendarByBookingId(bookingTimeViewModel.CalendarBookingId); Student student = _teacherRepository.GetStudentById(calendar.StudentId); Subject subject = _teacherRepository.GetSubjectById(calendar.SubjectId); bookingTimeViewModel.StudentId = (int)student.StudentId; bookingTimeViewModel.SubjectId = (int)subject.SubjectId; bookingTimeViewModel.CalendarBookingId = calendar.CalendarBookingId; ModelState.Clear(); var calendars = _teacherRepository.GetTeacherCalendar(); var classRooms = _teacherRepository.GetClassrooms(); var calendarsLeftJoin = from cal in calendars join cls in classRooms on cal.CalendarBookingId equals cls.CalendarId into res from q in res.DefaultIfEmpty() select new { ClassroomId = q == null ? null : q.ClassroomId, SubjectId = cal.SubjectId, TeacherId = cal.TeacherId, StudentId = cal.StudentId, BookingTimeId = cal.BookingTimeId }; if (calendarsLeftJoin != null) { foreach (var cal in calendarsLeftJoin) { student = _teacherRepository.GetStudentById(cal.StudentId); subject = _teacherRepository.GetSubjectById(cal.SubjectId); var teacher = _teacherRepository.GetTeacherById(cal.TeacherId); var bookingTime = _teacherRepository.GetBookingById(cal.BookingTimeId); if (bookingTime == null) { continue; } calendarBookingViewModels.Add(new CalendarBookingViewModel { Teacher = teacher, Subject = subject, Student = student, BookingTime = bookingTime, ClassroomId = cal.ClassroomId }); } } ViewBag.CalendarUiList = calendarBookingViewModels.ToArray(); return(View("BookTeacherHelpTime", bookingTimeViewModel)); } return(View("BookTeacherHelpTime", bookingTimeViewModel)); } if (bookingTimeViewModel.Delete != null) { if (ModelState.IsValid) { var teacherCalendar = _teacherRepository.GetTeacherCalendarByBookingId(bookingTimeViewModel.CalendarBookingId); _teacherRepository.DeleteTeacherCalendarByBooking(teacherCalendar); return(View("SuccessfullCreation")); } return(View("BookTeacherHelpTime", bookingTimeViewModel)); } if (bookingTimeViewModel.SubjectId < 1) { ModelState.AddModelError("Subject", "Subject Id is required"); } if (ModelState.IsValid) { Teacher teacher = _teacherRepository.GetTeacherById(bookingTimeViewModel.TeacherId); Student student = _teacherRepository.GetStudentByName(User.Identity.Name); Subject subject = _teacherRepository.GetSubjectById(bookingTimeViewModel.SubjectId); foreach (var bookingTime in bookingTimeViewModel.BookingTimes) { _teacherRepository.SaveOrUpdateBooking(teacher, student, subject, bookingTime, bookingTimeViewModel.Description); } return(View("SuccessfullCreation")); } return(View("BookTeacherHelpTime", bookingTimeViewModel)); }