public ActionResult Query(MotoSearch parm) { InitBag(); var model = modelService.Query(parm).ToList(); return(View("Index", model)); }
public IEnumerable <Model> Query(MotoSearch m) { string sql = "select * from dbo.Model where 1=1 "; //if(m.Brand_code != "") { sql += "and brand_code =" + m.Brand_code; } //if (m.Year != "") { sql += " and year =" + m.Year; } //if (m.cc_s != "") { sql += " and cc >=" + m.cc_s; } //if (m.cc_e != "") { sql += " and cc <=" + m.cc_e; } if (!string.IsNullOrEmpty(m.Brand_code)) { sql += $" and brand_code ='{m.Brand_code}'"; } if (!string.IsNullOrEmpty(m.Year)) { sql += $" and year ={m.Year}"; } if (!string.IsNullOrEmpty(m.cc_s)) { sql += " and cc >=" + m.cc_s; } if (!string.IsNullOrEmpty(m.cc_e)) { sql += " and cc <=" + m.cc_e; } if (!string.IsNullOrEmpty(m.Factory_price)) { sql += " and Factory_price >=" + m.Factory_price; } if (!string.IsNullOrEmpty(m.Factory_price2)) { sql += " and Factory_price <=" + m.Factory_price2; } if (!string.IsNullOrEmpty(m.ABS)) { sql += " and ABS =" + m.ABS; } var result = modelRepository.QueryModelBySql(sql); return(result); }