Overwrite Complex Object fields that have been edited by the user - c#

I have a complex object (seen below) that is stored on a server. A client (browser) will pull this object down and present it flattened on a webpage. The user can then edit any field data and send the field as updated text to the server. The object will updated according to only the fields that have been changed. What is the best way to do this in C#? Since the "mobile" field is nested, how would a create a mapping?
Request with changed fields (example):
{ "mobile": "999-999-9999" }
Complex Object on Server (to be updated):
{
"product": "Live JSON generator",
"version": 3.1,
"releaseDate": "2014-06-25T00:00:00.000Z",
"demo": true,
"person": {
"id": 12345,
"name": "John Doe",
"phones": {
"home": "800-123-4567",
"mobile": "877-123-1234"
},
"email": [
"jd#example.com",
"jd#example.org"
],
"dateOfBirth": "1980-01-02T00:00:00.000Z",
"registered": true,
"emergencyContacts": [
{
"name": "Jane Doe",
"phone": "888-555-1212",
"relationship": "spouse"
},
{
"name": "Justin Doe",
"phone": "877-123-1212",
"relationship": "parent"
}
]
}
}
I looked at Automapper. The issue I see with it is that I have not seen an example where an Update is done, only new creation of an object.

Related

DocuSign API: Signing issues with sending multiple documents in the same envelope

