Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SampleController : ApiController
- {
- [HttpGet]
- [Route("api/getobject")]
- public HttpResponseMessage GetByGSTNumber(string token, string key)
- {
- DataConnection connection = null; new DataConnection();//Set up COM reference
- DataObject dataObj = null;
- try
- {
- connection = new DataConnection();
- connection.login(token);
- dataObj = new DataObject(connection);
- Request.CreateResponse(HttpStatusCode.OK, dataObj);
- }
- catch (Exception ex)
- {
- return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
- }
- finally
- {
- if (connection != null) { Request.RegisterForDispose(connection); }
- if (dataObj != null) { Request.RegisterForDispose(dataObj); }
- }
- }
- }
- public class DataObject : IDisposable
- {
- internal DataConnection dbConnection;
- internal dynamic _dataRecord;
- public string Key
- {
- get { return _dataRecord.KeyField.ToString(); }
- }
- public string Property1
- {
- get { return _dataRecord.Property1Feild.ToString(); }
- }
- public DataObject(DataConnection connection)
- {
- dbConnection = connection;
- }
- public void OpenRecord(string key)
- {
- if (!_dataRecord.Seek(key))
- {
- throw new Exception("Record not found");
- }
- }
- #region IDisposable Support
- }
- return Request.CreateResponse(HttpStatusCode.OK, dataObj);
- //Returns JSON even if specifying XML in request
- return Request.CreateResponse(HttpStatusCode.OK, dataObj "application/xml");
- // returns <ExceptionMessage>Could not find a formatter matching the media type 'application/xml' that can write an instance of 'DataObject'.</ExceptionMessage>
Add Comment
Please, Sign In to add comment