help with linq to sql - asp.net-mvc

Help me with this algorithm please.
var companies = companyrepository.GetAll().OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize);
string where = "";
if (op == "eq")
where = field + "=" + data;
else if (op == "cn")
where = field + " LIKE '%"+data+"%'"; ///here lies my problem
companies = companies.Where(where);
its for adding dynamic where clauses to a linq query... op, field, and data are all strings that come with ajax from a jquery grid.
The problem is that it gives me an error when it tries to do the Like operator... it works just fine with the equals operator.

Based on this page, the following should work for you:
if (op == "eq")
where = field + "=" + data;
else if (op == "cn")
where = field + ".Contains(\"" + data + "\")";
I ran some tests on my own data, and it appears to work fine.

Related

How can I have multiple hyperlinks in the same column using JS render function?

I have a shiny app that displays a datatable (using DTedit R pckg) and I would like to:
1) Insert all the hyperlinks in the same cell, separated by a new line
2) Open the hyperlinks in a different tab.
For point 2, I have tried different versions of ' target="_blank" but it does not work. My guess is that I am doing something wrong with the quotes.
#E.g.:
<a href=' + data + ' target='_blank'>' + 'PanelApp' + '</a>' ;}"
I have tried with double quotes too (target="_blank") but is not recognising them (I have zero experience in JS)
This is an example of the app:
library(shiny)
library(DT)
#devtools::install_github('jbryer/DTedit')
library(DTedit)
ui = fluidPage(
h3("How can I have all the links in one column separated by <br> ?"),
mainPanel(
shiny::uiOutput("mytable")
)
)
server = function(input, output){
#dataframe
mydata <- data.frame(Gene = c("GBE1", "KMT2D"),
Metric = c(10, 20))
## Add hyperlinks
mydata$Decipher <- paste0("https://decipher.sanger.ac.uk/gene/", mydata$Gene, "#overview/protein-info")
mydata$PanelApp <- paste0("https://panelapp.genomicsengland.co.uk/panels/entities/", mydata$Gene)
#render table
DTedit::dtedit(input, output,
name = 'mytable',
thedata = mydata,
datatable.options = list(
columnDefs = list(
list(targets= 2,
render = JS("function(data){return '<a href=' + data + '>' + 'PanelApp' + '</a>' ;}")),
list(targets= 3,
render = JS("function(data){return '<a href=' + data + '>' + 'Decipher' + '</a>' ;}"))
)
)
)
}
shinyApp(ui = ui, server = server, options = list(height = 1080))
Can anyone shed some light here?
THANK YOU!!

xojo call a method with button

I have the code below in a View method to parse JSON files. The method ContentsOfDictionary accepts the parameters d as Xojo.Core.Dictionary and level as an integer, and returns text.If I use ContentsOfDictionary in an action button, I get this error:
error: Not Enough arguments: got 0, expected at least 1
Here is a link to the test file I am using.
How do I call the method ContentsOfDictionary?
dim dict as Xojo.Core.Dictionary = Xojo.Data.ParseJSON (kJsonData)
const kEOL = &u0A
dim indent as text
for i as integer = 1 to level
indent = indent + " "
next
dim t as text
for each entry as Xojo.Core.DictionaryEntry in dict
t = t + indent + entry.Key + " "
if Xojo.Introspection.GetType( entry.Value ) is nil then
t = t + "nil" + kEOL
else
select case Xojo.Introspection.GetType( entry.Value ).Name
case "Boolean"
t = t + if( entry.Value, "true", "false" ) + kEOL
case "Text"
t = t + entry.Value + kEOL
case "Int32", "Int64"
//
// You get the idea
//
case "Dictionary"
t = t + kEOL + ContentsOfDictionary( entry.Value, level + 1 )
end select
end if
next
return t
UPDATE: None of the below applies as #johnnyB's example was of the ContentsOfDictionary function and should not have been trying to access the JSON data but just working on the supplied Dictionary. There is a link to the fixed test project in the comments below.
It's failing because you're not satisfying the parameter types of any of ContentsOfDictionary's signatures.
entry.Value is of type Auto, so before calling ContentsOfDictionary you need to copy entry.Value into a Dictionary and pass that in to the function instead.
For example...
...
case "Dictionary"
dim d as new Xojo.Core.Dictionary = entry.Value
t = t + kEOL + ContentsOfDictionary( d, level + 1 )
end select

Twitter API link parser

