public ActionResult GetCompanyList(int listid, string citycircle, string biztype, string title, string name, string Notes) { var prospectviewlist = new List <SpGetprosviewlistclient_Result>(); var complist = new List <CompanyModel>(); try { List <string> titlelist = new List <string>(); Notes = Notes.Replace(" ", ""); if (!string.IsNullOrEmpty(title)) { if (title == "Manager") { titlelist.Add("CEO"); titlelist.Add("EXEC"); titlelist.Add("Manager"); } else { titlelist.Add(title); } } if (listid != 0 && string.IsNullOrEmpty(citycircle) && string.IsNullOrEmpty(biztype) && string.IsNullOrEmpty(title) && string.IsNullOrEmpty(name) && string.IsNullOrEmpty(Notes)) { var data = context.SpGetprosviewlistclient(listid).ToList(); prospectviewlist = data; } else if (listid != 0 || !string.IsNullOrEmpty(citycircle) || !string.IsNullOrEmpty(biztype) || !string.IsNullOrEmpty(title)) { var data = (from com in context.Companies join con in context.Contacts on com.companyid equals con.companyid into gj from x in gj.DefaultIfEmpty() where ((citycircle == null || citycircle == "") || com.citycircle == citycircle) && ((biztype == null || biztype == "") || com.biztype == biztype) && ((title == null || title == "") || (titlelist.Contains(x.titlestandard) || x.titlestandard == null)) && ((name == null || name == "") || x.contactfullname.Contains(name) || com.name.Contains(name)) && ((Notes == null || Notes == "") || x.combinednotes.Trim().Replace("\r", "").Replace("\n", "").Replace(System.Environment.NewLine, "").Replace(" ", "").Contains(Notes)) && com.listid == listid select new { com.companyid, com.listid, com.citycircle, com.biztype, com.name, com.addr1, com.addr2, com.city, com.state, com.zip, com.weburl, com.phone, com.priority, com.target, x.combinednotes, com.Userid }).Distinct().ToList(); foreach (var i in data) { CompanyModel objcomp = new CompanyModel(); objcomp.companyid = i.companyid; objcomp.listid = i.listid; objcomp.citycircle = i.citycircle; objcomp.biztype = i.biztype; objcomp.name = i.name; objcomp.addr1 = i.addr1; objcomp.addr2 = i.addr2; objcomp.city = i.city; objcomp.state = i.state; objcomp.zip = i.zip; objcomp.weburl = i.weburl; objcomp.phone = i.phone; objcomp.Userid = i.Userid; if (i.priority == null) { objcomp.priority = false; } else { objcomp.priority = Convert.ToBoolean(i.priority); } if (i.target == null) { objcomp.priority = false; } else { objcomp.target = Convert.ToBoolean(i.target); } objcomp.combinednotes = i.combinednotes; if (complist.Where(x => x.companyid == objcomp.companyid).Count() == 0) { complist.Add(objcomp); } } return(View(complist)); //return RedirectToAction("Index", "ProspectListsAdmin"); } } catch (Exception ex) { cm.ErrorExceptionLogingByService(ex.ToString(), "ProspectViewListClient" + ":" + new StackTrace().GetFrame(0).GetMethod().Name, "GetCompanyList", "NA", "NA", "NA", "WEB"); } return(View(prospectviewlist)); }