/// <summary> /// Delete Student Schedule Report /// </summary> /// <param name="studentCourseSectionScheduleAddViewModel"></param> /// <returns></returns> public StudentCourseSectionScheduleAddViewModel DeleteStudentScheduleReport(StudentCourseSectionScheduleAddViewModel studentCourseSectionScheduleAddViewModel) { try { var studentScheduleViewData = this.context?.StudentScheduleView.Where(e => e.SchoolId == studentCourseSectionScheduleAddViewModel.SchoolId && e.TenantId == studentCourseSectionScheduleAddViewModel.TenantId).ToList(); if (studentScheduleViewData.Count > 0) { this.context?.StudentScheduleView.RemoveRange(studentScheduleViewData); this.context?.SaveChanges(); studentCourseSectionScheduleAddViewModel._failure = false; studentCourseSectionScheduleAddViewModel._message = "Student Schedule Report Deleted Successfully"; } else { studentCourseSectionScheduleAddViewModel._message = NORECORDFOUND; studentCourseSectionScheduleAddViewModel._failure = true; } } catch (Exception es) { studentCourseSectionScheduleAddViewModel._failure = true; studentCourseSectionScheduleAddViewModel._message = es.Message; } return(studentCourseSectionScheduleAddViewModel); }
public ActionResult <StudentCourseSectionScheduleAddViewModel> DeleteStudentScheduleReport(StudentCourseSectionScheduleAddViewModel studentCourseSectionScheduleAddViewModel) { StudentCourseSectionScheduleAddViewModel StudentCourseSectionScheduleDelete = new StudentCourseSectionScheduleAddViewModel(); try { StudentCourseSectionScheduleDelete = _studentScheduleService.DeleteStudentScheduleReport(studentCourseSectionScheduleAddViewModel); } catch (Exception es) { StudentCourseSectionScheduleDelete._failure = true; StudentCourseSectionScheduleDelete._message = es.Message; } return(StudentCourseSectionScheduleDelete); }
public ActionResult <StudentCourseSectionScheduleAddViewModel> AddStudentCourseSectionSchedule(StudentCourseSectionScheduleAddViewModel studentCourseSectionScheduleAddViewModel) { StudentCourseSectionScheduleAddViewModel StudentCourseSectionScheduleAddModel = new StudentCourseSectionScheduleAddViewModel(); try { StudentCourseSectionScheduleAddModel = _studentScheduleService.AddStudentCourseSectionSchedule(studentCourseSectionScheduleAddViewModel); } catch (Exception es) { StudentCourseSectionScheduleAddModel._failure = true; StudentCourseSectionScheduleAddModel._message = es.Message; } return(StudentCourseSectionScheduleAddModel); }
/// <summary> /// Add Student Course Section Schedule /// </summary> /// <param name="studentCourseSectionScheduleAddViewModel"></param> /// <returns></returns> public StudentCourseSectionScheduleAddViewModel AddStudentCourseSectionSchedule(StudentCourseSectionScheduleAddViewModel studentCourseSectionScheduleAddViewModel) { StudentCourseSectionScheduleAddViewModel studentCourseSectionScheduleAddModel = new StudentCourseSectionScheduleAddViewModel(); try { if (TokenManager.CheckToken(studentCourseSectionScheduleAddViewModel._tenantName + studentCourseSectionScheduleAddViewModel._userName, studentCourseSectionScheduleAddViewModel._token)) { studentCourseSectionScheduleAddModel = this.studentScheduleRepository.AddStudentCourseSectionSchedule(studentCourseSectionScheduleAddViewModel); } else { studentCourseSectionScheduleAddModel._failure = true; studentCourseSectionScheduleAddModel._message = TOKENINVALID; } } catch (Exception es) { studentCourseSectionScheduleAddModel._failure = true; studentCourseSectionScheduleAddModel._message = es.Message; } return(studentCourseSectionScheduleAddModel); }
/// <summary> /// Add Student Course Section Schedule /// </summary> /// <param name="studentCourseSectionScheduleAddViewModel"></param> /// <returns></returns> public StudentCourseSectionScheduleAddViewModel AddStudentCourseSectionSchedule(StudentCourseSectionScheduleAddViewModel studentCourseSectionScheduleAddViewModel) { using (var transaction = this.context.Database.BeginTransaction()) { try { string conflictMessage = "All Student Scheduled Successfully"; if (studentCourseSectionScheduleAddViewModel.courseSectionList.Count > 0) { int restSeats = 0; List <StudentMaster> studentData = null; foreach (var courseSection in studentCourseSectionScheduleAddViewModel.courseSectionList) { var studentCourseSectionScheduleData = this.context?.StudentCoursesectionSchedule.Where(c => c.SchoolId == courseSection.SchoolId && c.TenantId == courseSection.TenantId && c.CourseSectionId == courseSection.CourseSectionId && c.AcademicYear == courseSection.AcademicYear).ToList(); if (studentCourseSectionScheduleData.Count > 0) { restSeats = (int)courseSection.Seats - studentCourseSectionScheduleData.Count; } else { restSeats = (int)courseSection.Seats; } if (restSeats > 0) { if (studentCourseSectionScheduleAddViewModel.studentMasterList.Count > 0) { if (restSeats < studentCourseSectionScheduleAddViewModel.studentMasterList.Count) { studentData = studentCourseSectionScheduleAddViewModel.studentMasterList.Take(restSeats).ToList(); if (studentData.Count > 0) { var restStudentCount = studentCourseSectionScheduleAddViewModel.studentMasterList.Count - studentData.Count; if (restStudentCount > 0) { var restStudentList = studentCourseSectionScheduleAddViewModel.studentMasterList.TakeLast(restStudentCount).ToList(); if (restStudentList.Count > 0) { foreach (var restStudent in restStudentList) { var conflictStudent = new StudentScheduleView() { TenantId = restStudent.TenantId, SchoolId = restStudent.SchoolId, StudentId = restStudent.StudentId, CourseId = courseSection.CourseId, CourseSectionId = courseSection.CourseSectionId, CourseSectionName = courseSection.CourseSectionName, StudentInternalId = restStudent.StudentInternalId, StudentName = restStudent.FirstGivenName + " " + restStudent.MiddleName + " " + restStudent.LastFamilyName, Scheduled = false, ConflictComment = "Seats Not Avalaible" }; this.context?.StudentScheduleView.Add(conflictStudent); conflictMessage = "Some Student could not be scheduled due to conflicts. Please find the detailed report below."; } } } } } else { studentData = studentCourseSectionScheduleAddViewModel.studentMasterList.ToList(); } if (studentData.Count > 0) { foreach (var student in studentData) { var studentCourseSectionSchedule = this.context?.StudentCoursesectionSchedule.FirstOrDefault(c => c.SchoolId == student.SchoolId && c.TenantId == student.TenantId && c.StudentId == student.StudentId && c.CourseSectionId == courseSection.CourseSectionId && c.AcademicYear == courseSection.AcademicYear); if (studentCourseSectionSchedule != null) { var conflictStudent = new StudentScheduleView() { TenantId = student.TenantId, SchoolId = student.SchoolId, StudentId = student.StudentId, CourseId = courseSection.CourseId, CourseSectionId = courseSection.CourseSectionId, CourseSectionName = courseSection.CourseSectionName, StudentInternalId = student.StudentInternalId, StudentName = student.FirstGivenName + " " + student.MiddleName + " " + student.LastFamilyName, Scheduled = false, ConflictComment = "Student is already scheduled in the course section" }; this.context.StudentScheduleView.Add(conflictStudent); conflictMessage = "Some Student could not be scheduled due to conflicts. Please find the detailed report below."; } else { var courseSectionAllData = this.context?.AllCourseSectionView.Where(c => c.TenantId == courseSection.TenantId && c.SchoolId == courseSection.SchoolId && c.CourseSectionId == courseSection.CourseSectionId).ToList(); if (courseSectionAllData.FirstOrDefault().AllowStudentConflict == true) { var studentCourseScheduling = new StudentCoursesectionSchedule() { TenantId = courseSection.TenantId, SchoolId = courseSection.SchoolId, StudentId = student.StudentId, CourseId = courseSection.CourseId, CourseSectionId = courseSection.CourseSectionId, StudentGuid = student.StudentGuid, AlternateId = student.AlternateId, StudentInternalId = student.StudentInternalId, FirstGivenName = student.FirstGivenName, MiddleName = student.MiddleName, LastFamilyName = student.LastFamilyName, FirstLanguageId = student.FirstLanguageId, GradeId = student.StudentEnrollment.FirstOrDefault().GradeId, AcademicYear = (decimal)courseSection.AcademicYear, GradeScaleId = courseSection.GradeScaleId, CourseSectionName = courseSection.CourseSectionName, CalendarId = courseSection.CalendarId, CreatedBy = studentCourseSectionScheduleAddViewModel.CreatedBy, CreatedOn = DateTime.UtcNow }; this.context.StudentCoursesectionSchedule.Add(studentCourseScheduling); var conflictStudent = new StudentScheduleView() { TenantId = student.TenantId, SchoolId = student.SchoolId, StudentId = student.StudentId, CourseId = courseSection.CourseId, CourseSectionId = courseSection.CourseSectionId, CourseSectionName = courseSection.CourseSectionName, StudentInternalId = student.StudentInternalId, StudentName = student.FirstGivenName + " " + student.MiddleName + " " + student.LastFamilyName, Scheduled = true, }; this.context?.StudentScheduleView.Add(conflictStudent); } else { //var courseSectionAllData = this.context?.AllCourseSectionView.Where(c => c.TenantId == courseSection.TenantId && c.SchoolId == courseSection.SchoolId && c.CourseSectionId == courseSection.CourseSectionId).ToList(); if (courseSectionAllData.Count > 0) { bool isPeriodConflict = false; foreach (var courseSectionAll in courseSectionAllData) { var courseSectionData = this.context?.AllCourseSectionView. Join(this.context?.StudentCoursesectionSchedule, acsv => acsv.CourseSectionId, scs => scs.CourseSectionId, (acsv, scs) => new { acsv, scs }).AsEnumerable().Where(x => x.scs.SchoolId == courseSection.SchoolId && x.scs.StudentId == student.StudentId && x.acsv.DurationEndDate > courseSectionAll.DurationStartDate && ( courseSectionAll.FixedPeriodId != null && ((x.acsv.FixedPeriodId == courseSectionAll.FixedPeriodId || x.acsv.VarPeriodId == courseSectionAll.FixedPeriodId || x.acsv.CalPeriodId == courseSectionAll.FixedPeriodId) && ((x.acsv.FixedDays != null && (Regex.IsMatch(courseSectionAll.FixedDays.ToLower(), x.acsv.FixedDays.ToLower(), RegexOptions.IgnoreCase))) || (x.acsv.VarDay != null && (courseSectionAll.FixedDays.ToLower().Contains(x.acsv.VarDay.ToLower()))) || (x.acsv.CalDay != null && (courseSectionAll.FixedDays.ToLower().Contains(x.acsv.CalDay.ToLower()))))) || courseSectionAll.VarPeriodId != null && ((x.acsv.FixedPeriodId == courseSectionAll.VarPeriodId || x.acsv.VarPeriodId == courseSectionAll.VarPeriodId || x.acsv.CalPeriodId == courseSectionAll.VarPeriodId) && ((x.acsv.FixedDays != null && (Regex.IsMatch(courseSectionAll.VarDay.ToLower(), x.acsv.FixedDays.ToLower(), RegexOptions.IgnoreCase))) || (x.acsv.VarDay != null && (courseSectionAll.VarDay.ToLower().Contains(x.acsv.VarDay.ToLower()))) || (x.acsv.CalDay != null && (courseSectionAll.VarDay.ToLower().Contains(x.acsv.CalDay.ToLower()))))) || courseSectionAll.CalPeriodId != null && ((x.acsv.FixedPeriodId == courseSectionAll.CalPeriodId || x.acsv.VarPeriodId == courseSectionAll.CalPeriodId || x.acsv.CalPeriodId == courseSectionAll.CalPeriodId) && ((x.acsv.FixedDays != null && (Regex.IsMatch(courseSectionAll.CalDay.ToLower(), x.acsv.FixedDays.ToLower(), RegexOptions.IgnoreCase))) || (x.acsv.VarDay != null && (courseSectionAll.CalDay.ToLower().Contains(x.acsv.VarDay.ToLower()))) || (x.acsv.CalDay != null && (courseSectionAll.CalDay.ToLower().Contains(x.acsv.CalDay.ToLower()))))) ) ); if (courseSectionData.ToList().Count > 0) { isPeriodConflict = true; break; } } if (!(bool)isPeriodConflict) { var studentCourseScheduling = new StudentCoursesectionSchedule() { TenantId = courseSection.TenantId, SchoolId = courseSection.SchoolId, StudentId = student.StudentId, CourseId = courseSection.CourseId, CourseSectionId = courseSection.CourseSectionId, StudentGuid = student.StudentGuid, AlternateId = student.AlternateId, StudentInternalId = student.StudentInternalId, FirstGivenName = student.FirstGivenName, MiddleName = student.MiddleName, LastFamilyName = student.LastFamilyName, FirstLanguageId = (int)student.FirstLanguageId, GradeId = student.StudentEnrollment.FirstOrDefault().GradeId, AcademicYear = (decimal)courseSection.AcademicYear, GradeScaleId = courseSection.GradeScaleId, CourseSectionName = courseSection.CourseSectionName, CalendarId = courseSection.CalendarId, CreatedBy = studentCourseSectionScheduleAddViewModel.CreatedBy, CreatedOn = DateTime.UtcNow }; this.context?.StudentCoursesectionSchedule.Add(studentCourseScheduling); var conflictStudent = new StudentScheduleView() { TenantId = student.TenantId, SchoolId = student.SchoolId, StudentId = student.StudentId, CourseId = courseSection.CourseId, CourseSectionId = courseSection.CourseSectionId, CourseSectionName = courseSection.CourseSectionName, StudentInternalId = student.StudentInternalId, StudentName = student.FirstGivenName + " " + student.MiddleName + " " + student.LastFamilyName, Scheduled = true, }; this.context?.StudentScheduleView.Add(conflictStudent); } else { var conflictStudent = new StudentScheduleView() { TenantId = student.TenantId, SchoolId = student.SchoolId, StudentId = student.StudentId, CourseId = courseSection.CourseId, CourseSectionId = courseSection.CourseSectionId, CourseSectionName = courseSection.CourseSectionName, StudentInternalId = student.StudentInternalId, StudentName = student.FirstGivenName + " " + student.MiddleName + " " + student.LastFamilyName, Scheduled = false, ConflictComment = "There is a period conflict" }; this.context?.StudentScheduleView.Add(conflictStudent); conflictMessage = "Some Student could not be scheduled due to conflicts. Please find the detailed report below."; } } else { studentCourseSectionScheduleAddViewModel._failure = true; studentCourseSectionScheduleAddViewModel._message = "Course Section Does Not Exist"; } } } } } } else { studentCourseSectionScheduleAddViewModel._message = "Select Atleast One Student"; studentCourseSectionScheduleAddViewModel._failure = true; studentCourseSectionScheduleAddViewModel.ConflictMessage = null; return(studentCourseSectionScheduleAddViewModel); } } else { if (studentCourseSectionScheduleAddViewModel.studentMasterList.Count > 0) { foreach (var studentMaster in studentCourseSectionScheduleAddViewModel.studentMasterList) { var conflictStudent = new StudentScheduleView() { TenantId = studentMaster.TenantId, SchoolId = studentMaster.SchoolId, StudentId = studentMaster.StudentId, CourseId = courseSection.CourseId, CourseSectionId = courseSection.CourseSectionId, CourseSectionName = courseSection.CourseSectionName, StudentInternalId = studentMaster.StudentInternalId, StudentName = studentMaster.FirstGivenName + " " + studentMaster.MiddleName + " " + studentMaster.LastFamilyName, Scheduled = false, ConflictComment = "Seats Not Avalaible" }; this.context?.StudentScheduleView.Add(conflictStudent); conflictMessage = "Some Student could not be scheduled due to conflicts. Please find the detailed report below."; } } } } var studentScheduleViewData = this.context?.StudentScheduleView.Where(e => e.SchoolId == studentCourseSectionScheduleAddViewModel.SchoolId && e.TenantId == studentCourseSectionScheduleAddViewModel.TenantId).ToList(); if (studentScheduleViewData.Count > 0) { this.context?.StudentScheduleView.RemoveRange(studentScheduleViewData); } this.context?.SaveChanges(); transaction.Commit(); studentCourseSectionScheduleAddViewModel._message = "Student Schedule Added Successfully"; studentCourseSectionScheduleAddViewModel.ConflictMessage = conflictMessage; studentCourseSectionScheduleAddViewModel._failure = false; } else { studentCourseSectionScheduleAddViewModel._message = "Select Atleast One Course Section"; studentCourseSectionScheduleAddViewModel.ConflictMessage = null; studentCourseSectionScheduleAddViewModel._failure = true; return(studentCourseSectionScheduleAddViewModel); } } catch (Exception es) { transaction.Rollback(); studentCourseSectionScheduleAddViewModel._failure = true; studentCourseSectionScheduleAddViewModel.ConflictMessage = null; studentCourseSectionScheduleAddViewModel._message = es.Message; } } return(studentCourseSectionScheduleAddViewModel); }