by JuiceyBrucey » Tue Mar 02, 2021 2:05 pm
Yes, to clarify, I dont want all fields/columns returned. I want to specify which fields to return and not any others.
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;
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(MyGetInventoryBlockRequest), "/Custom/GetInventoryBlock/{StartPosition}/{EndPosition}", "GET", "Retrieves a block of inventory specified by start and end position.", "");
}
}
#region "Requests"
[Serializable()]
[ApiResponse(200, "Records retrieved OK")]
[ApiResponse(401, "Not authenticated")]
[ApiResponse(404, "No debtor with the Account No. provided was found")]
public class MyGetInventoryBlockRequest : IReturn<MyGetInventoryBlockResponse>
{
public int StartPosition{ get; set; }
public int EndPosition { get; set; }
}
#endregion
#region "Responses"
[Serializable()]
public class MyGetInventoryBlockResponse
{
public List<IN_Main> RecordResults {get; set;}
}
#endregion
#region "Services"
public class CustomServices : Service
{
[Authenticate]
public MyGetInventoryBlockResponse Get(MyGetInventoryBlockRequest request)
{
var query = Db.From<IN_Main>().Join<IN_Main, IN_SellingPrices>((main, prices) => main.InventoryID == prices.InventoryID).Limit(request.StartPosition,request.EndPosition);
return new MyGetInventoryBlockResponse() { RecordResults = Db.Select(query) } ;
}
}
#endregion
}