-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace SODA.Utilities | ||
{ | ||
/// <summary> | ||
/// Helper class for constructing payload for post requests | ||
/// </summary> | ||
class PayloadBuilder | ||
{ | ||
/// <summary> | ||
/// Construct JSON payload to delete a single row using Upsert | ||
/// </summary> | ||
/// <param name="idFieldName">The name of the unique id field for the resource.</param> | ||
/// <param name="rowId">The identifier of the row to be deleted.</param> | ||
/// <returns>A json array string for submitting to the Upsert method</returns> | ||
public static string GetDeletePayload(string IdFieldName,string rowId) | ||
{ | ||
return $"[{{\"{IdFieldName}\": \"{rowId}\",\":deleted\": true }}]"; | ||
} | ||
|
||
/// <summary> | ||
/// Construct JSON payload to delete multiple rows using Upsert | ||
/// </summary> | ||
/// <param name="idFieldName">The name of the unique id field for the resource.</param> | ||
/// <param name="rowIds">List of row identifiers to be deleted.</param> | ||
/// <returns>A json array string for submitting to the Upsert method</returns> | ||
public static string GetDeletePayload(string idFieldName, List<string> rowIds) | ||
{ | ||
string jsonPayload = "["; | ||
foreach (var rowId in rowIds) | ||
{ | ||
jsonPayload = $"{jsonPayload}{{\"{idFieldName}\": \"{rowId}\",\":deleted\": true }},"; | ||
} | ||
|
||
jsonPayload = jsonPayload.TrimEnd(','); | ||
return $"{jsonPayload}]"; | ||
} | ||
} | ||
} |