Using C#, DocuSign API SDK 4.5.2.
I'm sending out 3 documents for signatures in the same envelope. Each document will use the same server template (which just places the signature elements over the document using anchor tags). I can send out the envelope and I get the email back from DocuSign to view/sign the documents.
The issue I'm having is when I go to sign, I have to sign each document 3 times -- 9 times total -- before I'm allowed to click the Finish button. There is only 1 place to sign on each document, but I have to click the sign button 3 times before it's accepted. If I have 2 recipients, it's the same for each of them. If I change the code to send out only 1 document, it works fine so it's obvious something is not being generated correctly in the envelope request.
I have also tried giving each recipient a different Id number even though there are only 2 roles and 2 distinct names/email addresses.
Right before I call the API to actually send the document, I capture the JSON for debugging purposes:
{
"compositeTemplates": [
{
"compositeTemplateId": "1",
"document": {
"documentBase64": "---Document 1 Bytes---",
"documentId": "1",
"fileExtension": "pdf",
"name": "MultiDocument1"
},
"inlineTemplates": [
{
"recipients": {
"signers": [
{
"email": "client#gmail.com",
"name": "Client Name",
"recipientId": "1",
"roleName": "Signer1"
},
{
"email": "advisor#gmail.com",
"name": "Advisor Name",
"recipientId": "2",
"roleName": "Advisor"
}
]
},
"sequence": "2"
}
],
"serverTemplates": [
{
"sequence": "1",
"templateId": "99321CB1-A3E8-44A0-BDF4-D4F20069BC7B"
}
]
},
{
"compositeTemplateId": "2",
"document": {
"documentBase64": "---Document 2 Bytes---",
"documentId": "2",
"fileExtension": "pdf",
"name": "MultiDocument2"
},
"inlineTemplates": [
{
"recipients": {
"signers": [
{
"email": "client#gmail.com",
"name": "Client Name",
"recipientId": "1",
"roleName": "Signer1"
},
{
"email": "advisor#gmail.com",
"name": "Advisor Name",
"recipientId": "2",
"roleName": "Advisor"
}
]
},
"sequence": "2"
}
],
"serverTemplates": [
{
"sequence": "1",
"templateId": "99321CB1-A3E8-44A0-BDF4-D4F20069BC7B"
}
]
},
{
"compositeTemplateId": "3",
"document": {
"documentBase64": "---Document 3 Bytes---",
"documentId": "3",
"fileExtension": "pdf",
"name": "MultiDocument3"
},
"inlineTemplates": [
{
"recipients": {
"signers": [
{
"email": "client#gmail.com",
"name": "Client Name",
"recipientId": "1",
"roleName": "Signer1"
},
{
"email": "advisor#gmail.com",
"name": "Advisor Name",
"recipientId": "2",
"roleName": "Advisor"
}
]
},
"sequence": "2"
}
],
"serverTemplates": [
{
"sequence": "1",
"templateId": "99321CB1-A3E8-44A0-BDF4-D4F20069BC7B"
}
]
}
],
"emailSubject": "Multiple Documents for Signature",
"status": "Sent"
}
Here's one of the documents I'm using. The other 2 are similar -- different text, but using the same anchor tags.
I've also tried substituting another document I have used successfully in testing for Document 1 -- it is completely different, but still uses the same anchor tags. I'm getting the same results -- having to sign each signature 3 times.
Can anyone see what I'm doing wrong? If you need more information, please let me know.
thanks,
randy
Update: As suggested by Inbar and Larry, I contacted DocuSign Support and had the "Anchor Population Scope" setting changed from "Envelope" to "Document". Unfortunately, this made things worse. I still have to click the signature element multiple times to sign, but only the first document can be signed. The other documents do not have any signature elements attached.
Update #2: I'm wondering if the way I'm using templates might be confusing and causing these issues. I probably should have explained myself clearer. The server template I'm using has a "dummy" Word document that just contains a common set of anchor tags for signatures and dates. I uploaded it as a template and assigned the signature and date UI elements to the anchor tags. But when I'm sending a request from my application, I'm using a different document I choose/generate at runtime. This document replaces the dummy Word document in the template, but has the same anchor tags so all the signature & date elements find their places on the real document. This works great when sending out just 1 document, but I can't get things to work for more than one.
Update #3: Requirements -- We are adding digital signature capability to our website (ASP.NET, WinForms). We already have a page where an Advisor can either print out a document for a physical signature or start a digital signature process with DocuSign. All our documents come from MS Report Server because they need to contain Client data from our database. We currently do not send out any static documents. In the code behind on the page, I get the PDF bytes from Report Server and add that (as a document) to a composite template to be sent to DocuSign. It also contains a reference to a server template in my account of a Word document (see below) containing the anchor tags and signature elements (mentioned in Update #2) to be overlaid on the Report Server document. What happens is the Report Server document replaces the text of the Word template (like a form background) and because I'm using the same text as anchor tags, the signature elements on the Word template find their match on the Report Server document and move to their positions on the document. I finally include 1 or more names/email addresses of the Clients and usually 2 other required signers (Advisor and Manager). This is then sent to DocuSign (SDK API) to start the signing process. Using a single document, this is working well. We are preparing for when we will need to send more than 1 document to a Client and we'd like to do that in a single request. If you need more info, please let me know.
DocuSign Customer Service put me in touch with a Developer Support Representative who was VERY patient and helpful. I explained what I was trying to do and he was able to come up with a solution which was very easily integrated into my existing codebase.
To get this to work, you need 2 pieces of the puzzle. The first item was mentioned above: you must have the Anchor Population Scope value in your account set to "Document". This has to be done by a DocuSign Customer Service rep as the setting is not user accessible.
The second item was what was contributing to the signature tags all being stacked on the first document. In your Composite Template, the Inner Template must have a sequence number of "1" and the Server Template must use a sequence number of "2". Once both of these items were in place, I could send out multiple documents each using the same server template (to define AutoPlace tags and roles) to multiple signers in a single envelope.
Here's the sample JSON which works for me:
{
"compositeTemplates": [
{
"compositeTemplateId": "1",
"inlineTemplates": [
{
"documents": [
{
"documentBase64": "<PDF Bytes>",
"documentId": "1",
"fileExtension": "PDF",
"name": "MultiDocument1"
}
],
"recipients": {
"signers": [
{
"email": "client#email.com",
"name": "Client Name",
"recipientId": "1",
"roleName": "Signer1"
},
{
"email": "advisor#email.com",
"name": "Advisor Name",
"recipientId": "2",
"roleName": "Advisor"
}
]
},
"sequence": "1"
}
],
"serverTemplates": [
{
"sequence": "2",
"templateId": "1234xxxx-xxxx-xxxx-xxxx-xxxxxxxx5678"
}
]
},
{
"compositeTemplateId": "2",
"inlineTemplates": [
{
"documents": [
{
"documentBase64": "<PDF Bytes>",
"documentId": "2",
"fileExtension": "PDF",
"name": "MultiDocument2"
}
],
"recipients": {
"signers": [
{
"email": "client#email.com",
"name": "Client Name",
"recipientId": "1",
"roleName": "Signer1"
},
{
"email": "advisor#email.com",
"name": "Advisor Name",
"recipientId": "2",
"roleName": "Advisor"
}
]
},
"sequence": "1"
}
],
"serverTemplates": [
{
"sequence": "2",
"templateId": "1234xxxx-xxxx-xxxx-xxxx-xxxxxxxx5678"
}
]
},
{
"compositeTemplateId": "3",
"inlineTemplates": [
{
"documents": [
{
"documentBase64": "<PDF Bytes>",
"documentId": "3",
"fileExtension": "PDF",
"name": "MultiDocument3"
}
],
"recipients": {
"signers": [
{
"email": "client#email.com",
"name": "Client Name",
"recipientId": "1",
"roleName": "Signer1"
},
{
"email": "advisor#email.com",
"name": "Advisor Name",
"recipientId": "2",
"roleName": "Advisor"
}
]
},
"sequence": "1"
}
],
"serverTemplates": [
{
"sequence": "2",
"templateId": "1234xxxx-xxxx-xxxx-xxxx-xxxxxxxx5678"
}
]
}
],
"emailSubject": "Multiple Documents for Signatures",
"status": "Sent"
}
If you have any questions, please let me know. Thanks to Larry K and Inbar Gazit for the assist!
I believe the problem is that your account is set so that anchor tab positioning works across all of the documents in the envelope, not just the one document that you're applying the template to.
So you're ending up with three signing fields, positioned directly on top of one-another.
Suggestions for fixing:
Only apply the last template.
Or have your account changed so anchor positioning only affects the document the template is applied to.

