datatable js ajax pass variable to C# serverside method - c#

I have a datatable that is being populated via serverside ajax. I need to pass variables to the serverside C# method. The variables are not getting to the serverside.
I've tried a few different approaches. It should be pretty easy.
var tblApplication = $('#tblApplication').DataTable({
"ajax": {
"url": '../../Search/ApplicationList',
"type": 'POST',
"data":{
yearh: 2014,
make: ''
}
},
"autoWidth": false,
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$(nRow).addClass("parent");
return nRow;
},
"order": [[1, "desc"]],
"deferRender": true,
"columns": [
{
"title": '',
"class": 'details-control',
"orderable": false,
"data": null,
"defaultContent": '<img src="../../assets/images/details_open.png" />'
},
{ "title": 'ApplicationId', "data": 'ApplicationId', "visible": false },
{ "title": 'Year', "data": 'Year' },
{ "title": 'Make', "data": 'Make' },
{ "title": 'Model', "data": 'Model' },
{ "title": 'Qualifier', "data": 'Qualifier' },
{ "title": 'Axle', "data": 'Axle' },
{ "title": 'Pad Set', "data": 'PadSet' },
{ "title": 'Side', "data": 'Side' },
{ "title": 'Part List', "data": 'PartListId' }
]
});
[HttpPost]
public JsonResult ApplicationList(int year = 0, string make = null )
{
}

According to datatables.js reference you need to extend "data" something like following to make it work;
$('#example').dataTable( {
"ajax": {
"url": "data.json",
"data": function ( d ) {
return $.extend( {}, d, {
"extra_search": $('#extra').val(),
"year": 2014,
"make": 'Nissan'
} );
}
}
} );
For further documentation please see the this. Hope this helps.

Related

Applying Term, Filter and Aggregation in one Es Query using Nest

