How to perform a simple Couchbase Lite query - c#

I wanted to know how it's possible to do some simple CouchbaseLite queries.
I have a document named "test", with key-values "id": 5 and "name":"My first test".
I wanted to search following:
I want to get the id (5) where name = "My first test".
I also wanted to know if this name = "My first test" entry is already available? I only wanted to add it if it's not there.
Database db = new Database("test_db");
using (var testDoc = new MutableDocument("test"))
{
testDoc.SetInt("id", 5)
.SetString("name", "My first test");
db.Save(testDoc);
}
Thanks!

Assuming I understood your question right that you want to fetch documents with a specific property value only if it exists, you can do something like this
var query = QueryBuilder.Select(SelectResult.expression(Meta.id),
SelectResult.expression(Expression.property("id")))
.From(DataSource.Database(db))
.Where(Expression.Property("name").NotNullOrMissing()
.And(Expression.Property("name").EqualTo(Expression.string("My first test"))))
Alternatively, if you know the Id of the document, it would be faster to do a GetDocument with the Id. Once you have the document, do a GetString on the name property. If it returns null, you can assume it does not exist.
Refer to the documentation on Couchbase Lite query fundamentals here.There are several examples. You may also want to check out API specs on NotNullOrMissing

Related

Schema.NET HowTo item cannot add more than one step

I've been trying to use Schema.NET to generate HowTo schema on certain articles. I have not been able to use this because I can only add a single step to the HowTo element. Google validation says I need at least 2 steps. Google samples show a step array, but again, I can only add a single step using Schema.NET.HowTo class.
var schema = new HowTo()
{
Name = "How to tie make pie",
Description = "If you want to make pie...",
Step = //This property's type is Values<ICreativeWork, IHowToSection, IHowToStep, string>
};
For reference, here are Google's examples: https://developers.google.com/search/docs/data-types/how-to#standard
Any idea on how to make this work?
I just look closer at the Values object and noticed you can use an array of IHowToStep object.

How to modify a record with a Specific ListID in Quickbooks Using c#

I am new to QuickBooks development.
I have successfully managed to call add records and query but I am having problems figuring out how to modify records.
I have quick books ListIds stored in a separate system, I would like modify the specific record in Quickbooks using the list ID as a defining criteria.
I am using c#.
I have a QSessionManager and IMsgSetDefined defined.
So to preform a modification on say vendor I would imaging that I would proceed as follows:
QBSessionManager sessionManager = new SessionManager();
sessionManager.OpenConnection("MyAPP", "My Name");
sessionManader.BeginSession(companyFile, ENOpenMode.omDontCare);
IMsgSetRequest msgSetRq = qbSessionManager.CreateMsgSetRequest("CA", 7, 0);
IVendorMod vndrMod = msgSetRq.AppendVendorModRq();
vndrMod.CompanyName.SetValue("TEST COMPANY");
//TODO ADD A FILTER ON ListID
IMsgSetResponse responseSet = sessionManager.DoRequests(msgSetRq);
My initial reaction is to try a Filter similar to this:
vndrQry.ORVendorListQuery.VendorListFilter.ActiveStatus.SetValue(ENActiveStatus.asActiveOnly);
That however does not appear to the way to proceed.
vndrMod.ListID.SetValue("<ListID>");
vndrMod.EditSequence.SetValue("<EditSeq>");
Edit Sequence must be valid (ie from) from quickbooks.
And list id is immutable this is not a change value field.

Salesforce: create Opportunity Line Items along with Opportunity from C#

