Académique Documents
Professionnel Documents
Culture Documents
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net.Http;
using System.Web.Http;
using ONGC_WEB_SERVICES.Models;
using MySql.Data.MySqlClient;
using System.Data;
using System.Web;
using System.Configuration;
namespace ONGC_WEB_SERVICES.Controllers
{
public class BOREControllers : System.Web.Mvc.Controller
{
//
// GET: /BORE/
[HttpGet]
public List<BORE_WEB> GetBORE_WEB()
{
string Str="Server=localhost;Port=3022;Database=ongc;Uid=;root;Pwd=root";
[HttpPost]
public object ONGC_WEB_SERVICES (HttpRequestMessage RequestMsgData)
{
ApiStatus _apistatus = new ApiStatus();
_apistatus.status = false;
_apistatus.statusmessage = "";
_apistatus.id = null;
string readQuery = "";
try
{
//Take out Posted values
var jsonAsyncString =
RequestMsgData.Content.ReadAsStringAsync().Result;
jsonAsyncString = "{"+jsonAsyncString+"\"}";
if (!(String.IsNullOrEmpty(jsonAsyncString)))
{
// whereClause = HttpUtility.UrlDecode(whereClause);
//Get DB Resultset
List<object> results = new List<object>();
// MySql.Connection oc = new
.DataSourceConnection().getConn("nr");
oc.Open();
if (results.Count > 0)
{
_apistatus.id = results;
_apistatus.status = true;
_apistatus.statusmessage = "Fetched Feedbacks";
}
else
{
_apistatus.statusmessage = "No Feedback Found!";
}
} // End if
else
{
_apistatus.statusmessage = "Error msg" + readQuery;
}
return _apistatus;
}
catch (Exception exp)
{
_apistatus.statusmessage = exp.ToString();
return _apistatus;
}
} // End
using (conn)
{
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = query;
MySqlDataReader reader = cmd.ExecuteReader();
DataTable dtSchema;
Dictionary<string, object> ValuePair = new Dictionary<string,
object>();
string[] tableColName;
dtSchema = reader.GetSchemaTable();
tableColName = rowValues.ToArray();
if (reader.HasRows)
{
string tempColName = "";
while (reader.Read())
{
ValuePair = new Dictionary<string, object>();
for (int i = 0; i < reader.FieldCount; i++)
{
tempColName = tableColName[i].ToString();
ValuePair[tempColName] = reader[tempColName];
}
results.Add(ValuePair);
}
}
}
return results;
} // End
if (myDict.ContainsKey("matchmode"))
{
matchmode = myDict["matchmode"];
myDict.Remove("matchmode");
}
if (myDict.Count > 0)
{
foreach (KeyValuePair<string, dynamic> entry in myDict)
{
// do something with entry.Value or entry.Key
if (matchmode == "EXACT")
{
wherePartial = wherePartial + entry.Key + " = '" +
HttpUtility.UrlDecode(entry.Value) + "' " + _stringJoiner + " ";
}
if (matchmode == "LIKE")
{
wherePartial = wherePartial + entry.Key + " Like '%" +
HttpUtility.UrlDecode(entry.Value) + "%' " + _stringJoiner + " ";
}
}
}
if (wherePartial != "")
{
wherePartial = wherePartial.TrimEnd(' ');
wherePartial = wherePartial.Remove(wherePartial.Length -
_stringJoiner.Length);
whereClause = " Where " + wherePartial;
}
return whereClause;
} // End Class
class ApiStatus
{
public bool status;
public string statusmessage;
public object id;
}
} // End Namespace
2.using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ONGC_WEB_SERVICES.Controllers
{
class ApiStatus1
{
public bool status { get; set; }
3.using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ONGC_WEB_SERVICES.Models
{
public class BORE_WEB
{
public string INSERT_DATE { get; set; }
public string INSERT_USER { get; set; }
public string UPDATE_DATE { get; set; }
public string UPDATE_USER { get; set; }
public string ID { get; set; }
public string NAME { get; set; }
public string BOREHOLE_NUMBER { get; set; }
public string BOTTOM_LOCATION_ID { get; set; }
public string CURRENT_STATUS_DATE { get; set; }
public string CURRENT_STATUS { get; set; }
}
}
4.global.asax.ac
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Routing;
namespace Testapi
{
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
}