Retrieve Card Detail from Stripe Customer Id - asp.net

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_BQokikJOvBiI2HlWgH4ol‌fQ2");
StripeConfiguration.SetApiKey("sk_test_BQokikJOvBiI2HlWgH4ol‌​fQ2");
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();

Related

IBM Watson Assistant: Why is "Try It" giving me the correct results but my client code is not?

I have created a chat bot in Watson Assistant (see attached workspace file). In "try it" it gives correct results.
I have created a client application to consume this chat using ASP.NET Core. There, I am saving the context. Still, the result I am getting is different than "try it".
Steps to simulate the issue:
me: Hello
reply from watson: Hello, please enter your Supplier Number for authentication.
me: 135587-1239848
reply from watson: For authentication purpose, I have sent an One Time Password (OTP) to your registered mobile number for supplier [135587-1239848]. Please enter the 6 digit OTP number
me: 121212
reply from watson: Welcome Richie. I am Shery from EXL. How can I help you today?
me: where is my invoice ?
reply from watson: Sure Richie, I can help with that! Can you please provide the Invoice number?
Till the 8th step both "try it" and ASP.NET Core client application return the same results. But at 8th step my client application again says "For authentication purpose, I have sent an One Time Password (OTP) to your registered mobile number for supplier [135587-1239848]. Please enter the 6 digit OTP number" instead of Sure Richie, I can help with that! Can you please provide the Invoice number?
Please suggest. Attached asp.net code (WatsonAPI.txt) as well what I am passing to WATSON API.
public string CallConversation(string input)
{
if (_conversation == null)
{
//_conversation = new ConversationService(_username.ToString(), _password.ToString(), "2018-05-16");
_conversation = new ConversationService(_username.ToString(), _password.ToString(), "2018-02-16");
_conversation.Endpoint = _url.ToString();
_workspaceID = _workspaceID.ToString();
}
MessageRequest messageRequest = new MessageRequest()
{
Input = new InputData()
{
//Text = _questionArray[questionIndex]
Text = input//Console.ReadLine()
},
AlternateIntents = true
};
// if (_questionContext != null)
if (Session["Context"] != null)
{
_questionContext = (dynamic)Session["Context"];
messageRequest.Context = new Context();
messageRequest.Context.ConversationId = _questionContext.conversation_id;
messageRequest.Context.System = _questionContext.system;
}
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var result = _conversation.Message(_workspaceID, messageRequest);
//Console.WriteLine(string.Format("result: {0}", JsonConvert.SerializeObject(result, Formatting.Indented)));
string strResult = "";
if (((Newtonsoft.Json.Linq.JProperty)((Newtonsoft.Json.Linq.JContainer)result.Output).First) != null)
strResult = string.Format(((Newtonsoft.Json.Linq.JProperty)((Newtonsoft.Json.Linq.JContainer)result.Output).First).Value.ToString().Replace(Environment.NewLine, ""));
//int intstart = strResult.IndexOf('"');
//Console.WriteLine(strResult.Replace("[", "").Replace("]", "").Replace("\"", "").Trim());
string strOutput = strResult.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
if (strResult.Contains("Welcome Richie. I am Shery from EXL."))
{
strOutput = "Welcome " + Convert.ToString(Session["supplierName"]) + ". I am Shery from EXL. How can I help you today?";
}
if (strResult.Contains("I have sent an One Time Password (OTP) to your registered mobile number for supplier "))
{
List<string> lstInvoicedetais = new List<string>();
lstInvoicedetais = strResult.Split('[').ToList<string>();
supplierNumber = lstInvoicedetais[2].ToString();
lstInvoicedetais = supplierNumber.Split(']').ToList<string>();
supplierNumber = lstInvoicedetais[0].ToString();
supplierName = ValidateSupplierByNumber(supplierNumber);
if (string.IsNullOrEmpty(supplierName))
{
strOutput = "Invalid Supplier number [" + supplierNumber + "]. Please enter correct supplier number.";
result.Context.supplierNumber = "0";
//_questionContext.supplierNumber = "";
setContext = false;
Session["supplierNumber"] = null;
Session["supplierName"] = null;
}
else
{
Session["supplierNumber"] = supplierNumber;
Session["supplierName"] = supplierName;
//strOutput = "Invalid Supplier number [" + supplierName + "]. Please enter correct supplier number.";
}
}
if (strResult.Contains("Sure Richie, I can help with that! Can you please provide the Invoice number?"))
{
strOutput = strOutput.Replace("Richie", Convert.ToString(Session["supplierName"]));
//strOutput = strResult;
}
if (strResult.Contains("Let me fetch the details you requested for Invoice"))
{
//List<chatSummary> lstChatSummary = new List<chatSummary>();
//lstChatSummary = (List<chatSummary>)Session["lstChatSummary"];
//lstChatSummary.Add(new chatSummary()
//{
// ByUser = "User: ",
// Message = strResult
//});
//Session["lstChatSummary"] = lstChatSummary;
//AddRowtoTable("User:", strResult);
strValue.Append(Environment.NewLine + "Bot: " + strOutput.ToString());
//textBox1.Text = strValue.ToString();
//textBox1.Text = string.Empty;
//textBox1.AppendText(strValue.ToString());
string strMessage = string.Empty;
invoiceNumber = SearchbyInvoice(strResult, (string)Session["supplierNumber"], out strMessage);
List<chatSummary> lstChatSummary = (List<chatSummary>)Session["lstChatSummary"];
if (strMessage != string.Empty)
{
lstChatSummary.Add(new chatSummary()
{
ByUser = "BOT: ",
Message = strMessage
});
}
strMessage = "Hope I provided the information you are looking for. Is there anything else that I can help you ?";
strOutput = strMessage;
}
if (strResult.Contains("Please provide Invoice Amount for the invoice Dated"))
{
List<string> lstInvoicedetais = new List<string>();
lstInvoicedetais = strResult.Split('[').ToList<string>();
invoiceDate = lstInvoicedetais[2].ToString();
lstInvoicedetais = invoiceDate.Split(']').ToList<string>();
invoiceDate = lstInvoicedetais[0].ToString();
SearchbyInvoiceDate(invoiceDate, supplierNumber, out string strMessage);
List<chatSummary> lstChatSummary = (List<chatSummary>)Session["lstChatSummary"];
if (strMessage != string.Empty)
{
lstChatSummary.Add(new chatSummary()
{
ByUser = "BOT: ",
Message = strMessage
});
}
strMessage = "Hope I provided the information you are looking for. Is there anything else that I can help you ?";
strOutput = strMessage;
//strOutput = "Commeted above";
}
if (strResult.Contains("Searching for the invoice with invoice date"))
{
strValue.Append(Environment.NewLine + "Bot: " + strOutput.ToString());
//textBox1.Text = strValue.ToString();
//textBox1.Text = string.Empty;
//textBox1.AppendText(strValue.ToString());
List<string> lstInvoicedetais = new List<string>();
lstInvoicedetais = strResult.Split('[').ToList<string>();
invoiceAmt = lstInvoicedetais[3].ToString();
lstInvoicedetais = invoiceAmt.Split(']').ToList<string>();
invoiceAmt = lstInvoicedetais[0].ToString();
}
_questionIndex++;
if (setContext == true)
{
_questionContext = result.Context;
Session["Context"] = result.Context;
}
else
{
setContext = true;
}
//if (questionIndex < 100)
// CallConversation(_questionIndex);
return strOutput;
}
{"name":"Test_VendorEnquiry","intents":[{"intent":"Notavailable","examples":[{"text":"I don�t know"},{"text":"I am not sure"},{"text":"I don�t have it"},{"text":"I do not know"},{"text":"I do not have it"},{"text":"not sure"}],"description":null},{"intent":"Invoice_Status","examples":[{"text":"Let me know status of my inovice"},{"text":"I want to know my invoice status"},{"text":"I want to know status of my Invoice"},{"text":"what is my invoice status"},{"text":"Let me know status of my invoice ?"},{"text":"where is my invoice ?"},{"text":"In what state my invoice is ?"},{"text":"Is my invoice is processed ?"}],"description":null},{"intent":"greetings","examples":[{"text":"hi"},{"text":"hi how are u"},{"text":"hi there"},{"text":"Hi watson"},{"text":"hiya"},{"text":"Hola"},{"text":"I am not feeling good"},{"text":"howdy"},{"text":"How are you doing?"},{"text":"yo"},{"text":"yello"},{"text":"namaste"},{"text":"hola como estas"},{"text":"Its not that good"},{"text":"I'm feeling good thanks"},{"text":"greetings"},{"text":"aloha"},{"text":"bad"},{"text":"bonjour"},{"text":"buenos dias"},{"text":"ciao"},{"text":"feeling bit low"},{"text":"g'day"},{"text":"good"},{"text":"good day"},{"text":"good evening"},{"text":"good how are you"},{"text":"good morning"},{"text":"Hello"},{"text":"Hello, how are you?"},{"text":"Hello Watson"},{"text":"hey"},{"text":"heya"},{"text":"hey there"}],"description":null},{"intent":"goodbyes","examples":[{"text":"adieu"},{"text":"gotta go"},{"text":"good night"},{"text":"good day"},{"text":"good bye"},{"text":"goodbye"},{"text":"farewell"},{"text":"cya"},{"text":"bye now"},{"text":"bye bye"},{"text":"BYE"},{"text":"au revoir"},{"text":"adios"},{"text":"gtg"},{"text":"have to go"},{"text":"have to leave"},{"text":"have to run"},{"text":"I'm leaving"},{"text":"later"},{"text":"laters"},{"text":"logging off"},{"text":"my time is up"},{"text":"need to go"},{"text":"need to leave"},{"text":"need to run"},{"text":"ok bye"},{"text":"out of time"},{"text":"over and out"},{"text":"see ya"},{"text":"see ya later"},{"text":"see ya soon"},{"text":"see you"},{"text":"see you later"},{"text":"see you soon"},{"text":"should be going"},{"text":"should go"},{"text":"signing off"},{"text":"signing out"},{"text":"so long"},{"text":"thanks watson"},{"text":"thank you for your help"},{"text":"then bye"},{"text":"time to go"},{"text":"toodles"},{"text":"got to go"},{"text":"gotta run"}],"description":null}],"entities":[{"entity":"OTPNumber","values":[{"type":"patterns","value":"OTPNumber","metadata":null,"patterns":["(\\d{6})"]}],"metadata":null,"description":null},{"entity":"sys-person","values":[],"metadata":null,"description":null},{"entity":"sys-time","values":[],"metadata":null,"description":null},{"entity":"InvoiceNumformat","values":[{"type":"patterns","value":"invoiceNumFormat","metadata":null,"patterns":["^[a-zA-Z0-9]+$"]}],"metadata":null,"description":null},{"entity":"sys-date","values":[],"metadata":null,"description":null},{"entity":"sys-percentage","values":[],"metadata":null,"description":null},{"entity":"sys-currency","values":[],"metadata":null,"description":null},{"entity":"sys-number","values":[],"metadata":null,"description":null},{"entity":"sys-location","values":[],"metadata":null,"description":null},{"entity":"supplierNumber","values":[{"type":"patterns","value":"suppNumber","metadata":null,"patterns":["(\\d{6})-(\\d{7})","(\\d{5})-(\\d{6})","(\\d{6})-(\\d{6})","(\\d{5})-(\\d{7})","(\\d{4})-(\\d{7})"]}],"metadata":null,"description":null,"fuzzy_match":true}],"language":"en","metadata":{"api_version":{"major_version":"v1","minor_version":"2017-05-26"}},"description":"","dialog_nodes":[{"type":"standard","title":"Send OTP for Supplier","output":{"text":{"values":["For authentication purpose, I have sent an One Time Password (OTP) to your registered mobile number for supplier [$supplierNumber]. Please enter the 6 digit OTP number"],"selection_policy":"sequential"}},"parent":"node_1_1533652772745","context":{"supplierNumber":"<? input.text ?>"},"metadata":{},"next_step":null,"conditions":"#supplierNumber","description":null,"dialog_node":"node_2_1533653340211","previous_sibling":null},{"type":"standard","title":"If invoice date is not avilable","output":{"text":{"values":["Need to have at least Invoice Number or Invoice Date."],"selection_policy":"sequential"}},"parent":"node_5_1533723730779","context":null,"metadata":{},"next_step":null,"conditions":"#Notavailable","description":null,"dialog_node":"node_9_1533723922103","previous_sibling":"node_6_1533723769818"},{"type":"standard","title":"Search with Invoice date & Invoice Amount","output":{"text":{"values":["Please provide Invoice Amount for the invoice Dated [$InvoiceDate]."],"selection_policy":"sequential"}},"parent":"node_5_1533723730779","context":{"InvoiceDate":"#sys-date"},"metadata":{},"next_step":null,"conditions":"#sys-date","description":null,"dialog_node":"node_6_1533723769818","previous_sibling":null},{"type":"standard","title":"If invoice number is not there","output":{"text":{"values":["Please provide Invoice Date ?"],"selection_policy":"sequential"}},"parent":"node_3_1533653519184","context":null,"metadata":{},"next_step":null,"conditions":"#Notavailable","description":null,"dialog_node":"node_5_1533723730779","previous_sibling":"node_4_1533723673094"},{"type":"standard","title":"Search with Invoice Number","output":{"text":{"values":["Let me fetch the details you requested for Invoice [$InvoiceNumber] . Please hold on for a moment..."],"selection_policy":"sequential"}},"parent":"node_3_1533653519184","context":null,"metadata":{},"next_step":null,"conditions":"#InvoiceNumformat","description":null,"dialog_node":"node_4_1533723673094","previous_sibling":null},{"type":"standard","title":"Search with Invoice Date and Amount","output":{"text":{"values":["Searching for the invoice with invoice date [$InvoiceDate] with amount [$InvoiceAmount]. Please wait..."],"selection_policy":"sequential"}},"parent":"node_6_1533723769818","context":{"InvoiceAmount":"#sys-currency"},"metadata":{},"next_step":null,"conditions":"#sys-currency","description":null,"dialog_node":"node_8_1533723852451","previous_sibling":"node_7_1533723817717"},{"type":"standard","title":"If invoice amount is not available","output":{"text":{"values":["Need to have both Invoice amount and Invoice Date to search invoice status. So please let us know Invoice Number or Invoice Date."],"selection_policy":"sequential"}},"parent":"node_6_1533723769818","context":null,"metadata":{},"next_step":null,"conditions":"#Notavailable","description":null,"dialog_node":"node_7_1533723817717","previous_sibling":null},{"type":"standard","title":"Enter OTP and proceed with Invoice Search","output":{"text":{"values":[],"selection_policy":"sequential"}},"parent":"node_2_1533653340211","context":{"SupplierValidated":"True"},"metadata":{},"next_step":{"behavior":"jump_to","selector":"body","dialog_node":"node_3_1533653519184"},"conditions":"#OTPNumber && $InvoiceStatusRequested==2","description":null,"dialog_node":"node_4_1533714921647","previous_sibling":"node_2_1533714230483"},{"type":"standard","title":"Enter OTP and ask what user wants to know","output":{"text":{"values":["Welcome Richie. I am Shery from EXL. How can I help you today?"],"selection_policy":"sequential"}},"parent":"node_2_1533653340211","context":{"SupplierValidated":"True"},"metadata":{},"next_step":null,"conditions":"#OTPNumber && $supplierNumber!=0 && $InvoiceStatusRequested!=2","description":null,"dialog_node":"node_2_1533714230483","previous_sibling":null},{"type":"standard","title":null,"output":{"text":{"values":[],"selection_policy":"sequential"}},"parent":null,"context":{"InvoiceStatusRequested":2},"metadata":{},"next_step":{"behavior":"jump_to","selector":"body","dialog_node":"node_1_1533652772745"},"conditions":"#Invoice_Status && $supplierNumber:0","description":null,"dialog_node":"node_1_1533800680816","previous_sibling":"node_1_1533652772745"},{"type":"standard","title":"Vendor Validation","output":{"text":{"values":["Hello, please enter your Supplier Number for authentication.","please provide your Supplier Number to assist you better."],"selection_policy":"sequential"}},"parent":null,"context":null,"metadata":{},"next_step":null,"conditions":"#greetings && $supplierNumber:0","description":null,"dialog_node":"node_1_1533652772745","previous_sibling":"node_1_1533713219851"},{"type":"standard","title":"Vendor already Validated","output":{"text":{"values":["Sure Richie, I can help with that! Can you please provide the Invoice number?"],"selection_policy":"sequential"}},"parent":null,"context":{"InvoiceStatusRequested":2},"metadata":{},"next_step":null,"conditions":"#Invoice_Status && $supplierNumber!=0 && $SupplierValidated==\"True\"","description":null,"dialog_node":"node_3_1533653519184","previous_sibling":"node_1_1533800680816"},{"type":"standard","title":null,"output":{"text":{"values":[],"selection_policy":"sequential"}},"parent":null,"context":null,"metadata":{},"next_step":{"behavior":"jump_to","selector":"condition","dialog_node":"node_2_1533653340211"},"conditions":"$supplierNumber:0 && #supplierNumber","description":null,"dialog_node":"node_5_1533715230884","previous_sibling":"Welcome"},{"type":"standard","title":"Goodbye","output":{"text":{"values":["Thank you. Good day"],"selection_policy":"sequential"}},"parent":null,"context":null,"metadata":{},"next_step":null,"conditions":"#goodbyes","description":null,"dialog_node":"node_10_1533724000756","previous_sibling":"node_3_1533653519184"},{"type":"standard","title":null,"output":{"text":{"values":[],"selection_policy":"sequential"}},"parent":null,"context":null,"metadata":{},"next_step":{"behavior":"jump_to","selector":"body","dialog_node":"node_1_1533652772745"},"conditions":"#greetings && $supplierNumber!=0","description":null,"dialog_node":"node_1_1533713219851","previous_sibling":"node_1_1533722523080"},{"type":"standard","title":"Anything else","output":{"text":{"values":["I didn't understand. You can try rephrasing.","Can you reword your statement? I'm not understanding.","I didn't get your meaning."],"selection_policy":"sequential"}},"parent":null,"context":null,"metadata":{},"next_step":null,"conditions":"anything_else","description":null,"dialog_node":"Anything else","previous_sibling":"node_10_1533724000756"},{"type":"standard","title":"Validate OTP if not entered","output":{"text":{"values":[],"selection_policy":"sequential"}},"parent":null,"context":{"InvoiceStatusRequested":2},"metadata":{},"next_step":{"behavior":"jump_to","selector":"body","dialog_node":"node_2_1533653340211"},"conditions":"$supplierNumber!=0 && $SupplierValidated!=\"True\" && #Invoice_Status","description":null,"dialog_node":"node_1_1533722523080","previous_sibling":"node_5_1533715230884"},{"type":"standard","title":"Welcome","output":{"text":{"values":["Hi, welcome to EXL Vendor Information Portal. Can you please provide your Supplier Number so that I can assist you better"],"selection_policy":"sequential"}},"parent":null,"context":{"supplierNumber":0,"SupplierValidated":"False","InvoiceStatusRequested":0},"metadata":{},"next_step":null,"conditions":"welcome","description":null,"dialog_node":"Welcome","previous_sibling":null}],"workspace_id":"ea8429e3-5eaa-4e94-935a-916bf3a769be","counterexamples":[],"system_settings":null,"learning_opt_out":false}
A couple comments:
Is your client app using the same API version as the "Try it"?
It is bad programming style to check for exact responses in your app. What happens if you change the response in Watson Assistant or support multiple languages? Use a combination of intents and placeholders. It is faster, too.
Do you really send back all context variables to correctly process the conditions for the dialog nodes? How is OTPNumber checked? Is it missing in the case of your app?