using Salesforce's enterprise wsdl I am trying to save opportunity line items along with opportunity. But I am getting following error:
INVALID_FIELD: No such column 'OpportunityLineItems' on entity 'Opportunity' If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
Here is my code to create line items:
if (oppLineItems.Count > 0)
{
sfOpportunity.OpportunityLineItems = new QueryResult();
sfOpportunity.HasOpportunityLineItem = true;
sfOpportunity.OpportunityLineItems.records = oppLineItems.Values.ToArray();
Pricebook2 priceBook = new Pricebook2();
priceBook.PricebookEntries = new QueryResult();
priceBook.PricebookEntries.records = new List<PricebookEntry>() { priceBookEntry }.ToArray();
sfOpportunity.Pricebook2 = priceBook;
}
oppLineItems is a dictionary whole values have proxy objects of opportunity line items.
sfOpportunity is proxy object of Opportunity which is then sent to Salesforce.
There's a very similar question here, not sure if we should mark it as duplicate though: Salesforce: Creating OpportunityLineItems as part of the Opportunity in PHP
OpportunityLineItems on Opportunity isn't a real field. Its something called "relationship name"... Similar to table alias in normal databases, useful especially when you're making joins. And HasOpportunityLineItem is a readonly field :) And I don't think these should be QueryResult, check http://www.salesforce.com/us/developer/docs/api/Content/sample_create_call.htm for some hints?
You will need to insert the Opportunity first, the operation result will give you the record's Id. Then you should insert a list (array) of the line items.
This means 2 API calls and extra considerations what to do when the Opp header saves OK but one or more lines fails... So maybe it's good idea to write an Apex webservice like I suggested in that other question.

How to Insert a copy of a row (with a new identity) using LINQ to SQL?

I have a number of tables that together make up a "Test" that somebody can take. There are multiple types (scripts) of Test a person can take. I'm working on an Edit function that will allow somebody to edit the Test Questions. I want these edited questions to show up on all new Tests of that type, but still show the old questions when viewing past test scores.
To do this each "Test" has a TestId auto-increment identity (along with its name). When a test is edited I want to make a copy of the test with a new TestId and present the questions for editing.
So what is the best way to make the copy and insert it into my table using LINQ to SQL? This:
DataContext db = new DataContext(ConnectionString);
//Copy old test into identical new test but with a different script ID
var oldScript = db.TestScripts.Single(ds => ds.TestScriptId == oldScriptID);
var newScript = oldScript;
db.TestScripts.InsertOnSubmit(newScript);
db.SubmitChanges();
of course tells me that I Cannot add an entity that already exists.
Is the only way to do this to go through every column in the TestScript and copy it manually, then insert it, and the database will give it a new Id?
Edit
I've also tried
DataContext db = new DataContext(ConnectionString);
//Copy old test into identical new test but with a different script ID
var oldScript = db.TestScripts.Single(ds => ds.TestScriptId == oldScriptID);
var newScript = new TestScript();
db.TestScripts.InsertOnSubmit(newScript);
db.SubmitChanges();
hoping that it would make a new empty row, then I could newScript = oldScript and submit the changes, but it gives me SqlDateTime overflow errors.
Is the cloning part overhere what you are looking for?
http://damieng.com/blog/2009/04/12/linq-to-sql-tips-and-tricks-2
Warning: Ugly hacky untested possibility
How about setting the id to null?
newScript.TestScriptId = null
db.TestScripts.InsertOnSubmit(newScript);
Well I see two ways for you:
Just make a "make copy" function that copies all the attributes over
Use reflection to automaticly copy all properties with the [column] attribute over (Thats a little bit hardcore, and can be alittle magical, if you get it to work)
There are some "magic" functions floating around the web, that saids that they can do it, but I would prefer number 1, and have full control myself.
Also: Ask yourself it it's really the right DB schema you are using, the you need to copy an entire tree, if a person makes a change - maybe a DB change, can make this way easier for you?

Dropdown with image and text together in Asp.net 3.5 and jquery

I've been given a task to make a dynamic drop down which takes it's data[image and value id] from table. I am wondering if any of you came across this scenario or if any one can help me out in this I need help in concept and coding. Definitely any help is appreciated.
I see the example in jquery here is the link:
http://www.marghoobsuleman.com/jquery-image-dropdown
something like this but data is coming from table.
If you use the plugin that you found in the link, then basically what you will want to do is create the dropdown dynamically based on the table content. Without having more details of how your table is structured I can't give you exact details, but something like this should get you close (I'm going to assume there is a drop-down element already on the page somewhere called "select", and your table is called "table" with the image in field 0, and the text in field 1) Note: This hasn't really been tested.
var options = "";
$("#table tr").each(function() {
var imagePath = $(this).find("td:eq(0) img").attr("src");
var title = $(this).find("td:eq(1)").text();
options += '<option value="'+title+'" title="'+imagePath+'">'+title+'</option>';
});
$("#select").html(options);

Categories