Send array as part of x-www-form-urlencoded - arrays

I want to send array using postman.
the request looks like this:
Im using postman to execute requests.
I found on the internet to send array via form-data or raw.
But I need them to be send as x-www-form-urlencoded.
I tried it this way:
But its wrong because value ads is string not array.

I had a bit of a more complex objects.
A class emaillist
public class emailist
{
public String id { get; set; }
public String emailaddress { get; set; }
public String name { get; set; }
}
A class emailRecipientList
public class emailRecipientList
{
public String procedure { get; set; }
public String server { get; set; }
public String filename { get; set; }
public String fileid { get; set; }
public List<emailist> emaillists { get; set; }
}
And a Task
public async Task<System.Xml.XmlElement> postUploadEmailRecipientList([FromBody] emailRecipientList recipientList)
Now to send the data as "application/x-www-form-urlencoded"
If more elements need to get added just keep increasing the array index.
I tested it on a asp.net WebAPI 2 project and worked fine.

If you want to pass 1,2,3 in array ads , try with below screenshot

Just figured out how it's done, same as in html forms
cheers

I wasnt able to solve it via x-www-form-urlencoded even I found solutions like
ads[].id, ads[0].id, ads.id,... It wasnt working.
So I had to write it as raw. and in headers section change it this way.
And the body is:
{ "deleted": "false",
"ads":
[
{
"id": 15
},
{
"id": 20
}
]
}

check this image
i think you can just repeat the same key and give it different value id for example

Just Use the key without square brackets

For adding array as value, click Bulk Edit in body tab of postman.
It will allow you to input of key value pairs in blank area.
Enter the data of key value pair as below:
Id:1
FirstName:John
LastName:Smith
For adding bytes of Image in ImageData key array generate the byte array of image and enter or copy/paste as below:
Id:1
FirstName:John
LastName:Smith
ImageData:255
ImageData:216
ImageData:255
...
...
This will send the data in array for key ImageData.

Try the below screenshot:
My postman version is 7.13.0.

Related

Filtering AutoQuery Results to Only Display Table Rows that Match Data in the Users Session

I'm working on a project that want's to control data access in a multi-tenant system. I've got a table set up which has a row on it that says what tenant the object applies to. Let's call this property
ClientObject.ClientOrgId
I want to set something up so that anytime this table is accessed the only results that are returned are results that match some piece of data in the users session. I.e.
ClientObject.ClientOrgId == UserSession.ClientOrgId
and I ideally want to do this restriction on the table model instead of re-implementing it for every query created.
I've found the Autofilter attribute in the service stack documentation, and it looks like the thing that I want to use, but I've been unable to get it working. An example of my code is below, and I'm not seeing any filtering whenever I set the user sessions ClientOrgID to anything different.
[Authenticate]
[Route("/clientObject", HttpMethods.Post)]
[Api("Creates a Client Object")]
public class CreateClientObject : ICreateDb<ClientObjectTableModel>, IReturn<ClientObjectMutationResponse>
{
[ValidateNotEmpty]
public string ClientName{ get; set; }
[ValidateNotEmpty]
public string ClientLocation { get; set; }
[ValidateNotEmpty]
[ValidateNotNull]
public Guid? ClientOrgId { get; set; }
}
[AutoFilter(QueryTerm.Ensure, nameof(ClientObjectTableModel.ClientOrgId), Eval= "userSession.ClientOrgId")]
public class ClientObjectTableModel : AuditBase
{
[AutoId]
public Guid Id { get; set; }
[Required]
public string ClientName { get; set; }
[Required]
public string ClientLocation { get; set; }
[Required]
public Guid ClientOrgId { get; set; }
}
I even went off the rails and tried something like
[AutoFilter(QueryTerm.Ensure, nameof(ClientObjectTableModel.ClientLocation), Value = "The Fourth Moon Of Mars")]
with the expectation that nothing would get returned, and yet I'm still seeing results.
All AutoQuery CRUD Attribute like [AutoFilter] should be applied to the AutoQuery Request DTO, not the data model.
Have a look at how to populate Tenant Ids with AutoPopulate and how it's later used to filter results with [AutoFilter].