I'm using ElasticSearch's Nest 7.17.x to try and applying a Term, Filter and Aggregation all on single query.
The Term is a document id restriction which should restrict all following filters and aggregations. The Filter is to restriction the price to a specific range. The aggregation to is to make price buckets.
In the example below, is looks like both the price filter and term restriction arent being applied as I'm being returned documents with ids outside of the restriction and with prices larger than the filter.
var orderChangedArgFilter = client.Search<Product>(s => s
.Query(q => +q.Terms(p => p.Field("id").Terms(productIds)))
.Aggregations(aggs => aggs
.Filter("user filter with aggs", f => f
.Filter(q => q.Range(rf => rf.Field("price").GreaterThanOrEquals(0.01).LessThan(50.0)))
.Aggregations(childAggs => childAggs
.Range("0 to 50 price agg", r => r.Field("price").Ranges(rs => rs.From(0.0).To(50.0)))
.Range("50 to 100 price agg", r => r.Field("price").Ranges(rs => rs.From(50.0).To(100.0)))
.Range("100 to 150 price agg", r => r.Field("price").Ranges(rs => rs.From(100.0).To(150.0)))
)
)
)
);
How do I correct the query to have the Term restriction apply first and then the filter on top of it?
Edit 1:
It looks like the document Id term restriction is working as expected but the filter is not.
My engine was created via AppSearch. Looks like the datatype for the price field is actually text instead of number (on the abstracted elastic engine), even though I've specified number on the AppSearch engine. This seems to be the cause of the problem.
The raw index mappings
{
".ent-search-engine-documents-luke-test": {
"mappings": {
"dynamic": "true",
"properties": {
"price": {
"fields": {
"prefix": {
"search_analyzer": "q_prefix",
"type": "text",
"analyzer": "i_prefix",
"index_options": "docs"
},
"enum": {
"ignore_above": 2048,
"type": "keyword"
},
"float": {
"ignore_malformed": true,
"type": "double"
},
"joined": {
"search_analyzer": "q_text_bigram",
"type": "text",
"analyzer": "i_text_bigram",
"index_options": "freqs"
},
"stem": {
"type": "text",
"analyzer": "iq_text_stem"
},
"delimiter": {
"type": "text",
"analyzer": "iq_text_delimiter",
"index_options": "freqs"
},
"location": {
"ignore_malformed": true,
"type": "geo_point",
"ignore_z_value": false
},
"date": {
"ignore_malformed": true,
"type": "date",
"format": "strict_date_time||strict_date"
}
},
"type": "text",
"analyzer": "iq_text_base",
"index_options": "freqs"
},
"id": {
"type": "keyword"
},
"title": {
"fields": {
"prefix": {
"search_analyzer": "q_prefix",
"type": "text",
"analyzer": "i_prefix",
"index_options": "docs"
},
"enum": {
"ignore_above": 2048,
"type": "keyword"
},
"float": {
"ignore_malformed": true,
"type": "double"
},
"joined": {
"search_analyzer": "q_text_bigram",
"type": "text",
"analyzer": "i_text_bigram",
"index_options": "freqs"
},
"stem": {
"type": "text",
"analyzer": "iq_text_stem"
},
"delimiter": {
"type": "text",
"analyzer": "iq_text_delimiter",
"index_options": "freqs"
},
"location": {
"ignore_malformed": true,
"type": "geo_point",
"ignore_z_value": false
},
"date": {
"ignore_malformed": true,
"type": "date",
"format": "strict_date_time||strict_date"
}
},
"type": "text",
"analyzer": "iq_text_base",
"index_options": "freqs"
}
},
"dynamic_templates": [
{
"permissions": {
"mapping": {
"type": "keyword"
},
"match": "_*_permissions"
}
},
{
"thumbnails": {
"mapping": {
"type": "binary"
},
"match": "_thumbnail_*"
}
},
{
"data": {
"match_mapping_type": "*",
"mapping": {
"fields": {
"enum": {
"ignore_above": 2048,
"type": "keyword"
},
"float": {
"ignore_malformed": true,
"type": "double"
},
"delimiter": {
"type": "text",
"index_options": "freqs",
"analyzer": "iq_text_delimiter"
},
"joined": {
"search_analyzer": "q_text_bigram",
"type": "text",
"index_options": "freqs",
"analyzer": "i_text_bigram"
},
"prefix": {
"search_analyzer": "q_prefix",
"type": "text",
"index_options": "docs",
"analyzer": "i_prefix"
},
"location": {
"ignore_malformed": true,
"type": "geo_point",
"ignore_z_value": false
},
"date": {
"ignore_malformed": true,
"type": "date",
"format": "strict_date_time||strict_date"
},
"stem": {
"type": "text",
"analyzer": "iq_text_stem"
}
},
"type": "text",
"index_options": "freqs",
"analyzer": "iq_text_base"
}
}
}
]
}
}
}
Is it possible to still use the Nest client against an engine created via AppSearch?
My query had a couple of issues. Firstly I should have been using field name price.float which is the numeric representation of the price field on ES vs AppSearch. You could figure this out from the Explain endpoint offered by AppSearch.
The next issue was the structure of my query, I shouldn't have been using a FilteredAggregation. My intent was to not apply the filter specifically onto the aggregation, but to the query result.
Lastly, retrieving the results from the Aggregations was not that straight forward. Dumping the contents to console falsely shows an empty aggregation, however upon investigating the debugging info via the .EnableDebugMode() header, I was able to see that I was indeed receiving results. Applying a breakpoint and inspecting the results of the object allowed me to retrieve the object I wanted.
var orderChangedArgFilter = client.Search<Product>(s => s
.Query(q => +q.Range(rf => rf.Field("price.float").GreaterThanOrEquals(0.01).LessThan(50.0)) && +q.Terms(p => p.Field("id").Terms(productIds)))
.Aggregations(a => a
.Range("Price aggs", r => r
.Field("price.float")
.Ranges(rs =>
rs.From(0.01).To(50.0).Key("0 to 50 price agg"),
rs => rs.From(50.01).To(100).Key("50 to 100 price agg"),
rs => rs.From(100.01).Key("From 100 price agg")))
)
);
orderChangedArgFilter.Aggregations.Dump();
// vs
var agg = (Nest.BucketAggregate)orderChangedArgFilter.Aggregations.GetValueOrDefault("Price aggs");
var buckets = agg.Items.Select(b => (RangeBucket)b).ToList();
Console.WriteLine(buckets[0].Key + ", " + buckets[0].DocCount);
Note the line of text at the bottom of the below screen shot showing the Key and DocCount

Getting a Jquery DataTable Error (Unknown Parameter)

