public static List <TeacherStudentCategory> InitializeStudentCategory(List <StudentCategory> studentCategories) { try { List <TeacherStudentCategory> teacherStudentCategories = new List <TeacherStudentCategory>(); for (int i = 0; i < studentCategories.Count; i++) { TeacherStudentCategory teacherStudentCategory = new TeacherStudentCategory(); teacherStudentCategory.StudentCategory = studentCategories[i]; teacherStudentCategory.IsSelected = false; teacherStudentCategories.Add(teacherStudentCategory); } return(teacherStudentCategories); } catch (Exception) { throw; } }
public ActionResult CostImplication(long tid, long epid) { try { _viewModel = new Models.RequestViewModel(); int highestQualificationId = 0; _viewModel.Periods = _da.GetAll <Period, PERIOD>(); _viewModel.WeekDays = _da.GetAll <WeekDay, WEEK_DAY>(); _viewModel.EmployerStudentCategories = _da.GetModelsBy <EmployerStudentCategory, EMPLOYER_STUDENT_CATEGORY>(esc => esc.Person_Id == epid); _viewModel.TeacherStudentCategories = _da.GetModelsBy <TeacherStudentCategory, TEACHER_STUDENT_CATEGORY>(tsc => tsc.Person_Id == tid); List <TeacherEducationalQualification> educationalQualifications = _da.GetModelsBy <TeacherEducationalQualification, TEACHER_EDUCATIONAL_QUALIFICATION>(x => x.Person_Id == tid); if (educationalQualifications != null && educationalQualifications.Count > 0) { highestQualificationId = educationalQualifications.Max(eq => eq.Qualification.Category.Id); } if (_viewModel.Periods != null && _viewModel.Periods.Count > 0) { _viewModel.WeekDays.Insert(0, new WeekDay()); } if (_viewModel.WeekDays != null && _viewModel.WeekDays.Count > 0) { _viewModel.Periods.Insert(0, new Period()); } Person person = new Person() { Id = tid }; List <TeacherAvailability> teacherAvailabilities = _da.GetModelsBy <TeacherAvailability, TEACHER_AVAILABILITY>(ta => ta.Person_Id == tid); _viewModel.Teacher = _teacherFinder.GetBy(person); _viewModel.RequestCostImplications = new List <RequestForEmploymentCostImplication>(); if (_viewModel.EmployerStudentCategories != null && _viewModel.EmployerStudentCategories.Count > 0) { _viewModel.Employer = _viewModel.EmployerStudentCategories[0].Person; foreach (EmployerStudentCategory employerStudentCategory in _viewModel.EmployerStudentCategories) { RequestForEmploymentCostImplication requestCostImplication = new RequestForEmploymentCostImplication(); TeachingCost teachingCost = _da.GetModelBy <TeachingCost, TEACHING_COST>(tc => tc.Qualification_Category_Id == highestQualificationId && tc.Student_Category_Id == employerStudentCategory.StudentCategory.Id); TeacherStudentCategory teacherStudentCategory = _viewModel.TeacherStudentCategories.Where(sc => sc.StudentCategory.Id == employerStudentCategory.StudentCategory.Id).SingleOrDefault(); if (teacherStudentCategory != null && teacherStudentCategory.Id > 0) { List <TeacherAvailability> teacherPeriodsAvailable = UiUtility.InitializeAvailability(_viewModel.WeekDays, _viewModel.Periods); requestCostImplication.EmployerStudentCategory = employerStudentCategory; List <RequestForEmploymentTeacherAvailability> requestForEmploymentTeacherAvailabilities = new List <RequestForEmploymentTeacherAvailability>(); if (teacherPeriodsAvailable != null && teacherPeriodsAvailable.Count > 0) { decimal totalCost = 0; foreach (TeacherAvailability teacherAvailability in teacherPeriodsAvailable) { TeacherAvailability availability = teacherAvailabilities.Where(x => x.WeekDay.Id == teacherAvailability.WeekDay.Id && x.Period.Id == teacherAvailability.Period.Id).SingleOrDefault(); RequestForEmploymentTeacherAvailability requestForEmploymentTeacherAvailability = new RequestForEmploymentTeacherAvailability(); if (availability != null && availability.Id > 0) { requestForEmploymentTeacherAvailability.TeacherAvailability = availability; requestForEmploymentTeacherAvailability.TeacherAvailability.IsAvailable = true; if (teachingCost != null) { totalCost += teachingCost.Amount; requestForEmploymentTeacherAvailability.TeachingCost = teachingCost; } } else { requestForEmploymentTeacherAvailability.TeacherAvailability = new TeacherAvailability(); requestForEmploymentTeacherAvailability.TeacherAvailability.IsAvailable = false; } requestForEmploymentTeacherAvailabilities.Add(requestForEmploymentTeacherAvailability); } //decimal totalCost = requestForEmploymentTeacherAvailabilities.Sum(x => x.TeachingCost.Amount); requestCostImplication.MonthlyPay = 4 * totalCost * employerStudentCategory.NoOfStudent; requestCostImplication.TeacherAvailabilities = requestForEmploymentTeacherAvailabilities; } } else { requestCostImplication.EmployerStudentCategory = employerStudentCategory; requestCostImplication.TeacherAvailabilities = null; //requestCostImplication.TeacherPeriodsAvailable = null; } _viewModel.RequestCostImplications.Add(requestCostImplication); } //foreach (TeacherStudentCategory teacherStudentCategory in _viewModel.TeacherStudentCategories) //{ // TeachingCost teachingCost = _da.GetModelBy<TeachingCost, TEACHING_COST>(tc => tc.Qualification_Category_Id == highestQualificationId && tc.Student_Category_Id == teacherStudentCategory.StudentCategory.Id); // EmployerStudentCategory employerStudentCategory = _viewModel.EmployerStudentCategories.Where(sc => sc.StudentCategory.Id == teacherStudentCategory.StudentCategory.Id).SingleOrDefault(); // if (employerStudentCategory == null || employerStudentCategory.Id <= 0) // { // RequestCostImplication costImplication = new RequestCostImplication(); // costImplication.TeacherAvailabilities = UiUtility.InitializeAvailability(_viewModel.WeekDays, _viewModel.Periods); // costImplication.StudentCategory = teacherStudentCategory.StudentCategory; // costImplication.TeachingCost = teachingCost; // costImplication.NoOfStudent = 0; // if (costImplication.TeacherAvailabilities != null && costImplication.TeacherAvailabilities.Count > 0) // { // foreach (TeacherAvailability availability in costImplication.TeacherAvailabilities) // { // List<TeacherAvailability> availabilities = teacherAvailabilities.Where(x => x.WeekDay.Id == availability.WeekDay.Id && x.Period.Id == availability.Period.Id).ToList(); // if (availabilities != null && availabilities.Count > 0) // { // availability.IsAvailable = true; // if (teachingCost != null) // { // availability.Cost = teachingCost.Amount; // } // } // } // } // _viewModel.RequestCostImplications.Add(costImplication); // } //} _viewModel.ServiceCharge = _serviceCharge.GetRequestCostBy(new QualificationCategory() { Id = highestQualificationId }); } } catch (Exception ex) { _logger.LogError(ex); SetMessage(ex.Message, ApplicationMessage.Category.Error); } TempData["RequestViewModel"] = _viewModel; return(View(_viewModel)); }