How to pass multiple post parameters to web api using angular typescript

I would like to pass multiple values to the following web api using angularjs typescript.
// POST api/values
public void Post([FromBody]string value1, [FromBody]string value2)
{
}
I would like to call the above method something like this
$http.post('api/values', ???)
As I need to do some validations on the page by passing multiple parameters to the database.
I also tried with GET instead of post but didn't work for me.
Please share your thoughts.
Thank you.
Hari C
You can't read multiple values "FromBody". Instead you should define "Request" class with all needed parameters:
public class Request
{
public string Value1 { get; set; }
public string Value2 { get; set; }
}
//POST api/values
public void Post([FromBody]Request request)
{
}
And then like Aran said you can go this way
$http.post('api/values', {Value1:"foo", Value2:"bar"});
Use the data property (the second argument of $http.post) to pass your parameters:
$http.post('api/values', {x:"foo", y:"bar"});

Coming from a relational database background, how should I model relationships in db4o (or any object database)?

I'm experimenting with db4o as a data store, so to get to grips with it I thought I'd build myself a simple issue tracking web application (in ASP.NET MVC). I've found db4o to be excellent in terms of rapid development, especially for small apps like this, and it also negates the need for an ORM.
However, having come from a SQL Server/MySQL background I'm a little unsure of how I should be structuring my objects when it comes to relationships (or perhaps I just don't properly understand the way object databases work).
Here's my simple example: I have just two model classes, Issue and Person.
public class Issue
{
public string ID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime? SubmittedOn { get; set; }
public DateTime? ResolvedOn { get; set; }
public Person AssignedBy { get; set; }
public Person AssignedTo { get; set; }
}
public class Person
{
public string ID { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
The ID properties are just GUID strings generated by the .NET Guid.NewGuid() helper.
So here's how I initially thought the application would work; please ignore any security concerns etc and assume we already have a few Person objects stored in the database:
User logs in. Query the database for the Person which matches the username and password, and store his/her GUID id as a session variable. Redirect to app home screen.
Logged in user creates a new issue ticket, selecting the user to assign it to from a drop-down list. They fill in the other details (Title, Description etc), and then submit the form.
Query the Person objects in the database (by their GUID ID's) to get an object representing the logged in user and one representing the user the ticket has been assigned to. Create a new Person object (populated with the posted form data), assign the Person objects to the Issue object's AssignedBy and AssignedTo properties, and store it.
This would mean I have two Person objects stored against each Issue record. But what happens if I update the original Person—do all the stored references to that Person in the various issue objects update, or do I have to handle that manually? Are they references, or copies?
Would it be better/more efficient to just store a GUID string for the AssignedBy and AssignedTo fields (as below) and then look up the original person based on that each time?
public class Issue
{
public string ID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime? SubmittedOn { get; set; }
public DateTime? ResolvedOn { get; set; }
public string AssignedByID { get; set; }
public string AssignedToID { get; set; }
}
I think I'm just stuck in a certain way of thinking which is confusing me. If someone could explain it clearly that would be most helpful!
Object-Databases try to provide the same semantics as objects in memory. The rule of thumb is: It works like objects in memory. Object databases store references between the objects in the database. When you update the object, that object is updates. And if you have a reference to that objects, you see the changed version.
In your case, the Issue-objects refer to the person object. When you update that person, all Issues which refer to it 'see' that update.
Of course, primitive types like int, strings, longs etc are handled like value objects and not a reference objects. Also arrays are handled like value objects in db4o, this means a array is stored together with the object and not as a reference. Everything else is stored as a reference, even collections like List or Dictionaries.
Please take a look at:
http://developer.db4o.com/Documentation/Reference/db4o-7.4/java/reference/html/reference/basic_concepts/database_models/object-relational_how_to.html
Best!

Creating a Dynamic Linq filter over List<T>

Ok, I asked this question before, but deleted it as the way I went about describing my problem was wrong.
Firstly, let me state that Im creating a .NET3.5 Winforms app using C# and Plinqo (Professional Linq to Objects) as my ORM. Here's my situation: I have a DataGridview that is populated from a SortableBindingList<T> - in my case, formed from a List<Task> which is simply represented as follows:
public class Task {
public long TaskID { get; set; }
public string TaskDescription { get; set; }
public enumPriority TaskPriority { get; set; }
public DateTime DueDate { get; set; }
public double PercentageComplete { get; set; }
}
Now, I want to provide a Dialog to my user to allow him/her to Filter this list. I envision passing in a list of property names and associated DataType into the Dialog that I can use to populate a ComboBox. So the user will choose which property they want to query from the comboBox and based on the selection the appropriate comparers and UI control will be made available for the user to enter in thier criteria. Lastly, it will contain an AND/OR togglebutton at the end which the user can use to add additional criterion. Each criterion will be an object of type FilterItem as shown below:
public class FilterItem {
public string MappedPropertyName { get; set; }
public enumComparer Comparer { get; set; }
public object FilterValue { get; set; }
public enumOpertor Operator { get; set; }
}
After the user constructs his/her query, I intend to pass this as a List<FilterItem> back to my calling form, which can then iterate thru the list and allow me to filter the original List<Task>.
This is all fine, and something that I can put together with ease. But I want to make sure that the ACTUAL filter mechanism I go with is as strongly-typed as possible, and not using bulit up strings like in the Dynamic Query Library. (I used to do something similar previously with ADO.NET, DataViews and dynamically constructing a RowFilter string)
I've read up on Joseph Albahari's PredicatBuilder and an article on tomasp.net, but I seem heavily confused with it and expression trees in general.
I sincerely seek your assistance in helping me better understand these concepts, and how to go about using it up so that my intended architecture can work with it.
Much appreciation!
Additionally, I know I can do something like:
private SortableBindingList<Task> GetSortedTaskList()
{
List<Task> list = new List<Task>();
var query = DataUtil.GetUserTasks(xSys.Current.UserID);
if (/*description condition met*/)
{
query = query.Where(x => x.TaskDescription.Contains(FilterDesc));
}
if (/*due date condition met*/)
{
query = query.Where(x => x.DueDate >= FilterDate);
}
if (/*priority condition met*/)
{
query = query.Where(x => x.TaskPriority == FilterPriority);
}
...
list = query.ToList();
return new SortableBindingList<ArcTask>(list);
}
but this does not seem very scalable and 'dynamic'.

In winforms what is the best (or a good) way to bind a form (view) to a strongly-typed object?

For example if I have a Name object
public class Name
{
public string First { get; set; }
public string Middle { get; set; }
public string Last { get; set; }
}
and I have a form with 3 textboxes on it, named txtFirstName, txtMiddleName, txtLastName
I want some way to automatically bind the domain object to these text boxes.
I'm very used to working with asp.net-mvc but I'm trying to transfer this knowledge to winforms 0_0
You want a "Data Source", specifically an "object data source".
This will get you started, from the "Data" menu, select "Add New Data Source..." You want to select "Object".
Data Source Configuration Wizard at
http://msdn.microsoft.com/en-us/library/w4dd7z6t(VS.80).aspx.
How to: Connect to Data in an Object at http://msdn.microsoft.com/en-us/library/5xf878ky.aspx.
Name n = new Name { First = "test", Last = "last", Middle = "midddle" };
textBox1.DataBindings.Add("Text", n, "First");
I'm not quite sure if this is what you are asking but, you can override the tostring method of your object
public override string ToString()
{
return string.Format("first:{0}, middle:{1} last:{2}", First, Middle, Last);
}
then you can set it as the datasource of a control.

Resources