//Check if user is participated or not public bool isUserParticipated(string Token, long CourseID) { bool isParticipated = false; try { long UserID = Utility.GetUserIDByToken(Token); if (UserID > 0 && CourseID > 0) { using (ResultatPartnerASEntities dbContext = new ResultatPartnerASEntities()) { CourseParticipant dbUserParticipated = dbContext.CourseParticipants.Where(x => x.CourseID == CourseID && x.UserID == UserID).FirstOrDefault(); if (dbUserParticipated != null && dbUserParticipated.CourseParticipantID > 0) { isParticipated = true; } } } } catch (Exception ex) { LogManager.writelog(ex.Message); } return(isParticipated); }
public static CourseParticipant CreateCourseParticipant(string dataAreaId, string courseId, string personId, global::System.DateTimeOffset registeredDate, global::Microsoft.Dynamics.DataEntities.Person dirPerson, global::Microsoft.Dynamics.DataEntities.CourseTable courseTable) { CourseParticipant courseParticipant = new CourseParticipant(); courseParticipant.dataAreaId = dataAreaId; courseParticipant.CourseId = courseId; courseParticipant.PersonId = personId; courseParticipant.RegisteredDate = registeredDate; if ((dirPerson == null)) { throw new global::System.ArgumentNullException("dirPerson"); } courseParticipant.DirPerson = dirPerson; if ((courseTable == null)) { throw new global::System.ArgumentNullException("courseTable"); } courseParticipant.CourseTable = courseTable; return(courseParticipant); }
// To Participate in Course public bool ParticipateInCourse(string Token, long CourseID) { bool isParticipated = false; try { long UserID = Utility.GetUserIDByToken(Token); if (UserID > 0 && CourseID > 0) { using (ResultatPartnerASEntities dbContext = new ResultatPartnerASEntities()) { CourseParticipant dbUserParticipated = new CourseParticipant(); dbUserParticipated.UserID = UserID; dbUserParticipated.CourseID = CourseID; dbUserParticipated.CreatedDate = DateTime.Now; dbUserParticipated.UpdatedDate = DateTime.Now; dbContext.CourseParticipants.Add(dbUserParticipated); dbContext.SaveChanges(); isParticipated = true; } } } catch (Exception ex) { LogManager.writelog(ex.Message); } return(isParticipated); }
private static Attendee MapCourseParticipantToAttendee(CourseParticipant cp) { string email = cp.Participant.Email; if (!string.IsNullOrEmpty(cp.Participant.AlternateEmail)) { email += "?cc=" + cp.Participant.AlternateEmail; } var uri = new Uri(mailto + email); return(new Attendee(uri) { CommonName = cp.Participant.FullName, Role = "REQ-PARTICIPANT", Rsvp = false, ParticipationStatus = cp.IsConfirmed.HasValue ? cp.IsConfirmed.Value ? EventParticipationStatus.Accepted : EventParticipationStatus.Declined : EventParticipationStatus.Tentative }); }
// Get Course Details By ID public UserParticipatedCourse GetUserParticipatedCourseByID(string Token, long CourseID) { UserParticipatedCourse _Course = new UserParticipatedCourse(); try { long UserID = Utility.GetUserIDByToken(Token); if (UserID > 0 && CourseID > 0) { using (ResultatPartnerASEntities dbContext = new ResultatPartnerASEntities()) { Cours dbCourse = dbContext.Courses.Where(x => x.CourseID == CourseID).FirstOrDefault(); if (dbCourse != null && dbCourse.CourseID > 0) { _Course.Course = new CourseModel(); _Course.Course.CourseID = dbCourse.CourseID; _Course.Course.CourseName = dbCourse.CourseName; _Course.Course.CourseDescription = dbCourse.CourseDescription; } CourseParticipant dbCourseParticipant = dbContext.CourseParticipants.Where(x => x.CourseID == CourseID && x.UserID == UserID).FirstOrDefault(); if (dbCourseParticipant != null && dbCourseParticipant.CourseParticipantID > 0) { _Course.Participated = true; } else { _Course.Participated = false; } } } } catch (Exception ex) { LogManager.writelog(ex.Message); } return(_Course); }
public void AddStudentToCourse(CourseParticipant student) { this.studentsInCourse.Add(student); }
public void ExecuteCreate(string[] commandWords) { string[] cW = commandWords; switch (cW[1]) { case "course_participant": Person courseParticipant = new CourseParticipant(cW[2], cW[3], cW[4], cW[5], this.ConvertStrintIntoDateTime(cW[6]), cW[7], cW[8], cW[9], cW[10], this.ConvertStrintIntoDateTime(cW[11]), ESallaryType.Monthly, decimal.Parse(cW[13])); this.ExecuteAdd(courseParticipant); break; case "teacher": Person teacher = new Teacher(cW[2], cW[3], cW[4], cW[5], this.ConvertStrintIntoDateTime(cW[6]), cW[7], cW[8], cW[9], cW[10], this.ConvertStrintIntoDateTime(cW[11]), ESallaryType.Monthly, decimal.Parse(cW[13])); this.ExecuteAdd(teacher); break; case "secretary": Person secretary = new Secretary(cW[2], cW[3], cW[4], cW[5], this.ConvertStrintIntoDateTime(cW[6]), cW[7], cW[8], cW[9], cW[10], this.ConvertStrintIntoDateTime(cW[11]), ESallaryType.Monthly, decimal.Parse(cW[13])); this.ExecuteAdd(secretary); break; case "adult_language_course": string courseName = CourseInputer.CourseNameCreator(cW[2]); ECourseActivityStatus status = CourseInputer.CourseActivityCreator(cW[3]); EGroupType groupType = CourseInputer.GroupTypeCreator(cW[4]); ECoursePlace coursePlace = cW[5] == "local" ? ECoursePlace.Local : ECoursePlace.Online; decimal coursePrice = decimal.Parse(cW[6]); IList <IPerson> coursists = CourseInputer.GetCoursistsInCourse(cW[7]); IList <IPerson> teachers = CourseInputer.GetTeachersInCourse(cW[8]); IList <IClassInfo> conductedClasses = new List <IClassInfo>(); EAge age = EAge.Adults; ELanguage language = CourseInputer.GetLanguage(cW[11]); ELanguageLevelForAdults level = CourseInputer.LanguageLevelAdults("a1"); LanguageCourseForAdults languageCourseAdults = new LanguageCourseForAdults(courseName, status, groupType, coursePlace, coursePrice, coursists, teachers, conductedClasses, age, language, level); Course.Add(languageCourseAdults); break; case "class": ICourse courseToAddToClass = null; ulong courseId = ulong.Parse(cW[5].Split('_')[1]); foreach (var currentCourse in Course.CourseList) { if (currentCourse.Id == courseId) { courseToAddToClass = currentCourse; } } ITeacher teacherToAddToClass = null; ulong teacherId = ulong.Parse(cW[6].Split('_')[1]); foreach (var currentTeacher in Person.GetAllTeachers()) { if (currentTeacher.Id == teacherId) { teacherToAddToClass = (ITeacher)currentTeacher; } } string[] conductionDateString = cW[2].Split('_')[1].Split('.'); int conductionDateYear = int.Parse(conductionDateString[2]); int conductionDateMonth = int.Parse(conductionDateString[1]); int conductionDateDay = int.Parse(conductionDateString[0]); DateTime conductionDate = new DateTime(conductionDateYear, conductionDateMonth, conductionDateDay); string[] startHourStringArray = cW[3].Split('_')[2].Split(':'); int startHourHour = int.Parse(startHourStringArray[0]); int startHourMinutes = int.Parse(startHourStringArray[1]); DateTime startHour = new DateTime(conductionDateYear, conductionDateMonth, conductionDateDay, startHourHour, startHourMinutes, 0); string[] endHourStringArray = cW[4].Split('_')[2].Split(':'); int endHourHour = int.Parse(endHourStringArray[0]); int endHourMinutes = int.Parse(endHourStringArray[1]); DateTime endHour = new DateTime(conductionDateYear, conductionDateMonth, conductionDateDay, endHourHour, endHourMinutes, 0); ClassInfo currentClass = new ClassInfo(conductionDate, startHour, endHour, teacherToAddToClass, courseToAddToClass); bool presentTeacher = false; foreach (var teacherInCourse in courseToAddToClass.TeachersInCourse) { if (teacherInCourse.Id == teacherToAddToClass.Id) { presentTeacher = true; break; } } if (presentTeacher == true) { courseToAddToClass.AddConductedClass(currentClass); } else { throw new ArgumentException(String.Format("There's no teacher with ID {0} who conducts classes in the course with ID {1}", teacherToAddToClass.Id, courseToAddToClass.Id)); } break; default: break; } }
public ActionResult SubmitParticipant(CourseParticipant courseParticipant) { if (ModelState.IsValid) { /* add course to student */ var id = Session["ID"].ToString(); /* change or add grade */ using (CoursesDal coursesDb = new CoursesDal()) using (ExamsDal exmaDb = new ExamsDal()) using (UsersDal usersDb = new UsersDal()) using (GradesDal gradesDb = new GradesDal()) using (CourseParticipantsDal courseParticipantDb = new CourseParticipantsDal()) { /* check course exist */ var courseId = coursesDb.Courses.Where(Course => Course.courseId.Equals(courseParticipant.courseId)).FirstOrDefault(); if (courseId == null) { TempData["msg"] = "Invalid course ID"; return(View("ManageCourseParticipants", courseParticipant)); } /* check if student exist */ var student = (from row in usersDb.Users where row.ID.Equals(courseParticipant.ID) && row.type.Equals("Student") select row).FirstOrDefault(); if (student == null) { TempData["msg"] = "Student doesnt exist"; return(View("ManageCourseParticipants", courseParticipant)); } /* check if student takes this course */ var studentTakesCourse = (from row in courseParticipantDb.CourseParticipants where row.ID.Equals(courseParticipant.ID) && row.courseId.Equals(courseParticipant.courseId) select row).FirstOrDefault(); if (studentTakesCourse != null) { TempData["msg"] = "Student takes this course"; return(View("ManageCourseParticipants", courseParticipant)); } /* course time doesnt clashes with student courses */ var studentCourses = (from row in courseParticipantDb.CourseParticipants where row.ID.Equals(courseParticipant.ID) select row.courseId).ToList(); var courses = (from row in coursesDb.Courses where studentCourses.Contains(row.courseId) select row).ToList(); foreach (Course x in courses) { if (x.startTime < courseId.endTime && courseId.startTime < x.endTime && x.day.Equals(courseId.day)) { TempData["msg"] = "Course time clashes with student schedule"; return(View("ManageCourseParticipants", courseParticipant)); } } /* add course to student */ courseParticipantDb.CourseParticipants.Add(courseParticipant); courseParticipantDb.SaveChanges(); } TempData["goodMsg"] = "Inserted\\updated grade"; /* redirect with succsees message */ return(View("ManageCourseParticipants", new CourseParticipant())); } else { return(View("ManageCourseParticipants", courseParticipant)); } }
public void ExecuteCreate(string[] commandWords) { string[] cW = commandWords; switch (cW[1]) { case "course_participant": Person courseParticipant = new CourseParticipant(cW[2], cW[3], cW[4], cW[5], this.ConvertStrintIntoDateTime(cW[6]), cW[7], cW[8], cW[9], cW[10], this.ConvertStrintIntoDateTime(cW[11]), ESallaryType.Monthly, decimal.Parse(cW[13])); this.ExecuteAdd(courseParticipant); break; case "teacher": Person teacher = new Teacher(cW[2], cW[3], cW[4], cW[5], this.ConvertStrintIntoDateTime(cW[6]), cW[7], cW[8], cW[9], cW[10], this.ConvertStrintIntoDateTime(cW[11]), ESallaryType.Monthly, decimal.Parse(cW[13])); this.ExecuteAdd(teacher); break; case "secretary": Person secretary = new Secretary(cW[2], cW[3], cW[4], cW[5], this.ConvertStrintIntoDateTime(cW[6]), cW[7], cW[8], cW[9], cW[10], this.ConvertStrintIntoDateTime(cW[11]), ESallaryType.Monthly, decimal.Parse(cW[13])); this.ExecuteAdd(secretary); break; case "adult_language_course": string courseName = CourseInputer.CourseNameCreator(cW[2]); ECourseActivityStatus status = CourseInputer.CourseActivityCreator(cW[3]); EGroupType groupType = CourseInputer.GroupTypeCreator(cW[4]); ECoursePlace coursePlace = cW[5] == "local" ? ECoursePlace.Local : ECoursePlace.Online; decimal coursePrice = decimal.Parse(cW[6]); IList<IPerson> coursists = CourseInputer.GetCoursistsInCourse(cW[7]); IList<IPerson> teachers = CourseInputer.GetTeachersInCourse(cW[8]); IList<IClassInfo> conductedClasses = new List<IClassInfo>(); EAge age = EAge.Adults; ELanguage language = CourseInputer.GetLanguage(cW[11]); ELanguageLevelForAdults level = CourseInputer.LanguageLevelAdults("a1"); LanguageCourseForAdults languageCourseAdults = new LanguageCourseForAdults(courseName, status, groupType, coursePlace, coursePrice, coursists, teachers, conductedClasses, age, language, level); Course.Add(languageCourseAdults); break; case "class": ICourse courseToAddToClass = null; ulong courseId = ulong.Parse(cW[5].Split('_')[1]); foreach (var currentCourse in Course.CourseList) { if (currentCourse.Id == courseId) { courseToAddToClass = currentCourse; } } ITeacher teacherToAddToClass = null; ulong teacherId = ulong.Parse(cW[6].Split('_')[1]); foreach (var currentTeacher in Person.GetAllTeachers()) { if (currentTeacher.Id == teacherId) { teacherToAddToClass = (ITeacher)currentTeacher; } } string[] conductionDateString = cW[2].Split('_')[1].Split('.'); int conductionDateYear = int.Parse(conductionDateString[2]); int conductionDateMonth = int.Parse(conductionDateString[1]); int conductionDateDay = int.Parse(conductionDateString[0]); DateTime conductionDate = new DateTime(conductionDateYear, conductionDateMonth, conductionDateDay); string[] startHourStringArray = cW[3].Split('_')[2].Split(':'); int startHourHour = int.Parse(startHourStringArray[0]); int startHourMinutes = int.Parse(startHourStringArray[1]); DateTime startHour = new DateTime(conductionDateYear, conductionDateMonth, conductionDateDay, startHourHour, startHourMinutes, 0); string[] endHourStringArray = cW[4].Split('_')[2].Split(':'); int endHourHour = int.Parse(endHourStringArray[0]); int endHourMinutes = int.Parse(endHourStringArray[1]); DateTime endHour = new DateTime(conductionDateYear, conductionDateMonth, conductionDateDay, endHourHour, endHourMinutes, 0); ClassInfo currentClass = new ClassInfo(conductionDate, startHour, endHour, teacherToAddToClass, courseToAddToClass); bool presentTeacher = false; foreach (var teacherInCourse in courseToAddToClass.TeachersInCourse) { if(teacherInCourse.Id == teacherToAddToClass.Id) { presentTeacher = true; break; } } if (presentTeacher == true) { courseToAddToClass.AddConductedClass(currentClass); } else { throw new ArgumentException(String.Format("There's no teacher with ID {0} who conducts classes in the course with ID {1}", teacherToAddToClass.Id, courseToAddToClass.Id)); } break; default: break; } }
public void AddStudentToCourse(CourseParticipant student) { this.studentsInCourse.Add(student); }
public async Task <IHttpActionResult> Rsvp(RsvpBindingModel model) { var find = model.Auth.HasValue ? new[] { model.Auth.Value, model.ParticipantId } : new[] { model.ParticipantId }; var cps = await Repo.CourseParticipants.Include("Participant").Include("Course") .Where(cp => cp.CourseId == model.CourseId && find.Contains(cp.ParticipantId)).ToListAsync(); var part = cps.First(cp => cp.ParticipantId == model.ParticipantId); TimeSpan timeToStart = part.Course.StartParticipantUtc() - DateTime.UtcNow; string purpose = CreateParticipantEmails.InvitePurpose(model.CourseId); var verification = model.Auth.HasValue ? UserManager.VerifyUserTokenAsync(model.Auth.Value, purpose, model.Token, timeToStart) : UserManager.VerifyUserTokenAsync(model.ParticipantId, purpose, model.Token, timeToStart); if (!await verification) { return(Unauthorized()); } CourseParticipant auth = null; if (model.Auth.HasValue) { auth = cps.First(cp => cp.ParticipantId == model.Auth && cp.IsOrganiser); } if (part.Course.StartFacultyUtc < DateTime.UtcNow) { return(Ok("Confirmation status cannot be changed after the course has commenced.")); } string userName = part.Participant.FullName; var returnString = "registered as " + (model.IsAttending ? "attending" : "unable to attend"); if (model.IsAttending == part.IsConfirmed && !model.Auth.HasValue) { return(Ok(userName + " is already " + returnString)); } if (model.Auth.HasValue) { bool wasConfirmed = part.IsConfirmed.Value; part.IsConfirmed = model.IsAttending; await Repo.SaveChangesAsync(); using (var client = new SmtpClient()) { using (var mail = new MailMessage()) { mail.To.AddParticipants(part.Participant); mail.CC.AddParticipants((from cp in part.Course.CourseParticipants where cp.IsOrganiser select cp.Participant).ToArray()); var confirmEmail = new AuthConfirmationResult { CourseParticipant = part, Auth = auth.Participant, IsChanged = wasConfirmed != model.IsAttending }; mail.CreateHtmlBody(confirmEmail); await client.SendMailAsync(mail); } } return(Ok(userName + " is now " + returnString + ". A confirmation email has been sent, with copies to the course organisers.")); } if (!part.IsConfirmed.HasValue || part.IsOrganiser) { part.IsConfirmed = model.IsAttending; await Repo.SaveChangesAsync(); return(Ok(userName + " is now " + returnString)); } using (var client = new SmtpClient()) { foreach (var org in part.Course.CourseParticipants.Where(p => p.IsOrganiser)) { using (var mail = new MailMessage()) { mail.To.AddParticipants(org.Participant); var confirmEmail = new ReverseConfirmation { OrganiserId = org.ParticipantId, Token = await UserManager.GenerateUserTokenAsync(purpose, org.ParticipantId), CourseParticipant = part }; mail.CreateHtmlBody(confirmEmail); await client.SendMailAsync(mail); } } } return(Ok(userName + " had been confirmed as " + (part.IsConfirmed.Value ? "attending" : "not attending") + ", but would like to change to being " + returnString + ". An email has been sent to the course organiser(s), who will be able to confirm this change.")); }