How to know the interactions happened with the feed in stream?

My query goes like this: If I have a feedItem (an image posted on facebook), how can I verify that I have liked it or not? Can I verify all the interactions which I have done to the feedItem or the interactions other people have done to it (like, dislike, pin, share)? Is there any way in getstream.io to retrieve these interactions?
Thanks in advance...
Graph API provides all functions you need. Here are some examples:
Read shares[it's a field of an object]: https://developers.facebook.com/docs/graph-api/reference/v3.1/post#read
Read Shared posts: https://developers.facebook.com/docs/graph-api/reference/v3.1/object/sharedposts
read likes:
https://developers.facebook.com/docs/graph-api/reference/v3.1/object/likes#read
/likes returns only the profile for the current user if read with a
user access token:
Album, Photo, Post, Video
all returns are JSON, which you can directly Deserialize Anonymous Type without using stream, for example, likes:
{
"likes": {
"data": [
{
"name": "Bill the Cat",
"id": "155111347875779",
"created_time": "2017-06-18T18:21:04+0000"
},
{
"name": "Calvin and Hobbes",
"id": "257573197608192",
"created_time": "2017-06-18T18:21:02+0000"
},
{
"name": "Berkeley Breathed's Bloom County",
"id": "108793262484769",
"created_time": "2017-06-18T18:20:58+0000"
}
],
"paging": {
"cursors": {
"before": "Nzc0Njg0MTQ3OAZDZD",
"after": "NTcxODc1ODk2NgZDZD"
},
"next": "https://graph.facebook.com/vX.X/me/likes?access_token=user-access-token&pretty=0&summary=true&limit=25&after=NTcxODc1ODk2NgZDZD"
},
"summary": {
"total_count": 136
}
},
"id": "user-id"
}

Additional text found, but JSONLint says JSON validated correctly

On rare occasion when receiving the message "Additional text found in JSON string after finishing deserializing object." the first thing i do is fix some JSON structure typo of mine using JSONLint.
However this time the lint says the json is valid and i can't see where the problem lies. (As i don't control the data's source i need to ldeserialize to a generic object that i then traverse. - Is this possibly the error on my part?)
I'm deserializing with Unity specific Newtonsoft.Json (JsonNet-Lite)
object resultData = JsonConvert.DeserializeObject<object>(jsonString);
What am i missing?
JSON String
"{\"statements\":[{\"id\":\"14b6382c-ddb9-44c5-a22c-a133cec50711\",\"actor\":{\"objectType\":\"Agent\",\"mbox_sha1sum\":\"f7f99253cf6ede467c3a5425d05bfcd96e524595\",\"name\":\"My Name\"},\"verb\":{\"id\":\"https://w3id.org/xapi/dod-isd/verbs/completed\",\"display\":{\"en-US\":\"completed\"}},\"result\":{\"success\":true,\"completion\":true,\"duration\":\"PT0.05S\"},\"context\":{\"contextActivities\":{\"grouping\":[{\"id\":\"http://example.com/activities/MyActivity_Grandparent\",\"objectType\":\"Activity\"}],\"parent\":[{\"id\":\"http://example.com/activities/MyActivity_Parent\",\"objectType\":\"Activity\"}]}},\"timestamp\":\"2018-02-23T19:18:34.145Z\",\"stored\":\"2018-02-23T19:18:34.145Z\",\"authority\":{\"objectType\":\"Agent\",\"account\":{\"homePage\":\"http://cloud.scorm.com\",\"name\":\"abcdef-ghijk\"},\"name\":\"Test Provider\"},\"version\":\"1.0.0\",\"object\":{\"id\":\"http://example.com/activities/MyActivity\",\"definition\":{\"extensions\":{\"https://w3id.org/xapi/dod-isd/extensions/interactivity-level\":\"3\",\"https://w3id.org/xapi/dod-isd/extensions/ksa\":\"Attitude\",\"https://w3id.org/xapi/dod-isd/extensions/category\":\"Responding\",\"http://example.com/TerminalObjective\":\"My Activity Objective\"},\"name\":{\"en-US\":\"My Activity Name\"},\"description\":{\"en-US\":\"My Activity Description\"},\"type\":\"http://adlnet.gov/expapi/activities/simulation\"},\"objectType\":\"Activity\"}}],\"more\":\"/tc/Z5R2XATQZW/sandbox/statements?continueToken=e50555fe-0c3d-4663-91c4-7f0ff7df4ccf\"}"
JSON Formatted for readability
{
"statements": [{
"id": "14b6382c-ddb9-44c5-a22c-a133cec50711",
"actor": {
"objectType": "Agent",
"mbox_sha1sum": "f7f99253cf6ede467c3a5425d05bfcd96e524595",
"name": "My Name"
},
"verb": {
"id": "https://w3id.org/xapi/dod-isd/verbs/completed",
"display": {
"en-US": "completed"
}
},
"result": {
"success": true,
"completion": true,
"duration": "PT0.05S"
},
"context": {
"contextActivities": {
"grouping": [{
"id": "http://example.com/activities/MyActivity_Grandparent",
"objectType": "Activity"
}],
"parent": [{
"id": "http://example.com/activities/MyActivity_Parent",
"objectType": "Activity"
}]
}
},
"timestamp": "2018-02-23T19:18:34.145Z",
"stored": "2018-02-23T19:18:34.145Z",
"authority": {
"objectType": "Agent",
"account": {
"homePage": "http://cloud.scorm.com",
"name": "abcdef-ghijk"
},
"name": "Test Provider"
},
"version": "1.0.0",
"object": {
"id": "http://example.com/activities/MyActivity",
"definition": {
"extensions": {
"https://w3id.org/xapi/dod-isd/extensions/interactivity-level": "3",
"https://w3id.org/xapi/dod-isd/extensions/ksa": "Attitude",
"https://w3id.org/xapi/dod-isd/extensions/category": "Responding",
"http://example.com/TerminalObjective": "My Activity Objective"
},
"name": {
"en-US": "My Activity Name"
},
"description": {
"en-US": "My Activity Description"
},
"type": "http://adlnet.gov/expapi/activities/simulation"
},
"objectType": "Activity"
}
}],
"more": "/tc/Z5R2XATQZW/sandbox/statements?continueToken=e50555fe-0c3d-4663-91c4-7f0ff7df4ccf"
}
The deserialization method, you chose, is rather for a case, when you are deserializing a well-known Json to an object, which matches the structure.
In this case the Json structure does not match the System.Object type structure, you are trying to deserialize to. The library complaints, that there's much more in the Json, than in the System.Object structure.
For parsing any Json object, you could try an example from the Newtonsoft.Json documentation:
string json = #"{
CPU: 'Intel',
Drives: [
'DVD read/writer',
'500 gigabyte hard drive'
]
}";
JObject o = JObject.Parse(json);
You will still need to traverse the deserialized object. Depending on what you want to achieve, it may actually be much better to look for a .Net class that matches the Json structure (or write one).

