Here is my method:
public JsonResult ValidateAll(string toys)
{
Dictionary<string, object> res = new Dictionary<string, object>();
List<string> result_check = new List<string>();
string[] lines = toys.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string line in lines)
{
string toyName = line;
string toy_tmp = toyName.Trim();
string toy_tmp2 = HttpUtility.HtmlEncode(HttpUtility.HtmlDecode(toyName)).Replace("ä", "ä").Trim();
string toy_tmp3 = toyName.Replace("\u00a0", " ").Trim();
string toy_tmp4 = HttpUtility.HtmlDecode(toyName.Trim());
string toy_tmp5 = HttpUtility.HtmlDecode(toyName.Replace("\u00a0", " ").Replace(" ", " ").Trim());
string tableInDatabase = "";
//Check if the toy is a doll
tblDoll doll = (from x in db.tblDoll
where (x.doll_name == toy_tmp || x.doll_name == toy_tmp2 || x.doll_name == toy_tmp3 || x.doll_name == toy_tmp4 || x.doll_name == itoy_tmp5)// || x.doll_name == toy_tmp6)
select x)
.FirstOrDefault();
if (doll != null)
{
table = "doll";
result_check.Add("1");
continue;
}
if (table == "")
{
var car = (from x in db.tblCar
where (x.car_name == toy_tmp || x.car_name == toy_tmp2 || x.car_name == toy_tmp3 || x.car_name == toy_tmp4)
select y).FirstOrDefault();
if (car != null)
{
table = "car";
result_check.Add("1");
continue;
}
}
//Do the same as for Car and Doll, do it for Plane and Boat too
}
res.Add("ok", result_check);
return Json(res, JsonRequestBehavior.AllowGet);
}
What I'm trying to do is this: the input string is a name of a toy. I have four tables for toys in my db: Car, Doll, Plane, Boat. I need to find in which table is the toy (the input string).