Я должен реализовать поиск на основе выбранных условий, для которых я добавляю предложение where на основе условия поиска, но мой запрос всегда возвращает инструкцию else кода, не может выяснить, где я иду неправильно, и мой код идет ниже, любая помощь очень ценится
DateTime myDate = System.DateTime.Now.Date;
if (ddlUpdateOptions.SelectedValue == "1")
{
myDate = System.DateTime.Now;
}
if (ddlUpdateOptions.SelectedValue == "7")
{
myDate = System.DateTime.Now.AddDays(-7);
}
if (ddlUpdateOptions.SelectedValue == "15")
{
myDate = System.DateTime.Now.AddDays(-15);
}
if (ddlUpdateOptions.SelectedValue == "30")
{
myDate = System.DateTime.Now.AddDays(-30);
}
if (ddlUpdateOptions.SelectedValue == "60")
{
myDate = System.DateTime.Now.AddDays(-60);
}
using (mydatacontext db = new mydatacontext ())
{
var query = from b in db.JobSeekers
join c in db.JobContents on b.industryId equals c.JobContentid
join d in db.JobSeekerBasicEducations on b.BasicEduID equals d.BasicEduId
join f in db.JobSeekerMasterEdus on b.MasterEduID equals f.MasterEduId
join g in db.JobSeekerDoctarateEdus on b.DoctorateEduID equals g.DoctarateEduId
orderby b.UpdatedDate descending
select new
{
b.regId,
b.CurrentLocation,
b.CurrentEmployer,
b.MobileNumber,
b.ExpYears,
b.ExpMonths,
TotalExperience = b.ExpYears,
b.profileHeadlines,
b.KeySkills,
b.DownloadResume,
b.industryId,
b.UpdatedDate,
b.BasicEduID,
b.MasterEduID,
b.DoctorateEduID,
};
if (txtKeyword.Text != "")
{
query = query.Where(c => c.KeySkills.Contains(txtKeyword.Text));
}
if (txtLocation.Text != "")
{
query = query.Where(c => c.CurrentLocation.Contains(txtLocation.Text));
}
if (ddlExperienceMax.SelectedValue != "-Select-")
{
query = query.Where(c => c.ExpYears <= Convert.ToInt32(ddlExperienceMax.SelectedValue));
}
//if (txtEmployer.Text != "")
//{
// query = query.Where(c => c.CurrentEmployer.Contains(txtEmployer.Text));
//}
if (ddlIndustry.SelectedValue != "-Select-")
{
query = query.Where(c => c.industryId == Convert.ToInt32(ddlIndustry.SelectedValue));
}
if (ddlUpdateOptions.SelectedValue != "")
{
query = query.Where(c => c.UpdatedDate.Date < myDate.Date);
}
if (ddlEducation.SelectedValue != "-Select-")
{
query = query.Where(c => c.BasicEduID == Convert.ToInt32(ddlEducation.SelectedValue));
}
if (ddlMasters.SelectedValue != "-Select-")
{
query = query.Where(c => c.MasterEduID == Convert.ToInt32(ddlMasters.SelectedValue));
}
if (ddlDoctorate.SelectedValue != "-Select-")
{
query = query.Where(c => c.DoctorateEduID == Convert.ToInt32(ddlDoctorate.SelectedValue));
}
if (chkWithResumes.Checked)
{
query = query.Where(c => c.DownloadResume != "");
}
if (query.Count() > 0)
{
lblMessage.Text = "Search Results";
gvSearchResults.DataSource = query;
gvSearchResults.DataBind();
}
else
{
lblMessage.Text = "Your Search Yielded 0 Results. Please Modify/Broden your Search.";
gvSearchResults.DataSource = "";
gvSearchResults.DataBind();
}
}