C# Json File Add New Value

Example:
"database": {
"UUIDTOKEN": {
"name": "test",
"yearsold": "20",
"userid": "100",
"uuid": "a2b45475-aebe-4103-9c01-43ea8754dfc0",
"email": "email#gmail.com"
}
},
How to add new value ? so, database = main json text. How to add uuid {
name,yearsold,userid,uuid,email
}
"database": {
"UUIDTOKEN": {
"name": "test",
"yearsold": "20",
"userid": "100",
"uuid": "a2b45475-aebe-4103-9c01-43ea8754dfc0",
"email": "email#gmail.com"
},
"UUIDTOKEN": {
"name": "stackoverflow",
"yearsold": "24",
"userid": "110",
"uuid": "uuid-aebe-4103-9c01-43ea8754dfc0",
"email": "stackoverflow#gmail.com"
},
},
Thanks for help.
An object (the "database" in your case) can't have two fields with the same name ("UUIDTOKEN"). If you need your "database" to contain a list of "UUIDTOKEN" objects, consider changing it to an array:
{
"database": [{
"name": "test",
"yearsold": "20",
"userid": "100",
"uuid": "a2b45475-aebe-4103-9c01-43ea8754dfc0",
"email": "email#gmail.com"
}, {
"name": "stackoverflow",
"yearsold": "24",
"userid": "110",
"uuid": "uuid-aebe-4103-9c01-43ea8754dfc0",
"email": "stackoverflow#gmail.com"
}]
}
Please note, the "UUIDTOKEN" name was eliminated in this sample, but if you need it for some reason, add another object layer:
{
"database": [{
"UUIDTOKEN": {
"name": "test"
//...
}
}, {
"UUIDTOKEN": {
"name": "stackoverflow"
//...
}
}]
}
I'm not exactly sure what you are asking? Do you want to know how to add another value to a json object in c#, or do you want to know why what you've written won't work?
If it's the latter, you can't have a json object with 2 keys the same, you will need to change UUIDTOKEN to a unique key. Otherwise you could use an array.

