I made some tables in Entity Framework 5.0 and generated an SQL Server Database from it. The tables are as follows:
Title (TitleId, TitleName, TitlePrice, ISBN...)
Author (AuthorId, FirstName, LastName)
Category (CategoryId, CategoryName)
The relationships between Title and Author and Title and Category are many to many.
Now, here is how I access what categories are assigned to each title and what authors have contributed to a title.
//for authors
var queryAuthList = from au in ebs.Authors
from t in au.Titles
where t.TitleId == TitleId
select new
{
Name = string.Concat(au.FirstName, " ", au.LastName)
};
//for categories
var queryCatList = from cat in ebs.Categories
from t in cat.Titles
where t.TitleId == TitleId
select new
{
cat.CategoryName
};
Now, how do I display the contents of queryAuthList or queryCatList in a simple text label?
I want the output to be like AuthorA, AuthorB, AuthorC for authors and CategoryX, CategoryY, CategoryZ for categories assigned to a single title.
I tried declaring a List<String> and adding the items to the list in a foreach loop, and then printing the list using String.Join(",",strList). However the output appears as
{Name = AuthorA}, {Name = AuthorB}, {Name = AuthorC}
{CategoryName = CategoryX}, {CategoryName = CategoryY}, {CategoryName = CategoryZ}
The {Name = AuthorA} you see is the default ToString() for an anonymous type.
You don't want that, so do not wrap it in a anonymous type:
var queryAuthList = from au in ebs.Authors
from t in au.Titles
where t.TitleId == TitleId
//select new
//{
// Name = string.Concat(au.FirstName, " ", au.LastName)
//};
select string.Concat(au.FirstName, " ", au.LastName);
And since queryAuthList now is an IEnumerable<string>,
string result = String.Join(",", queryAuthList);
Related
Hi I am using stripe process for an payment and I am generating Stripe customer Id as from below code.
StripeCustomerId = CreateStripeCustomer(fname, lname, Email, objStripeRequestOptions);
Also
IEnumerable<StripeCard> AllStripeCardResponse = cardService.List(StripeCustomerId);
string strLast4 = CardNumber.Replace(" ", "").Substring(CardNumber.Replace(" ", "").Length - 4);
dynamic ExistingCard = (from x in AllStripeCardResponse where x.Last4 == strLast4 & x.ExpirationMonth == Convert.ToInt32(Month.Trim()) & x.ExpirationYear == Convert.ToInt32(Year.Trim()) select x).ToList();
it is giving existing card as 0
Can any one let me know how can I fetch Card Detail like card number, Name, Exp Month Year from Generated Stripe Customer Id?
You can't retrieve whole card info.
You can get some info from the source object which is present in the customer API.
Retrieving the source will provide you last 4 digit of card number and expiry date.
StripeConfiguration.SetApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
StripeConfiguration.SetApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
var customerService = new StripeCustomerService();
StripeCustomer customer = customerService.Get("cus_BwS21a7fAH22uk");
, in response of customer you will have source attribute. please see the JSON response returned. it contains source list(lists of cards added.)
you will get sample object similar to this , here you can see last 4 digit of card is returned as object in my case it is 1111
#<Stripe::ListObject:0x5ea1a78> JSON: {
"object": "list",
"data": [
{"id":"card_1BY6nrCaMyPmWTcG3uosK2up","object":"card","address_city":null,"address_country":null,"address_line1":null,"address_line1_check":null,"address_line2":null,"address_state":null,"address_zip":null,"address_zip_check":null,"brand":"Visa","country":"US","customer":"cus_BvylB8PAVap2JQ","cvc_check":"pass","dynamic_last4":null,"exp_month":12,"exp_year":2017,"fingerprint":"yE1mPcIGvqTYGcxQ","funding":"unknown","last4":"1111","metadata":{},"name":null,"tokenization_method":null}
],
"has_more": false,
"total_count": 1,
"url": "/v1/customers/cus_BvylB8PAVap2JQ/sources"
}
Also See Below
var stripecard = "cus_BwS21a7fAH22uk";
StripeCustomer customer;
StripeConfiguration.SetApiKey(ConfigurationManager.AppSettings["StripeApiKey"].ToString());
var customerService = new StripeCustomerService();
customer = customerService.Get(stripecard);
ViewBag.last4card = customer.Sources.Data[0].Card.Last4.ToString();
ViewBag.ExpMonth = customer.Sources.Data[0].Card.ExpirationMonth.ToString();
ViewBag.ExpYear = customer.Sources.Data[0].Card.ExpirationYear.ToString();
ViewBag.Name = customer.Sources.Data[0].Card.Name.ToString();
I just started a new Project _NewEnglandPatriots.
EDTs:
FirstName (extends Name)
SecondName(extends Name)
LastName (extends Name)
Position (String)
PlayerBirthday (Date)
JerseyNumber (Integer)
Tables:
SycTeamRoster (I've dragged all my EDTs to the "Fields" of the table)
Forms:
TeamRoster (I've dragged all the fields into my SimpleList design)
I have inserted the following player data to the form without a problem:
Thomas Edward
Patrick
Brady
12
Quarterback
03.08.1977
Next I wrote a Job insertTeamMembers, within which I insert the member with the following code:
static void insertTeamMembers(Args _args)
{
SycTeamRoster newEnglandTable;
container teammembers;
container conTake;
int i;
;
teammembers = [["Khashayar" ,"Goudarzi", 1, "Quarterback", 28,02,1990]];
ttsBegin;
for(i=1; i<=conLen(teammembers); i++)
{
conTake= conPeek(teammembers,i);
newEnglandTable.clear();
newEnglandTable.SycVorname = conPeek(teammembers,1);
newEnglandTable.SycNachname = conPeek(teammembers,2);
newEnglandTable.SycJerseyNumber = conPeek(teammembers,3);
newEnglandTable.SycPosition = conPeek(teammembers,4);
newEnglandTable.SycPlayerBirthday = conPeek(teammembers,5);
newEnglandTable.insert();
}
ttsCommit;
}
The problem is that I get the following data to the Form and Table:
FirstName: Khashayar
SecondName: empty, but because I left it that way
LastName: empty
JerseyNumber: 0
FieldPosition: 0
Birthday: empty
What is causing these empty fields in the table?
These lines are using teammembers instead of conTake
newEnglandTable.SycVorname = conPeek(teammembers,1);
Change to
newEnglandTable.SycVorname = conPeek(conTake,1);
And the way you have data entered in your nested container, specifically 28,02,1990 is going to be a problem.
This appears to be a learning exercise, so I don't want to solve the entire thing for you.
I am having trouble with displaying the results in the search activity of my app. I wonder where it went wrong.
The aim of the function below is to search the input query of the user and find it in every files listed. But the results only matches one data eventhough the query is also present in the other files. Here is the code.
public void searchFiles(File[] filelist, String query, String querysearch, String[] namesOfFiles){
querysearch = "SELECT * FROM Data WHERE ObjectID = ? ";
int temp2 = filelist.length;
for (int i = (temp2-1); i >= 0; i--) {
if(!(filelist[i].getName().equals("DataObjectDB.db")) && !(filelist[i].getName().endsWith("-journal"))){
temp1 = filelist[i].getName();
namesOfFiles[i] = temp1.replaceAll(".db$", "");
Toast.makeText(getApplicationContext(),"Searching " + query + " in: " + namesOfFiles[i], Toast.LENGTH_SHORT).show();
DatabaseHelper db1 = new DatabaseHelper(getApplicationContext(),namesOfFiles[i]);
SQLiteDatabase sqldb = db1.getWritableDatabase();
cursor = sqldb.rawQuery(querysearch, new String[]{query});
Toast.makeText(getApplicationContext(),cursor.toString(), Toast.LENGTH_SHORT).show();
}
}
final ListView listView = (ListView) findViewById(R.id.results_listview);
SearchAdapter adapter = new SearchAdapter(this, R.layout.results_column, cursor,0 );
listView.setAdapter(adapter);
}
The searchFiles() function passes the filelist, query, querysearch and namesOfFiles where 1) filelist contains the list of files in the source folder 2) query is the user input he/she wants to search 3) querysearch is the select statement 3) namesofFiles is just an empty string.
I indicate a toast to see if the code traverses through all the folders. And yes it is. But I don't know why it is not displaying all the results.
Any help? Thanks!
Found an answer on different posts. Basically, you just have to use hashmap and arraylist first before setting up the adapter directly.
I've inserted three Customer items into QuickBooks online. I want to find a special item by ids and modify one of the attributes' value. I want to accomplish this by coding in backstage of a application. How can I do this?
This is the connection code that I have:
realmId = HttpContext.Current.Session["realm"].ToString();
accessToken = HttpContext.Current.Session["accessToken"].ToString();
accessTokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString();
consumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(CultureInfo.InvariantCulture);
consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
dataSourcetype = IntuitServicesType.QBO;
OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
ServiceContext context = new ServiceContext(oauthValidator, realmId, dataSourcetype);
DataServices commonService = new DataServices(context);
You can query for customers as follows:
//search based on customer name
var qbdCustomerQuery1 = new Intuit.Ipp.Data.Qbd.CustomerQuery();
qbdCustomerQuery1.Item1ElementName = Intuit.Ipp.Data.Qbd.Item1ChoiceType.FirstLastInside; //Item1ChoiceType.FirstLastEnd //Item1ChoiceType.FirstLastStart
qbdCustomerQuery1.Item1 = "Popeye";
List<Intuit.Ipp.Data.Qbd.Customer> CustomerQueryResult = qbdCustomerQuery1.ExecuteQuery<Intuit.Ipp.Data.Qbd.Customer>(context).ToList<Intuit.Ipp.Data.Qbd.Customer>();
//search based on customer id
Intuit.Ipp.Data.Qbo.Customer qboCustomer = new Intuit.Ipp.Data.Qbo.Customer();
qboCustomer.Id = new IdType() { idDomain = Intuit.Ipp.Data.Qbo.idDomainEnum.QBO, Value = "3" };
IEnumerable<Intuit.Ipp.Data.Qbo.Customer> qboCustomerResults = commonService.FindById(qboCustomer) as IEnumerable<Intuit.Ipp.Data.Qbo.Customer>;
Use the resultset to get the customer object. Modify the values and call Update:
https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0100_ipp_.net_devkit/0299_synchronous_calls/0001_data_service_apis
Hey just started using Lucene.NET, any was wondering if anyone had a working example of Lucene.NET with a faceted search.
I know this below link http://www.devatwork.nl/articles/lucenenet/faceted-search-and-drill-down-lucenenet/
Which looked great, but all it does is tell me the number of results in the faceted search but not actually how I can retrieve the index and details of those results. i.e as in a normal search in Lucene.NET.
I.e from that link he has the following snippet
private static void FacetedSearch(string indexPath, string genre, string term){
var searcher = new IndexSearcher(indexPath);
// first get the BitArray result from the genre query
var genreQuery = new TermQuery(new Term("genre", genre));
var genreQueryFilter = new QueryFilter(genreQuery);
BitArray genreBitArray = genreQueryFilter.Bits(searcher.GetIndexReader());
Console.WriteLine("There are " + GetCardinality(genreBitArray) + " document with the genre " + genre);
// Next perform a regular search and get its BitArray result
Query searchQuery = MultiFieldQueryParser.Parse(term, new[] {"title", "description"}, new[] {BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD}, new StandardAnalyzer());
var searchQueryFilter = new QueryFilter(searchQuery);
BitArray searchBitArray = searchQueryFilter.Bits(searcher.GetIndexReader());
Console.WriteLine("There are " + GetCardinality(searchBitArray) + " document containing the term " + term);
// Now do the faceted search magic, combine the two bit arrays using a binary AND operation
BitArray combinedResults = searchBitArray.And(genreBitArray);
Console.WriteLine("There are " + GetCardinality(combinedResults) + " document containing the term " + term + " and which are in the genre " + genre);
}
Which will tell me i.e there is 2 records for the search term "Dublin" and which are in genre "Financial" which is perfect but the article seems to skip the part where it says how I can retrieve the indexes of those results and display on screen.
He does explain this in the link below for a normal search but not facete search..
i.e Normal Search
private static void Search(string indexPath, string term)
{
// create searcher
var searcher = new IndexSearcher(indexPath);
// create a query which searches through the title and description, the term can be in the title or the description
Query searchQuery = MultiFieldQueryParser.Parse(term, new[] {"title", "description"}, new[] {BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD}, new StandardAnalyzer());
// perform the search
Hits hits = searcher.Search(searchQuery);
// loop through all the hits and show their title
for (int hitIndex = 0; hitIndex &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt; hits.Length(); hitIndex++)
{
// get the corresponding document
Document hitDocument = hits.Doc(hitIndex);
// write its title to the console
Console.WriteLine(hitDocument.GetField("title").StringValue());
}
}
http://www.devatwork.nl/articles/lucenenet/search-basics-lucenenet/
Any help would be greatly appreciated
Edit :
Or should I do a search query and then do a Filter on the results ?
The BitArray represents hits. Each 1 has an index, that is equal to document id
So 1001001 means that documents with position 0, 3 and 6 in index match your search. You just have to retrieve them from lucene index.
var searcher = new IndexSearcher(indexPath);
// get document at position 0
var doc = searcher.Doc( 0 );