List<String> to String in C#

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);

google api .net client v3 getting free busy information

I am trying to query free busy data from Google calendar. Simply I am providing start date/time and end date/time. All I want to know is if this time frame is available or not. When I run below query, I get "responseOBJ" response object which doesn't seem to include what I need. The response object only contains start and end time. It doesn't contain flag such as "IsBusy" "IsAvailable"
https://developers.google.com/google-apps/calendar/v3/reference/freebusy/query
#region Free_busy_request_NOT_WORKING
FreeBusyRequest requestobj = new FreeBusyRequest();
FreeBusyRequestItem c = new FreeBusyRequestItem();
c.Id = "calendarresource#domain.com";
requestobj.Items = new List<FreeBusyRequestItem>();
requestobj.Items.Add(c);
requestobj.TimeMin = DateTime.Now.AddDays(1);
requestobj.TimeMax = DateTime.Now.AddDays(2);
FreebusyResource.QueryRequest TestRequest = calendarService.Freebusy.Query(requestobj);
// var TestRequest = calendarService.Freebusy.
// FreeBusyResponse responseOBJ = TestRequest.Execute();
var responseOBJ = TestRequest.Execute();
#endregion
Calendar API will only ever provide ordered busy blocks in the response, never available blocks. Everything outside busy is available. Do you have at least one event on the calendar
with the given ID in the time window?
Also the account you are using needs to have at least free-busy access to the resource to be able to retrieve availability.
I know this question is old, however I think it would be beneficial to see an example. You will needed to actually grab the Busy information from your response. Below is a snippet from my own code (minus the call) with how to handle the response. You will need to utilized your c.Id as the key to search through the response:
FreebusyResource.QueryRequest testRequest = service.Freebusy.Query(busyRequest);
var responseObject = testRequest.Execute();
bool checkBusy;
bool containsKey;
if (responseObject.Calendars.ContainsKey("**INSERT YOUR KEY HERE**"))
{
containsKey = true;
if (containsKey)
{
//Had to deconstruct API response by WriteLine(). Busy returns a count of 1, while being free returns a count of 0.
//These are properties of a dictionary and a List of the responseObject (dictionary returned by API POST).
if (responseObject.Calendars["**YOUR KEY HERE**"].Busy.Count == 0)
{
checkBusy = false;
//WriteLine(checkBusy);
}
else
{
checkBusy = true;
//WriteLine(checkBusy);
}
if (checkBusy == true)
{
var busyStart = responseObject.Calendars["**YOUR KEY HERE**"].Busy[0].Start;
var busyEnd = responseObject.Calendars["**YOUR KEY HERE**].Busy[0].End;
//WriteLine(busyStart);
//WriteLine(busyEnd);
//Read();
string isBusyString = "Between " + busyStart + " and " + busyEnd + " your trainer is busy";
richTextBox1.Text = isBusyString;
}
else
{
string isFreeString = "Between " + startDate + " and " + endDate + " your trainer is free";
richTextBox1.Text += isFreeString;
}
}
else
{
richTextBox1.Clear();
MessageBox.Show("CalendarAPIv3 has failed, please contact support\nregarding missing <key>", "ERROR!");
}
}
My suggestion would be to break your responses down by writing them to the console. Then, you can "deconstruct" them. That is how I was able to figure out "where" to look within the response. As noted above, you will only receive the information for busyBlocks. I used the date and time that was selected by my client's search to show the "free" times.
EDIT:
You'll need to check if your key exists before attempting the TryGetValue or searching with a keyvaluepair.

How to get spcial item in QuickBooks online by Programming

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

Lucene.NET & Facete Search Solution

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;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 );

Resources