I have a web-api controller that accepts a single Json object Post (currently using Postman as my user-agent).
Here is my Post method:
private AH_ODS_DB_Entities db = new AH_ODS_DB_Entities();
[ResponseType(typeof(Sales))]
public HttpResponseMessage PostSales(Sales Sales, [FromUri] string auth)
{
try
{
if (ModelState.IsValid)
{
if (auth == "KDI")
{
Int64 rs = db.Sales_.Where(sl => sl.Serial == Sales.Serial).Count();
if (1 == rs)
{
return Request.CreateErrorResponse(HttpStatusCode.Conflict, " Duplicate Found!");
}
else
{
db.Sales_.Add(Sales);
db.SaveChanges();
return Request.CreateErrorResponse(HttpStatusCode.OK, "Added!");
}
}
else
{
return Request.CreateResponse(HttpStatusCode.Unauthorized, "Unauthorized Access!");
}
}
else
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's wrong with the JSON model you sent me.");
}
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
And here is the Json:
{
"ExtSerial": "AH0000002",
"Date": "2015-03-01",
"CustomerRefNbr": "JPM0001",
"Description": "2015 FEBRUARY RENTAL 2015 FEBRUARY RENTAL",
"Customer": "TRDE0065",
"Amount": 17989.51,
"AQ_Branch": "KDI",
"AQ_COA": "4100503000",
"LineSubAccount": "OPMOPN000",
"LineTaxCategory": "JPMTAX",
"LineQuantity": 1,
"LineUnitPrice": 400000,
"AQ_PostStatus": 1,
"AQ_StatusDate": "2015-03-01",
"DTS": "2015-03-01"
}
It works fine and all but I wanted to have my post method to optionally accept multiple array of Json data
Something like this:
[{"Id1":3,"Id2":76,"Id3":19},{"Id1":56,"Id2":87,"Id3":94},{"Id1":976,"Id2":345,"Id3":7554}]
I tried putting my sales model parameter as a list<> but it could not read my Sales entity db.Sales_.Add(Sales); and it could not get the table serial in my Sales entity in Int64 rs = db.Sales_.Where(sl => sl.Serial == Sales.Serial).Count();
I am using EF6 and LINQ btw. I really need your help, I know it is a simple problem but I'm really stuck.