I'm getting the following error. I know there are similar answered questions but I have tried to use those answers but I am still unable to see my error.
Error Message:
I have the correct amount of columns in the table and in the request. I have checked for typo's. I am using a video as a guide and I have done everything exactly the same, yet mine doesn't work
code:
<table id="myTable">
<thead>
<tr>
<th>Title</th>
<th>FirstName</th>
<th>Surname</th>
<th>Address1</th>
<th>Address2</th>
<th>Town</th>
<th>Account1</th>
<th>Account2</th>
</tr>
</thead>
</table>
#section mydataTable{
<script type="text/javascript" charset="utf8"
src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.js"></script>
<script>
$(document).ready(function () {
$('#myTable').DataTable(
{
"processing": true,
"filter": false,
"serverSide": true,
"paging": false,
"responsive": true,
"ajax":
{
"url": "#Url.Action("LoadData")",
"datatype": "json",
"type": "POST",
},
"columnDefs": [
{ "defaultContent": "-", "targets": "_all" },
{ "width": "auto", "targets": 0, "orderable": false },
{ "width": "auto", "targets": 1, "orderable": false },
{ "width": "auto", "targets": 2, "orderable": false },
{ "width": "auto", "targets": 3, "orderable": false },
{ "width": "auto", "targets": 4, "orderable": false },
{ "width": "auto", "targets": 5, "orderable": false },
{ "width": "auto", "targets": 6, "orderable": false },
{ "width": "auto", "targets": 7, "orderable": false },
],
"columns": [
{ "data": "Title", "name": "CTitle" },
{ "data": "FirstName", "name": "CFirstName" },
{ "data": "Surname", "name": "CSurname" },
{ "data": "Address1", "name": "CAddress1" },
{ "data": "Address2", "name": "CAddress2" },
{ "data": "Town", "name": "CTown" },
{ "data": "Account1", "name": "CAccount1" },
{ "data": "Account2", "name": "CAccount2" },
],
});
});
</script>
}
C#:
public JsonResult LoadData()
{
IEnumerable<DeathClaims> deathclaims = GetDc();
return Json(new { data = deathclaims, recordsFiltered = deathclaims.Count(), recordsTotal = deathclaims.Count() });
}
private IEnumerable<DeathClaims> GetDc()
{
List<DeathClaims> deathlist = new List<DeathClaims>()
{
new DeathClaims {
Title = "Mr",
FirstName = "Michael",
Surname = "Smith",
Address1 = "132 Spalding Road",
Address2 = "TS252JP",
Town = "Hartlepool",
Account1 = "Current Account 1.0%",
Account2 = "Super Saver 3.0%"},
new DeathClaims {
Title = "Mr",
FirstName = "Steve",
Surname = "Smith",
Address1 = "1 Something Close",
Address2 = "TS273QQ",
Town = "Hartlepool",
Account1 = "Current Account 1.0%",
Account2 = "Super Saver 2.0%"}
};
return deathlist;
}
None of the data is getting through - I'm sure it's a small issue but I just cant see it
Thank you in advance for your help
Thanks
For DataTables plugin to work at server-side. You need to return the JSON in LoadData() method as follow i.e.
...
// Initialization.
string search = Request.Form.GetValues("search[value]")[0];
string draw = Request.Form.GetValues("draw")[0];
string order = Request.Form.GetValues("order[0][column]")[0];
string orderDir = Request.Form.GetValues("order[0][dir]")[0];
int startRec = Convert.ToInt32(Request.Form.GetValues("start")[0]);
int pageSize = Convert.ToInt32(Request.Form.GetValues("length")[0]);
...
// Process your code.
...
JsonResult result = this.Json(new { draw = Convert.ToInt32(draw), recordsTotal = totalRecords, recordsFiltered = recFilter, data = data }, JsonRequestBehavior.AllowGet);
return result;
...
The above properties of DataTables plugin are needed to be captured and maintained in your code by yourself.

Mailchimp not rendering variables

