public ActionResult Details(long tid) { //var stopWatch = System.Diagnostics.Stopwatch.StartNew(); try { //tid = 47; if (_viewModel == null) { _viewModel = new TeacherSubscriptionViewModel(); } Model.Model.Teacher teacher = _da.GetModelBy <Model.Model.Teacher, TEACHER>(x => x.Person_Id == tid); if ((teacher != null && teacher.Person.Id > 0) && _viewModel.PersonAlreadyExist == false) { _viewModel.Teacher = teacher; _viewModel.Periods = _da.GetAll <Period, PERIOD>(); _viewModel.WeekDays = _da.GetAll <WeekDay, WEEK_DAY>(); _viewModel.StudentCategories = _da.GetAll <StudentCategory, STUDENT_CATEGORY>(); List <TeacherOLevelResultDetail> firstSittingOLevelResultDetails = null; List <TeacherOLevelResultDetail> secondSittingOLevelResultDetails = null; Referee referee = _da.GetModelBy <Referee, TEACHER_REFEREE>(x => x.Person_Id == _viewModel.Teacher.Person.Id); LoginDetail loginDetail = _da.GetModelBy <LoginDetail, PERSON_LOGIN>(x => x.Person_Id == _viewModel.Teacher.Person.Id); TeacherOLevelResult firstSittingOLevelResult = _da.GetModelBy <TeacherOLevelResult, TEACHER_O_LEVEL_RESULT>(x => x.Person_Id == _viewModel.Teacher.Person.Id && x.O_Level_Exam_Sitting_Id == 1); TeacherOLevelResult secondSittingOLevelResult = _da.GetModelBy <TeacherOLevelResult, TEACHER_O_LEVEL_RESULT>(x => x.Person_Id == _viewModel.Teacher.Person.Id && x.O_Level_Exam_Sitting_Id == 2); List <TeacherEducationalQualification> teacherEducationalQualifications = _da.GetModelsBy <TeacherEducationalQualification, TEACHER_EDUCATIONAL_QUALIFICATION>(x => x.Person_Id == _viewModel.Teacher.Person.Id); List <TeacherEmploymentHistory> teacherEmploymentHistories = _da.GetModelsBy <TeacherEmploymentHistory, TEACHER_EMPLOYMENT_HISTORY>(x => x.Person_Id == _viewModel.Teacher.Person.Id); List <TeacherAward> teacherAwards = _da.GetModelsBy <TeacherAward, TEACHER_AWARD>(x => x.Person_Id == _viewModel.Teacher.Person.Id); List <TeacherStudentCategory> teacherStudentCategories = _da.GetModelsBy <TeacherStudentCategory, TEACHER_STUDENT_CATEGORY>(x => x.Person_Id == _viewModel.Teacher.Person.Id); List <TeacherAvailability> teacherAvailabilities = _da.GetModelsBy <TeacherAvailability, TEACHER_AVAILABILITY>(x => x.Person_Id == _viewModel.Teacher.Person.Id); //_viewModel.Periods = await _da.GetAllAsync<Period, PERIOD>(); //_viewModel.WeekDays = await _da.GetAllAsync<WeekDay, WEEK_DAY>(); //_viewModel.StudentCategories = await _da.GetAllAsync<StudentCategory, STUDENT_CATEGORY>(); //List<TeacherOLevelResultDetail> firstSittingOLevelResultDetails = null; //List<TeacherOLevelResultDetail> secondSittingOLevelResultDetails = null; //Referee referee = await _da.GetModelByAsync<Referee, TEACHER_REFEREE>(x => x.Person_Id == _viewModel.Teacher.Person.Id); //LoginDetail loginDetail = await _da.GetModelByAsync<LoginDetail, PERSON_LOGIN>(x => x.Person_Id == _viewModel.Teacher.Person.Id); //TeacherOLevelResult firstSittingOLevelResult = await _da.GetModelByAsync<TeacherOLevelResult, TEACHER_O_LEVEL_RESULT>(x => x.Person_Id == _viewModel.Teacher.Person.Id && x.O_Level_Exam_Sitting_Id == 1); //TeacherOLevelResult secondSittingOLevelResult = await _da.GetModelByAsync<TeacherOLevelResult, TEACHER_O_LEVEL_RESULT>(x => x.Person_Id == _viewModel.Teacher.Person.Id && x.O_Level_Exam_Sitting_Id == 2); //List<TeacherEducationalQualification> teacherEducationalQualifications = await _da.GetModelsByAsync<TeacherEducationalQualification, TEACHER_EDUCATIONAL_QUALIFICATION>(x => x.Person_Id == _viewModel.Teacher.Person.Id); //List<TeacherEmploymentHistory> teacherEmploymentHistories = await _da.GetModelsByAsync<TeacherEmploymentHistory, TEACHER_EMPLOYMENT_HISTORY>(x => x.Person_Id == _viewModel.Teacher.Person.Id); //List<TeacherAward> teacherAwards = await _da.GetModelsByAsync<TeacherAward, TEACHER_AWARD>(x => x.Person_Id == _viewModel.Teacher.Person.Id); //List<TeacherStudentCategory> teacherStudentCategories = await _da.GetModelsByAsync<TeacherStudentCategory, TEACHER_STUDENT_CATEGORY>(x => x.Person_Id == _viewModel.Teacher.Person.Id); //List<TeacherAvailability> teacherAvailabilities = await _da.GetModelsByAsync<TeacherAvailability, TEACHER_AVAILABILITY>(x => x.Person_Id == _viewModel.Teacher.Person.Id); if (referee != null) { _viewModel.Referee = referee; } if (loginDetail != null) { _viewModel.Teacher.LoginDetail = loginDetail; } else { _viewModel.Teacher.LoginDetail = new LoginDetail(); _viewModel.Teacher.LoginDetail.SecurityQuestion = new SecurityQuestion(); _viewModel.Teacher.LoginDetail.Role = new Role(); } 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()); } _viewModel.TeacherStudentCategories = UiUtility.InitializeStudentCategory(_viewModel.StudentCategories); _viewModel.TeacherAvailabilities = UiUtility.InitializeAvailability(_viewModel.WeekDays, _viewModel.Periods); if (teacherEducationalQualifications != null && teacherEducationalQualifications.Count > 0) { if (_viewModel.TeacherEducationalQualifications != null && _viewModel.TeacherEducationalQualifications.Count > 0) { foreach (TeacherEducationalQualification educationalQualification in teacherEducationalQualifications) { foreach (TeacherEducationalQualification qualification in _viewModel.TeacherEducationalQualifications) { if (qualification.SchoolType.Id == educationalQualification.SchoolType.Id && qualification.Id <= 0) { qualification.Id = educationalQualification.Id; qualification.Person = educationalQualification.Person; qualification.SchoolType = educationalQualification.SchoolType; qualification.School = educationalQualification.School; qualification.YearOfAdmission = educationalQualification.YearOfAdmission; qualification.YearOfGraduation = educationalQualification.YearOfGraduation; qualification.Qualification = educationalQualification.Qualification; break; } } } } } if (firstSittingOLevelResult != null && firstSittingOLevelResult.Id > 0) { firstSittingOLevelResultDetails = _da.GetModelsBy <TeacherOLevelResultDetail, TEACHER_O_LEVEL_RESULT_DETAIL>(x => x.Teacher_O_Level_Result_Id == firstSittingOLevelResult.Id); } if (secondSittingOLevelResult != null && secondSittingOLevelResult.Id > 0) { secondSittingOLevelResultDetails = _da.GetModelsBy <TeacherOLevelResultDetail, TEACHER_O_LEVEL_RESULT_DETAIL>(x => x.Teacher_O_Level_Result_Id == secondSittingOLevelResult.Id); } if (teacherEmploymentHistories != null && teacherEmploymentHistories.Count > 0) { if (_viewModel.TeacherEmploymentHistories != null && _viewModel.TeacherEmploymentHistories.Count > 0) { for (int i = 0; i < teacherEmploymentHistories.Count; i++) { _viewModel.TeacherEmploymentHistories[i].Id = teacherEmploymentHistories[i].Id; _viewModel.TeacherEmploymentHistories[i].Person = teacherEmploymentHistories[i].Person; _viewModel.TeacherEmploymentHistories[i].Employer = teacherEmploymentHistories[i].Employer; _viewModel.TeacherEmploymentHistories[i].LastPositionHeld = teacherEmploymentHistories[i].LastPositionHeld; _viewModel.TeacherEmploymentHistories[i].StartYear = teacherEmploymentHistories[i].StartYear; _viewModel.TeacherEmploymentHistories[i].EndYear = teacherEmploymentHistories[i].EndYear; } } } if (teacherAwards != null && teacherAwards.Count > 0) { if (_viewModel.TeacherAwards != null && _viewModel.TeacherAwards.Count > 0) { for (int i = 0; i < teacherAwards.Count; i++) { _viewModel.TeacherAwards[i].Id = teacherAwards[i].Id; _viewModel.TeacherAwards[i].Person = teacherAwards[i].Person; _viewModel.TeacherAwards[i].AwardBody = teacherAwards[i].AwardBody; _viewModel.TeacherAwards[i].AwardName = teacherAwards[i].AwardName; _viewModel.TeacherAwards[i].YearAwarded = teacherAwards[i].YearAwarded; } } } if (teacherStudentCategories != null && teacherStudentCategories.Count > 0) { if (_viewModel.TeacherStudentCategories != null && _viewModel.TeacherStudentCategories.Count > 0) { foreach (TeacherStudentCategory teacherStudentCategory in _viewModel.TeacherStudentCategories) { List <TeacherStudentCategory> studentCategories = teacherStudentCategories.Where(x => x.StudentCategory.Id == teacherStudentCategory.StudentCategory.Id).ToList(); if (studentCategories != null && studentCategories.Count > 0) { teacherStudentCategory.IsSelected = true; teacherStudentCategory.Person = _viewModel.Teacher.Person; } } } } if (teacherAvailabilities != null && teacherAvailabilities.Count > 0) { if (_viewModel.TeacherAvailabilities != null && _viewModel.TeacherAvailabilities.Count > 0) { foreach (TeacherAvailability teacherAvailability in _viewModel.TeacherAvailabilities) { List <TeacherAvailability> availabilities = teacherAvailabilities.Where(x => x.WeekDay.Id == teacherAvailability.WeekDay.Id && x.Period.Id == teacherAvailability.Period.Id).ToList(); if (availabilities != null && availabilities.Count > 0) { teacherAvailability.IsAvailable = true; teacherAvailability.Person = _viewModel.Teacher.Person; } } } } SetTeacherFirstSittingOLevelResult(firstSittingOLevelResult, firstSittingOLevelResultDetails); SetTeacherSecondSittingOLevelResult(secondSittingOLevelResult, secondSittingOLevelResultDetails); } SetPassportUrl(_viewModel.Teacher.ImageFileUrl); } catch (Exception ex) { _logger.LogError(ex); SetMessage(ex.Message, ApplicationMessage.Category.Error); } //stopWatch.Stop(); //var executionTime = stopWatch.ElapsedMilliseconds; //ViewBag.Time = executionTime; return(View(_viewModel)); }
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)); }
public async Task <ActionResult> Cost(string ptid) { ServiceCostViewModel viewModel = (ServiceCostViewModel)TempData["TeachingCostViewModel"]; try { if (viewModel == null) { _viewModel = new ServiceCostViewModel(); } else { _viewModel = viewModel; } if (!string.IsNullOrWhiteSpace(ptid)) { if (_viewModel.Subscribers == null || _viewModel.Subscribers.Count <= 0) { _viewModel.Subscribers = _da.GetModelsBy <PersonType, PERSON_TYPE>(p => p.Person_Type_Id != 1); } List <PersonType> personTypes = null; if (_viewModel.Subscribers != null && _viewModel.Subscribers.Count > 0) { personTypes = _viewModel.Subscribers.Where(u => ptid.Contains(u.Id.ToString())).ToList(); if (personTypes != null && personTypes.Count > 0) { _viewModel.PersonTypeSelectList = DropdownUtility.PopulateModelSelectListHelper(personTypes, false, "-- Select Your Category --"); if (personTypes.Count == 1) { ViewBag.PersonTypes = new SelectList(_viewModel.PersonTypeSelectList, DropdownUtility.VALUE, DropdownUtility.TEXT, personTypes[0].Id); } else { ViewBag.PersonTypes = _viewModel.PersonTypeSelectList; } } else { _viewModel.PersonTypeSelectList = new List <SelectListItem>(); } } else { _viewModel.PersonTypeSelectList = new List <SelectListItem>(); } } await LoadPersonType(); await InitializeTeachingCostHelper(); await InitializeTeacherAvailabilityHelper(); _viewModel.ServiceCharges = await _da.GetAllAsync <ServiceCharge, SERVICE_CHARGE>(); _viewModel.TeacherAvailabilities = UiUtility.InitializeAvailability(_viewModel.WeekDays, _viewModel.Periods); _viewModel.TeachingCosts = UiUtility.InitializeTeachingCost(_viewModel.StudentCategories, _viewModel.QualificationCategories, _viewModel.ExistingTeachingCosts); } catch (Exception ex) { _logger.LogError(ex); SetMessage(ex.Message, ApplicationMessage.Category.Error); } TempData["TeachingCostViewModel"] = _viewModel; return(View(_viewModel)); }