I am having an issue and tried to do everything regarding this!! even HttpUtility.ParseQueryString won't help!
I am trying to parse twitter links coming from the API in the form of http://t.co/oEVQbihMWu. I need the fully resolved URL.
My code:
richTextBox1.Clear();
richTextBox1.Visible = true;
SearchOptions SO = new SearchOptions();
SO.GeoCode = richTextBox3.Text + "," + richTextBox2.Text + "mi";
TwitterResponse<TwitterSearchResultCollection> TweetSearchResult = TwitterSearch.Search(tokens, "#blogger", SO);
if (TweetSearchResult.Result != RequestResult.Success) richTextBox1.Text = "connection Error";
else
{
string a = null;
foreach (var tweet in TweetSearchResult.ResponseObject)
{
string b = tweet.User.Location.Contains(",") ? tweet.User.Location.Replace(",", "-") : tweet.User.Location;
a += string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", tweet.CreatedDate, b, tweet.User.Id,
tweet.User.ScreenName, tweet.User.Name, tweet.User.NumberOfFollowers, tweet.User.Website, Environment.NewLine);
richTextBox1.AppendText(" " + tweet.CreatedDate + "\n" + tweet.User.Location + "\n" + tweet.User.Id + "\n" + tweet.User.ScreenName + "\n" + tweet.User.Name + "\n" + tweet.User.NumberOfFollowers +
"\n" + tweet.User.Website + "\n" + tweet.Text + "\n\n\n");
}
links being represented by tweet.user.website.
any help? :)
In the API response, there is entities.urls which contains an array of url and expanded_url mappings. Check your library's documentation for equivalent.
Alternatively, if you inspect the response for t.co links, you will find this:
<noscript><META http-equiv="refresh" content="0;URL=http://www.fitnessbydanielle.com"></noscript><title>http://www.fitnessbydanielle.com</title><script>window.opener = null; location.replace("http:\/\/www.fitnessbydanielle.com")</script>
Parse it to get the url.
I managed to crack it.
What I did:
foreach (var tweet in TweetSearchResult.ResponseObject)
{
if(tweet.User.Website != null)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(tweet.User.Website);
req.AllowAutoRedirect = false;
var resp = req.GetResponse();
string realUrl = resp.Headers["Location"];
string b = tweet.User.Location.Contains(",") ? tweet.User.Location.Replace(",", "-") : tweet.User.Location;
a += string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", tweet.CreatedDate, b, tweet.User.Id,
tweet.User.ScreenName, tweet.User.Name, tweet.User.NumberOfFollowers, realUrl, Environment.NewLine);
richTextBox1.AppendText(" " + tweet.CreatedDate + "\n" + tweet.User.Location + "\n" + tweet.User.Id + "\n" + tweet.User.ScreenName + "\n" + tweet.User.Name + "\n" + tweet.User.NumberOfFollowers +
"\n" + realUrl + "\n" + tweet.Text + "\n\n\n");
}
}
File.AppendAllText(#".\BloggerTable.csv", a, Encoding.UTF8);
}
Wrapped it inside a condition so no users without website will show and used a webrequest to get the link. stored the location inside the httprequest header for each and every tweet.

How to get qrcode with qrcode 0.3 Grails Plugin

I have some problem to activate qrcode 0.3 plugin. I already install on my project, and how to get print qrcode?
This is my code
def beforeInsert() {
Integer count = Batch.count()+1
String bc = sprintf('%04d',count)
if( packNoLevel1 != null){
number = prodDate.format('MM/dd/yy') + '/' + packNoLevel1 + '/' + item.code + '/' + bc
}else{
number = prodDate.format('MM/dd/yy') + '/' + packNoLevel2 + '/' + item.code + '/' + bc
}
and how to generate number to qrcode ??
thanks..
First is this beforeInsert an event in your domain? If so generating qr inside your domain does not help with rendering it. Either you need to move that logic into your controller or save that number in database and use it later from a controller when you want to display the qrcode.
I assumed you were able to move the logic into a controller then you just need to pass that number into your view and the view will render the qrCode for you based on that number.
YourController.groovy
def show() {
// this logic needs be tweaked if you decide to have it in controller
//Integer count = Batch.count()+1
//String bc = sprintf('%04d',count)
// if( packNoLevel1 != null){
// number = prodDate.format('MM/dd/yy') + '/' + packNoLevel1 + '/' + item.code + '/' + bc
// }else{
// number = prodDate.format('MM/dd/yy') + '/' + packNoLevel2 + '/' + item.code + '/' + bc
// }
def number = calculateMe()
[...,qrNumber:number]
}
list.gsp
<qrcode:image text="${qrNumber}"/>

Fusion table ST_INTERSECTS not work

My App using fusiontable to select records id by ST_INTERSECTS working fine before suddenly not work now!
var queryText = encodeURIComponent("select id from "+ v_TableID +" where ST_INTERSECTS(address, CIRCLE(LATLNG(" + lat + ',' + lng + '),' + 1000 + '))' + "and" + v_select + "and id > 1" );
var query = new google.visualization.Query("http://www.google.com/fusiontables/gvizdata?tq=" + queryText);
If removed ST_INTERSECTS(address, CIRCLE(LATLNG(" + lat + ',' + lng + '),' + 1000 + '))it work fine
var queryText = encodeURIComponent("select id from "+ v_TableID +" where " + v_select + "and id > 1");
var query = new google.visualization.Query("http://www.google.com/fusiontables/gvizdata?tq=" + queryText);
if i modify fusion table address(eg: 22.2202,113.9196 change to 22.22,113.919) it work again but only the first time.
Additional information
var v_select = 'category in ("abc","xyz")';
i try again than find out
var queryText = encodeURIComponent("select id from "+ v_TableID +" where ST_INTERSECTS(address, CIRCLE(LATLNG(" + lat + ',' + lng + '),' + 1000 + '))' + "and" + 'category in ("abc","xyz")' + "and id > 1" );
var query = new google.visualization.Query("http://www.google.com/fusiontables/gvizdata?tq=" + queryText);
if i remove "category in ("abc","xyz")" OR "ST_INTERSECTS(address, CIRCLE(LATLNG(" + lat + ',' + lng + ')" work fine.
Is it not allow to use "in" and "ST_INTERSECTS" together now?
Before 28/10/2012 it work fine i use the same clause already 6 months but now not work.
Please help
I appreciate that this isn't an answer (I don't have enough rep to make a comment) but it might help in solving this problem - I am having a similar problem with an almost identical query which has worked for a while. It seems to be because of the switch from Numeric tableID's to encrypted tableID's - that's the only difference in my two versions of code. Is the poster using encrypted table ID's? Working to try and fix this with no luck so far...

Resources