Hi,
Using JIWA 7.2.1.0
Doing a request that uses a SQL "LIKE" query to get all inventory items that have similar names.
I have tested the query in MS SQL server and it works fine. It compiles fine in JIWA, but I get an error message:
"HTTP Error 400. The request is badly formed"
Any advice?
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using JiwaFinancials.Jiwa;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing;
using ServiceStack;
using ServiceStack.DataAnnotations;
using ServiceStack.Model;
using JiwaFinancials.Jiwa.JiwaServiceModel.Tables;
using ServiceStack.Auth;
using System.Linq;
using ServiceStack.OrmLite; // Db
namespace JiwaFinancials.Jiwa.JiwaServiceModel
{
public class RESTAPIPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaRESTAPIPlugin
{
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(GetInventoryItemsLikeNameRequest), "/Custom/GetInventoryItemsLikeNameRequest/{ItemName}/", "GET", "Retrieves inventory with limited fields, end and start specified.", "");
}
}
#region "Requests"
[ApiResponse(200, "Records retrieved OK")]
[ApiResponse(401, "Not authenticated")]
[ApiResponse(404, "Handler for Request not found")]
public class GetInventoryItemsLikeNameRequest : IReturn<GetInventoryItemsLikeNameResponse>
{
public string ItemName { get; set; }
}
#endregion
#region "Responses"
[Serializable()]
public class GetInventoryItemsLikeNameResponse : List<MyCustomModel>
{
}
#endregion
#region "Models"
public class MyCustomModel
{
public DateTime LastSavedDateTime { get; set; }
public string InventoryID { get; set; }
public string PartNo { get; set; }
public string Description { get; set; }
public int Status { get; set; }
public decimal DefaultPrice { get; set; }
public decimal RRPPrice { get; set; }
public string Aux2 { get; set; }
public bool BackOrderable { get; set; }
public decimal Price1 { get; set; }
public decimal Price2 { get; set; }
public decimal Price3 { get; set; }
public decimal Price4 { get; set; }
public decimal Price9 { get; set; }
}
#endregion
#region "Services"
public class CustomServices : Service
{
[Authenticate]
public GetInventoryItemsLikeNameResponse Get(GetInventoryItemsLikeNameRequest request)
{
string query = @"SELECT
main.LastSavedDateTime,
main.InventoryID,
main.PartNo,
main.Description,
main.Status,
main.DefaultPrice,
main.RRPPrice,
main.Aux2,
main.BackOrderable,
price.InventoryID,
price.Price1,
price.Price2,
price.Price3,
price.Price4,
price.Price9
FROM IN_Main main
LEFT JOIN
IN_SellingPrices price
ON
price.InventoryID=main.InventoryID
WHERE
main.Description LIKE '%@itemName%'
ORDER BY main.Description
;";
return Db.SqlList<MyCustomModel>(query,
new {ItemName = request.ItemName}).ConvertTo<GetInventoryItemsLikeNameResponse>();
}
}
#endregion
}



