コード例 #1
0
        public ActionResult Search(SearchTutorBindingModel SearchData)
        {
            IList <Tutor> TutorList = db.Tutors.Include("Grades").Include("Subjects")
                                      .Where(t => t.Grades.Any(g => g.Id == SearchData.Grade) && t.Subjects.Any(s => s.Id == SearchData.Subject) && t.Gender == SearchData.Gender)
                                      .ToList();

            return(View("ExistingTutorList", new PrivateTutorOnline.Models.ViewModels.ExistingTutorListViewModel()
            {
                Tutors = TutorList,
                Subjects = db.Subjects.ToList(),
                Grades = db.Grades.ToList()
            }));
        }
コード例 #2
0
        public ActionResult Search(string Keyword,
                                   Gender Gender,
                                   int Grade,
                                   int Subject,
                                   AcademicDegree Degree,
                                   bool?IsAccurate, int?page)
        {
            SearchTutorBindingModel SearchData = new SearchTutorBindingModel();

            SearchData.IsAccurate = IsAccurate ?? false;
            SearchData.Subject    = Subject;
            SearchData.Grade      = Grade;
            SearchData.Degree     = Degree;
            SearchData.Gender     = Gender;
            SearchData.Keyword    = Keyword;
            IList <Tutor> TutorList = null;

            if (SearchData.IsAccurate)
            {
                if (String.IsNullOrEmpty(SearchData.Keyword))
                {
                    TutorList = db.Tutors.Include(s => s.Grades).Include(s => s.Subjects)
                                .Where(t =>
                                       t.Grades.Any(g => g.Id == SearchData.Grade) &&
                                       t.Subjects.Any(s => s.Id == SearchData.Subject) &&
                                       t.Gender == SearchData.Gender &&
                                       t.Degree == SearchData.Degree
                                       )
                                .ToList();
                }
                else
                {
                    int TutorId = -1;
                    if (int.TryParse(SearchData.Keyword, out TutorId))
                    {
                        TutorId = Int32.Parse(SearchData.Keyword);
                    }
                    TutorList = db.Tutors.Include(s => s.Grades).Include(s => s.Subjects)
                                .Where(t =>
                                       t.Grades.Any(g => g.Id == SearchData.Grade) &&
                                       t.Subjects.Any(s => s.Id == SearchData.Subject) &&
                                       t.Gender == SearchData.Gender &&
                                       t.Degree == SearchData.Degree &&
                                       (t.Id == TutorId ||
                                        t.FullName.Contains(SearchData.Keyword) ||
                                        t.District.Contains(SearchData.Keyword) ||
                                        t.City.Contains(SearchData.Keyword) ||
                                        t.Street.Contains(SearchData.Keyword) ||
                                        t.Ward.Contains(SearchData.Keyword) ||
                                        t.MajorSubject.Contains(SearchData.Keyword) ||
                                        t.GraduationYear.Equals(SearchData.Keyword) ||
                                        t.PhoneNumber.Equals(SearchData.Keyword) ||
                                        t.HomeTown.Contains(SearchData.Keyword) ||
                                        t.University.Contains(SearchData.Keyword)
                                       )
                                       )
                                .ToList();
                }
            }
            else
            {
                if (String.IsNullOrEmpty(SearchData.Keyword))
                {
                    TutorList = db.Tutors.Include(s => s.Grades).Include(s => s.Subjects)
                                .Where(t =>
                                       t.Grades.Any(g => g.Id == SearchData.Grade) ||
                                       t.Subjects.Any(s => s.Id == SearchData.Subject) ||
                                       t.Gender == SearchData.Gender ||
                                       t.Degree == SearchData.Degree
                                       )
                                .ToList();
                }
                else
                {
                    int TutorId = -1;
                    if (int.TryParse(SearchData.Keyword, out TutorId))
                    {
                        TutorId = Int32.Parse(SearchData.Keyword);
                    }
                    TutorList = db.Tutors.Include(s => s.Grades).Include(s => s.Subjects)
                                .Where(t =>
                                       t.Grades.Any(g => g.Id == SearchData.Grade) ||
                                       t.Subjects.Any(s => s.Id == SearchData.Subject) ||
                                       t.Gender == SearchData.Gender ||
                                       t.Grades.Any(h => h.Name.Contains(SearchData.Keyword)) ||
                                       t.Subjects.Any(h => h.Name.Contains(SearchData.Keyword)) ||
                                       t.FullName.Contains(SearchData.Keyword) ||
                                       t.District.Contains(SearchData.Keyword) ||
                                       t.City.Contains(SearchData.Keyword) ||
                                       t.Street.Contains(SearchData.Keyword) ||
                                       t.Ward.Contains(SearchData.Keyword) ||
                                       t.MajorSubject.Contains(SearchData.Keyword) ||
                                       t.GraduationYear.Equals(SearchData.Keyword) ||
                                       t.PhoneNumber.Contains(SearchData.Keyword) ||
                                       t.HomeTown.Contains(SearchData.Keyword) ||
                                       t.University.Contains(SearchData.Keyword) ||
                                       t.Degree == SearchData.Degree ||
                                       t.Id == TutorId

                                       )
                                .ToList();
                }
            }

            return(View("ExistingTutorList", new PrivateTutorOnline.Models.ViewModels.ExistingTutorListViewModel()
            {
                Tutors = TutorList.ToPagedList(page.HasValue ? page.Value : 1, 2),
                Subjects = db.Subjects.ToList(),
                Grades = db.Grades.ToList(),
                searchResult = SearchData,
                IsSearchBySubjects = false,
                IsSearchByGrades = false
            }));
        }