by mike.waugh » Fri Feb 28, 2020 12:32 pm
HI Steve
Thanks a lot for the help.
For now, we just work on the existing Custom Routes plugin for simplicity. We will create a new one after things working.
Questions:
1. Please let us know where are we getting wrong here. So we can solve it and get our solution.
Error Messages:
When we send POST request from our application, returned error is:
[A]JiwaFinancials.Jiwa.JiwaServiceModel.JiwaAuthUserSession cannot be cast to [B]JiwaFinancials.Jiwa.JiwaServiceModel.JiwaAuthUserSession.
Type A originates from 'REST API, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\\ProgramData\\Jiwa Financials\\Jiwa 7\\7.2.1\\SYSTEM\\DESKTOP-QTDMRQ9SQLEXPRESS\\Jiwa_Demo72_Test_DevWip\\Plugins\\Admin\\Runtime\\REST API\\REST API.dll'.
Type B originates from 'REST API Custom Routes Example, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\\ProgramData\\Jiwa Financials\\Jiwa 7\\7.2.1\\SYSTEM\\DESKTOP-QTDMRQ9SQLEXPRESS\\Jiwa_Demo72_Test_DevWip\\Plugins\\Admin\\Runtime\\REST API Custom Routes Example\\REST API Custom Routes Example.dll
What we have done:
We have done following steps and code in custom api.
Step 1: Route as per your suggestion.
public void Configure(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin, ServiceStack.ServiceStackHost AppHost, Funq.Container Container, JiwaApplication.Manager JiwaApplicationManager)
{
AppHost.RegisterService<CustomServices>();
AppHost.Routes.Add(typeof(SalesOrderWithPriceSchemePOSTRequest), "/SalesOrders/PatchWithScheme", "POST", "To create a new sales order together with a specific Price Scheme.", "");
}
Step 2: Inherrited request as per your suggestion. Please check code below.
[Serializable()]
[ApiResponse(200, "Created OK")]
[ApiResponse(401, "Not authenticated")]
[ApiResponse(403, "Not authorised")]
public class SalesOrderWithPriceSchemePOSTRequest : SalesOrderPOSTRequest
{
public string PriceSchemeId { get; set; }
}
Step 3: Making Service For Post to Save Sales Order
public class CustomServices : Service
{
[Authenticate]
public JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrder Post(SalesOrderWithPriceSchemePOSTRequest request)
{
JiwaApplication.Manager manager = this.SessionAs<JiwaAuthUserSession>().Manager;
JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder so = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder>(null);
so.DTO_Deserialise(request);
if (!string.IsNullOrWhiteSpace(request.PriceSchemeId))
{
so.PriceSchemeID=request.PriceSchemeId;
}
if (Helper.Service.IsStateful(this))
manager.ObjectDictionary.Add(so.InvoiceID, so);
else
{
so.Save();
so.Read(so.InvoiceID);
}
// Add the location to the response header
base.Response.AddHeader("Location", String.Format("{0}/{1}", base.Request.AbsoluteUri.Split(new[] { '?' })[0], so.InvoiceID));
return so.DTO_Serialise();
}
}