BreezeJS navigation properties not being populated despite data being returned from server

I just upgraded from BreezeJS 1.1 to 1.4 however "expand" doesn't seem to be working? I can see my expand going to the server:
http://localhost:60198/api/Data/App?$filter=Id%20eq%209&$expand=Household%2CHousehold%2FPrimary
and I can see the data coming back:
[
{
"$id": "1",
"$type": "App.Models.Base.App, App",
"Id": 9,
"Number": "ZZZZ",
"Name": "ZZZZZ",
"Household": {
"$id": "2",
"$type": "App.Models.Base.Household, App",
"Id": 6,
"Primary": {
"$id": "3",
"$type": "App.Models.Base.Person, App",
"Id": 9,
"FirstName": "ZZZZ",
"MiddleName": "ZZZZ",
"LastName": "ZZZ",
}
},
"HouseholdId": 6
}
]
but the household property is null when I try an access it. This used to work with 1.1.
breeze.EntityQuery
.from("App")
.where("id", "==", id)
.expand("Household, Household.Primary")
which if logged as json turns into
query {"resourceName":"App","entityType":null,"wherePredicate":{"_filterQueryOp":{"_$typeName":"FilterQueryOp","name":"Equals"},"_propertyOrExpr":"id","_value":9,"_valueIsLiteral":false},"orderByClause":null,"selectClause":null,"skipCount":null,"takeCount":null,"expandClause":{"propertyPaths":["Household","Household.Primary"]},"parameters":{},"inlineCountEnabled":false,"entityManager":null}
Update: I downgraded to 1.2.5 and it works again. I looked around in the code and it appears like this check here:
https://github.com/IdeaBlade/Breeze/blob/master/Breeze.Client/Scripts/breeze.debug.js#L13312
was return false and therefore the entity was not being updated? Who knows I am very new to the breeze codebase.
The navigation properties were not setup correctly.

Categories