I am using the Mailchimp template to send emails through Mandrill. Email being sent successfully. But the variables are not rendering. I tried lots of settings but unfortunately, it is not working. My code is looking like the following.
<p>Dear {{customerName}},</p>
<p>Thank you for using XXXXX to process your return.</p>
<p>All you have to do is bring your parcel along with this e-mail to {{pudoLocation}} at {{emailPudoAddress}}.</p>
And In the Email output, it is showing like this.
And My request JSON to API https://mandrillapp.com/api/1.0/messages/send-template.json is:-
valid json is `{
"key": "xxxxxxxxxxxxxxx",
"template_name": "TestTemplate",
"template_content": [],
"message": {
"subject": "TestEmail",
"from_email": "xxx.xx#xxxxx.in",
"from_name": "Drop2Shop",
"to": [{
"Email": "xxxxx.xxx#xxxxxx.in",
"Name": "Amrit Pannu",
"Type": "to"
}],
"headers": {
"Reply-To": "xxxxx.xxx#xxxx.in"
},
"important": false,
"track_clicks": true,
"track_opens": true,
"merge_language": "handlebars",
"global_merge_vars": [{
"name": "pudoLocation",
"content": "TRK00000028"
},
{
"name": "customerName",
"content": "TRK00000028"
}],
"tags": [""]
}
}`
Please can someone help me here what I missing in this?
Thanks and Advance
You can pass global variables in mandrill using *|VAR1|*. To pass array you can use {{handlebars}}.
The content will be like this:
<p>Dear *|customerName|*,</p>
<p>Thank you for using XXXXX to process your return.</p>
<p>All you have to do is bring your parcel along with this e-mail to *|pudoLocation|* at *|emailPudoAddress|*.</p>
The JSON should be like this only:
{
"key": "XXXXXXXXXXXXXXX",
"template_name": "XXXXXXXXXXXXXXXXXX",
"template_content": [],
"message": {
"subject": "TestEmail",
"from_email": "xxxx#xxxxxxxxxxx.in",
"from_name": "xxxxxx",
"to": [
{
"email": "xxxx#xxxxxxxxxxx.in",
"name": "xxxxx xxxxx",
"type": "to"
}
],
"headers": {
"reply_to": "xxxx.xxxx#xxxx.in"
},
"important": false,
"track_opens": true,
"track_clicks": true,
"merge_language": "handlebars",
"global_merge_vars": [
{
"name": "trackingNumber",
"content": "TRK00000028"
},
{
"name": "customerName",
"content": "Amrit Pannu"
},
{
"name": "eCommerceRetailer",
"content": "Jojo Retailer"
},
{
"name": "goodsDescription",
"content": "Tricycles, Scooters, and Similar Wheeled Toys; Dolls' Carriages"
},
{
"name": "shippingDate",
"content": "2021-07-07"
},
{
"name": "numberOfPackages",
"content": "45"
},
{
"name": "shipFromAddress",
"content": "IRELAND"
},
{
"name": "shipToAddress",
"content": "Britain"
},
{
"Name": "pudoAddress",
"Content": "USA"
},
{
"name": "shipFromContact",
"content": "Commin"
},
{
"name": "shipToContact",
"content": "Stark"
},
{
"name": "customerReference",
"content": "DF7889FSDHCB"
},
{
"name": "pudoLocation",
"content": "Denmark"
},
{
"name": "emailPudoAddress",
"content": "amrit#mailinator.com"
},
{
"name": "unsubscribePageUrl",
"content": ""
},
{
"name": "email",
"content": "amrit#mailinator.com"
},
{
"name": "scanEventTime",
"content": "12:07"
},
{
"name": "scanEventDate",
"content": "07 July 2021"
},
{
"name": "packageItems",
"content": [
{
"GoodsDescription": "869c6f67-f33d-4b30-a274-79b635d12461",
"ReturnReason": "c3b4b071-7664-4060-a39f-52c24147a1ce",
"Quantity": 3,
"Value": 6
},
{
"GoodsDescription": "5e2c625b-74e6-4e90-bb52-6595e9f3d088",
"ReturnReason": "f0949b28-f9a7-406e-8676-b8ce6c714509",
"Quantity": 3,
"Value": 14
},
{
"GoodsDescription": "cffe036a-2441-41af-82e1-130f9169924b",
"ReturnReason": "f31956b9-c24e-492e-b11f-4b4e19489b13",
"Quantity": 1,
"Value": 5
},
{
"GoodsDescription": "f8f64467-6926-4f08-9d4e-aa924dc1af35",
"ReturnReason": "d1f759b0-8e54-4119-94ee-6afe1bc49766",
"Quantity": 4,
"Value": 0
},
{
"GoodsDescription": "496f4e0e-739d-4fce-8a37-85113f27c4d4",
"ReturnReason": "b8d98439-928f-4e6c-bb56-01e6f8fb6be6",
"Quantity": 2,
"Value": 5
},
{
"GoodsDescription": "afe2986c-e51e-4cfe-9506-f9ef2afa5657",
"ReturnReason": "4e6e34f6-d921-46fb-8f4a-b04afd0856a7",
"Quantity": 4,
"Value": 12
},
{
"GoodsDescription": "13ac561a-d161-46a5-9795-8481e99a3afd",
"ReturnReason": "73f4441b-dcff-4f68-a58e-320a29a167c8",
"Quantity": 1,
"Value": 7
},
{
"GoodsDescription": "135e083b-0408-4445-9a0c-3656a46f7eab",
"ReturnReason": "325c7144-8f7d-4712-b708-1702416ca02c",
"Quantity": 2,
"Value": 13
},
{
"GoodsDescription": "ee510bfd-58ea-4707-9c52-26913b190b27",
"ReturnReason": "854629a5-289b-46c9-a072-099e2a572307",
"Quantity": 4,
"Value": 12
},
{
"GoodsDescription": "b6d6fa6e-a327-4014-b019-0c4cd0098da6",
"ReturnReason": "02394799-761c-46f0-af79-d8bc92b2c1b5",
"Quantity": 1,
"Value": 13
}
]
},
{
"name": "currentYear",
"content": 2021
}
],
"tags": null,
"inline_css": true
}
For more information, please see this: https://mailchimp.com/developer/transactional/docs/templates-dynamic-content/#dynamic-content
I'm probably too late, but if it can help someone else.
It's not working because you have to remove all the backslashes Mailchimp added when send it to Mandrill before your variables. Change : \{{customerName}} to {{customerName}}

How to add properties at runtime to JSON (C#)

Note: Im working with System.Text.Json package
Below is JSON I am getting from a database. I have to go through each of the keys in the JSON and check if there is a period (.) in the key name; if so, I need to add a property required with the value of true in the JSON in order to provide runtime validation:
validate:{"required", true}
Here is my JSON:
{
"display": "wizard",
"settings": {},
"components": [{
"title": "Event Information",
"label": "Event Information",
"type": "panel",
"key": "EventInformation",
"components": [{
"label": "Row1Columns",
"columns": [{
"components": [{
"label": "Event Date",
"format": "dd/MM/yyyy hh:mm a",
"tableView": false,
"datePicker": {
"disableWeekends": false,
"disableWeekdays": false
},
"validate": {
"unique": true
},
"key": "Event.EventDate",
"type": "datetime",
"input": true,
"suffix": "<i ref=\"icon\" class=\"fa fa-calendar\" style=\"\"></i>",
"widget": {
"type": "calendar",
"displayInTimezone": "viewer",
"language": "en",
"useLocaleSettings": false,
"allowInput": true,
"mode": "single",
"enableTime": true,
"noCalendar": false,
"format": "dd/MM/yyyy hh:mm a",
"hourIncrement": 1,
"minuteIncrement": 1,
"time_24hr": false,
"minDate": null,
"disableWeekends": false,
"disableWeekdays": false,
"maxDate": null
}
}],
"width": 6,
"offset": 0,
"push": 0,
"pull": 0
}, {
"components": [{
"label": "Duration (minutes)",
"mask": false,
"spellcheck": true,
"tableView": false,
"delimiter": false,
"requireDecimal": false,
"inputFormat": "plain",
"key": "Event.Duration",
"type": "number",
"input": true
}],
"width": 6,
"offset": 0,
"push": 0,
"pull": 0
}],
"tableView": false,
"key": "row1Columns",
"type": "columns",
"input": false
}, {
"label": "Row2Columns",
"columns": [{
"components": [{
"label": "Event Category",
"widget": "choicesjs",
"tableView": true,
"dataSrc": "custom",
"data": {
"custom": "values = getEventCategoryValues()"
},
"valueProperty": "AgencyEventCategoryId",
"template": "<span>{{ item.text }}</span>",
"selectThreshold": 0.3,
"validate": {
"required": true
},
"key": "Event.AgencyEventCategoryId",
"type": "select",
"indexeddb": {
"filter": {}
},
"input": true
}],
"width": 6,
"offset": 0,
"push": 0,
"pull": 0
}, {
"components": [{
"label": "Attendance",
"widget": "choicesjs",
"tableView": true,
"multiple": false,
"dataSrc": "custom",
"data": {
"custom": "values = getAttendanceValues()"
},
"valueProperty": "AgencyEventAttendanceId",
"template": "<span>{{ item.text }}</span>",
"selectThreshold": 0.3,
"validate": {
"required": true,
},
"key": "Event.AgencyEventAttendanceId",
"type": "select",
"indexeddb": {
"filter": {}
},
"input": true
}],
"width": 6,
"offset": 0,
"push": 0,
"pull": 0
}],
"tableView": false,
"key": "row2Columns",
"type": "columns",
"input": false
}, {
"label": "Event Options",
"widget": "choicesjs",
"tableView": true,
"multiple": true,
"dataSrc": "custom",
"data": {
"custom": "values = getEventManagerValues(data.Event.AgencyEventCategoryId)"
},
"template": "<span>{{ item.text }}</span>",
"refreshOn": "Event.AgencyEventCategoryId",
"clearOnRefresh": true,
"selectThreshold": 0.3,
"calculateServer": false,
"validate": {
"required": true,
"multiple": true
},
"key": "Event.EventDetail",
"type": "select",
"indexeddb": {
"filter": {}
},
"input": true
}, {
"label": "Casenote",
"wysiwyg": true,
"autoExpand": true,
"spellcheck": true,
"tableView": true,
"calculateServer": false,
"key": "Event.EventCasenote[0].Casenote",
"type": "textarea",
"input": true
}],
"input": false,
"tableView": false,
"breadcrumbClickable": true,
"buttonSettings": {
"previous": true,
"cancel": true,
"next": true
},
"collapsible": false
}]
}
One of the options would be to parse json into JObject and add property to it via Newtonsoft's Json.NET:
var obj = JObject.Parse("{'key':'value'}");
obj.Add("required", true);
Console.WriteLine(obj); // { "key": "value", "required": true }
To add new object you can use this overload of Add:
obj.Add("validate", JObject.FromObject(new { required = true }));
So the whole solution will look something like this:
var obj = JObect.Parse(your_json);
foreach(var token in obj.DescendantsAndSelf().ToList()) // ToList is important!!!
{
if(token is JObject xObj)
{
// check your conditions for adding property
// check if object does not have "validate" property
if(satisfies_all_conditions)
{
xObj.Add("validate", JObject.FromObject(new { required = true }));
}
}
}
I was having similar issue, and have found a solution, see below the code and comments. I am using Newtonsoft though but it is worth checking if you can use Newtonsoft library and have not found a solution for System.Text.Json.
All controls in your JSON are part of component object/array so we can use JSONPath, see the link for more details.
public void IterateJson(JObject obj, string mandatoryFieldKey)
{
JToken jTokenFoundForMandatoryField = obj.SelectToken
("$..components[?(#.key == '" + mandatoryFieldKey + "')]");
//Now we convert this oken into an object so that we can add properties/objects in it
if (jTokenFoundForMandatoryField is JObject jObjectForMandatoryField)
{
//We check if validate already exists for this field, if it does not
//exists then we add validate and required property inside the if condition
if (jObjectForMandatoryField["validate"] == null)
jObjectForMandatoryField.Add("validate",
JObject.FromObject(new { required = true })); //add validate and required property
else
{
//If validate does not exists then code comes here and
//we convert the validate into a JObject using is JObject statement
if (jObjectForMandatoryField["validate"] is JObject validateObject)
{
//We need to check if required property already exists,
//if it does not exists then we add it inside the if condition.
if (validateObject["required"] == null)
{
validateObject.Add("required", true); //add required property
}
}
}
}
}
It was interesting task for me, so this is what i have written
class Program
{
static void Main(string[] args)
{
string jsonFilePath = #"test.json"; //path to your json
string json = File.ReadAllText(jsonFilePath);
var data = JObject.Parse(json);
CheckJson(data);
Console.ReadLine();
}
static void CheckJson(JToken value)
{
if (value.Values().Count() != 0) //if more than 0 - so value is object or array and we have to call this method for each property
{
foreach (var item in value.Values().ToList())
{
CheckJson(item);
}
}
else if (true) //else - we have exactly value of key, which we can check, for example if . exists or additional checks
{
if (value.Parent.Parent is JObject jObject && jObject["validate"] == null) //check if above "required" property exists
{
jObject.Add("validate", JObject.FromObject(new { required = true })); //add required property
}
}
}
}
This code will add in each object property "required" if it is not exists.
All you need - just add Validation method and call it in if block.
And better to add additional validation that won't continue checking all properties if "required" property exists

troubles in extracting data from facebook graph c#

i'm working on a program that exports all user public data but the graph is making troubles,i made an app and got all the permissions (the extended profile properties permissions, and extended permissions) to generate the access token which i use to extract data, what confuses me is that some profiles extract the hole data some other don't even if it appears in the section.
example:
attempting to export me/ exported all the data i have sports education hometown etc..
attempting to export friend/ exported public data + sports and no education even tho he got education in the about section and it appears to public or friends
attempting to extract me/subscribers showed 12 subscribers which is right
attempting to extract friend/subscribers showed 12 of 20 even tho the subscribers appears as 20 in the subscribers section
i'm using the following command:
var res = JsonConvert.DeserializeObject<FacebookLikes>(fb.Get(txtUserName.Text + "/likes").ToString());
i hope you understand the idea, thanks for the help
okay here the problem with a live test:
i tried the following on the tool you stated:
blazzzin/?access_token
the result was:
{
"id": "100001748944712",
"name": "Ethan 'blaze' Parker",
"first_name": "Ethan",
"middle_name": "'blaze'",
"last_name": "Parker",
"link": "https://www.facebook.com/blazzzin",
"birthday": "02/20",
"hometown": {
"id": "102161913158207",
"name": "Delhi, India"
},
"quotes": "You're what you eat. Really? I am an Apple then.",
"sports": [
{
"id": "102173226491776",
"name": "Soccer"
},
{
"id": "112285278784684",
"name": "Badminton"
}
],
"favorite_teams": [
{
"id": "138570342846531",
"name": "WWE Nexus"
},
{
"id": "136759993012177",
"name": "Delhi Daredevils"
},
{
"id": "42884080673",
"name": "Uruguay"
},
{
"id": "365383271987",
"name": "Chelsea FC"
},
{
"id": "151170071595882",
"name": "Best of wwe"
},
{
"id": "166496596733768",
"name": "WWE World"
},
{
"id": "19221964237",
"name": "ECW"
},
{
"id": "31695961025",
"name": "Impact Wrestling"
},
{
"id": "5985827589",
"name": "Fnatic"
},
{
"id": "61630257716",
"name": "University of Cincinnati Bearcats"
},
{
"id": "44027083759",
"name": "Cincinnati Reds"
},
{
"id": "323348924370835",
"name": "Wrestling Memes"
},
{
"id": "127573517418762",
"name": "Veer Marathi"
},
{
"id": "208056762558521",
"name": "Team Razer"
},
{
"id": "228215007216138",
"name": "The awkward moment when you go to grab someone sexy and headbutt the mirror"
},
{
"id": "200933243299323",
"name": "If she's never seen Arsenal win a trophy, she's too young for you Bro"
},
{
"id": "189411184456673",
"name": "Sanfransisco Giants"
},
{
"id": "210487655659656",
"name": "Team Bring It vs Team Cenation"
},
{
"id": "146995142049876",
"name": "Like IF the First THNG You Do WheN You WAKE UP is ROll OVR &CHeCK UR Phone"
},
{
"id": "111507918902981",
"name": "• WWE Universe | Tunisian Page •"
}
],
"favorite_athletes": [
{
"id": "104023396299513",
"name": "Andrew Flintoff"
},
{
"id": "545498258812287",
"name": "Luke Wright"
},
{
"id": "111832475503333",
"name": "Michael Schumaker"
},
{
"id": "110393655686342",
"name": "Eddie Alvarez MMA"
},
{
"id": "112941715451427",
"name": "Maryse"
},
{
"id": "344128252278047",
"name": "Sachin Tendulkar"
},
{
"id": "179559748752616",
"name": "Maryse"
},
{
"id": "52911737290",
"name": "Doraemon"
},
{
"id": "14320933255",
"name": "Andrew Flintoff"
},
{
"id": "81221197163",
"name": "Cristiano Ronaldo"
},
{
"id": "136644946409767",
"name": "Mahmoud's charity run from Melbourne to Sydney"
},
{
"id": "42888741032",
"name": "R-Truth - WWE Universe"
},
{
"id": "203402113048458",
"name": "Abby Marie Johnson WBFF Bikini 2014 Competitor"
},
{
"id": "270759951686",
"name": "JASON DAVID FRANK - Official Fan Page"
},
{
"id": "110336188978264",
"name": "AJStyles.Org"
},
{
"id": "8707340185",
"name": "Edge - WWE Universe"
},
{
"id": "298344150293189",
"name": "Fandango - WWE"
},
{
"id": "195569370462754",
"name": "William Regal: A Tribute To An Underrated Legend"
},
{
"id": "173741199368967",
"name": "Steve Moriarty"
},
{
"id": "12714756642",
"name": "Fedor Emelianenko"
},
{
"id": "212481352152206",
"name": "Arkan Taha Fitness"
},
{
"id": "160505357316902",
"name": "Lexi Thompson"
},
{
"id": "10035000964",
"name": "The Great Khali - WWE Universe"
},
{
"id": "176063032413299",
"name": "Leo Messi"
},
{
"id": "65920772679",
"name": "Maria Sharapova"
},
{
"id": "226790007363705",
"name": "Divas - WWE UNiVERSE"
},
{
"id": "175535596516",
"name": "Sabine Lisicki"
},
{
"id": "415063578542561",
"name": "Eddie Guerrero"
},
{
"id": "157829220895967",
"name": "Kaitlyn - WWE Universe"
},
{
"id": "122046337858201",
"name": "WWE Maryse Ouellet"
},
{
"id": "185950250927",
"name": "Brock Lesnar"
},
{
"id": "8164128018",
"name": "Layla - WWE Universe"
},
{
"id": "110108465743414",
"name": "PUSH EVAN BOURNE"
},
{
"id": "115647961808394",
"name": "We love Evan Bourne"
},
{
"id": "105683519512165",
"name": "Sin Cara - WWE"
},
{
"id": "125557244171559",
"name": "Rikishi"
},
{
"id": "8457822873",
"name": "CM Punk - WWE Universe"
}
],
"inspirational_people": [
{
"id": "17774451468",
"name": "Mr. Bean"
},
{
"id": "9972312428",
"name": "The Miz - WWE Universe"
},
{
"id": "103107176396108",
"name": "CM Punk"
},
{
"id": "10392229299",
"name": "Gurbaksh Chahal"
}
],
"education": [
{
"school": {
"id": "424030284317485",
"name": "HarvardX"
},
"year": {
"id": "120960561375312",
"name": "2013"
},
"concentration": [
{
"id": "108146682539885",
"name": "Justice"
}
],
"type": "College"
},
{
"school": {
"id": "102052863223529",
"name": "TGC Animation and Multimedia"
},
"year": {
"id": "120960561375312",
"name": "2013"
},
"concentration": [
{
"id": "199849176695930",
"name": "Web Design & Development"
},
{
"id": "109803049037749",
"name": "Graphic Design"
}
],
"type": "College"
}
],
"gender": "male",
"relationship_status": "In a relationship",
"significant_other": {
"name": "Hailey Hayden",
"id": "100006853479540"
},
"website": "http://www.varunpuri.me
",
"locale": "en_US",
"languages": [
{
"id": "106059522759137",
"name": "English"
},
{
"id": "113301478683221",
"name": "American English"
},
{
"id": "112969428713061",
"name": "Hindi"
},
{
"id": "110343528993409",
"name": "Spanish"
},
{
"id": "105606752807048",
"name": "Punjabi"
},
{
"id": "107672419256005",
"name": "Dutch"
}
],
"updated_time": "2014-01-05T16:49:55+0000",
"username": "blazzzin"
}
i tried it on another friend and the friend have all the data public example work and education (i can see them in the about section)
khalil.bsaibes/?access_token
the result was:
{
"id": "806750229",
"name": "Khalil G. Bsaibes",
"first_name": "Khalil",
"middle_name": "G.",
"last_name": "Bsaibes",
"link": "https://www.facebook.com/khalil.bsaibes",
"location": {
"id": "106188806084417",
"name": "Beirut, Lebanon"
},
"gender": "male",
"locale": "en_US",
"updated_time": "2014-01-12T09:39:29+0000",
"username": "khalil.bsaibes"
}
so can you explain me what's happening and how to solve it?
What if the user whose information you are trying to access hasn't made some of his information public?
You can use the below tool to debug by putting the access token and your query and seeing what is the returned json. If it returns only 12 subscribers, then you should check the permission, if it returns 20 then recheck your code and parsing method..
https://developers.facebook.com/tools/explorer/

Categories

Resources