daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [System.Web.Http.RoutePrefix("api/PurchaseOrder")]
  2. public class PurchaseOrderController : ApiController
  3. {
  4.     private static ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  5.  
  6.     [System.Web.Http.Route("PagingCriticalPart")]
  7.     [System.Web.Http.HttpPost]
  8.     public JsonResult PagingCriticalPart([FromBody] Helper.DataTablesBase model)
  9.     {
  10.         logger.Info("PagingCriticalPart");
  11.         JsonResult jsonResult = new JsonResult();
  12.         try
  13.         {
  14.             if (model == null) { logger.Info("model is null."); }
  15.  
  16.             int filteredResultsCount;
  17.             int totalResultsCount;
  18.             var res = BLL.PurchaseOrderHandler.PagingCriticalPart(model, out filteredResultsCount, out totalResultsCount);
  19.  
  20.             var result = new List<Models.T_CT2_CriticalPart>(res.Count);
  21.             foreach (var s in res)
  22.             {
  23.                 // simple remapping adding extra info to found dataset
  24.                 result.Add(new Models.T_CT2_CriticalPart
  25.                 {
  26.                     active = s.active,
  27.                     createBy = s.createBy,
  28.                     createdDate = s.createdDate,
  29.                     id = s.id,
  30.                     modifiedBy = s.modifiedBy,
  31.                     modifiedDate = s.modifiedDate,
  32.                     partDescription = s.partDescription,
  33.                     partNumber = s.partNumber
  34.                 });
  35.             };
  36.  
  37.             jsonResult.Data = new
  38.             {
  39.                 draw = model.draw,
  40.                 recordsTotal = totalResultsCount,
  41.                 recordsFiltered = filteredResultsCount,
  42.                 data = result
  43.             };
  44.             return jsonResult;
  45.         }
  46.         catch (Exception exception)
  47.         {
  48.             logger.Error("PagingCriticalPart", exception);
  49.             string exceptionMessage = ((string.IsNullOrEmpty(exception.Message)) ? "" : Environment.NewLine + Environment.NewLine + exception.Message);
  50.             string innerExceptionMessage = ((exception.InnerException == null) ? "" : ((string.IsNullOrEmpty(exception.InnerException.Message)) ? "" : Environment.NewLine + Environment.NewLine + exception.InnerException.Message));
  51.             jsonResult.Data = new
  52.             {
  53.                 draw = model.draw,
  54.                 recordsTotal = 0,
  55.                 recordsFiltered = 0,
  56.                 data = new { },
  57.                 error = exception.Message
  58.             };
  59.             return jsonResult;
  60.         }
  61.     }
  62.  
  63.     [System.Web.Http.Route("UploadRawMaterialData")]
  64.     [System.Web.Http.HttpPost]
  65.     public JsonResult UploadRawMaterialData(string rawMaterialSupplierData)
  66.     {
  67.         JsonResult jsonResult = new JsonResult();
  68.         jsonResult.Data = new
  69.         {
  70.             uploadSuccess = true
  71.         };
  72.         return jsonResult;
  73.     }
  74. }
  75.    
  76. "ajax": {
  77.     url: 'http://localhost/ControlTower2WebAPI/api/PurchaseOrder/PagingCriticalPart',
  78.     type: 'POST',
  79.     contentType: "application/json",
  80.     data: function (data) {
  81.         //debugger;
  82.         var model = {
  83.             draw: data.draw,
  84.             start: data.start,
  85.             length: data.length,
  86.             columns: data.columns,
  87.             search: data.search,
  88.             order: data.order
  89.         };
  90.         return JSON.stringify(model);
  91.     },
  92.     failure: function (result) {
  93.         debugger;
  94.         alert("Error occurred while trying to get data from server: " + result.sEcho);
  95.     },
  96.     error: function (XMLHttpRequest, textStatus, errorThrown) {
  97.         debugger;
  98.         alert("Error occurred while trying to get data from server!");
  99.     },
  100.     dataSrc: function (json) {
  101.         //debugger;
  102.         for (key in json.Data) { json[key] = json.Data[key]; }
  103.         delete json['Data'];
  104.         return json.data;
  105.     }
  106. }
  107.    
  108. var data = Newtonsoft.Json.JsonConvert.SerializeObject(rawMaterialVendorUploads);
  109. string apiURL = @"http://localhost/ControlTower2WebAPI/api/PurchaseOrder/UploadRawMaterialData";
  110. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
  111. request.UseDefaultCredentials = true;
  112. request.Method = "POST";
  113. request.ContentType = "application/json";
  114. request.ContentLength = data.Length;
  115. using (Stream webStream = request.GetRequestStream())
  116. using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII))
  117. {
  118.     requestWriter.Write(data);
  119. }
  120.  
  121. try
  122. {
  123.     WebResponse webResponse = request.GetResponse();
  124.     using (Stream webStream = webResponse.GetResponseStream() ?? Stream.Null)
  125.     using (StreamReader responseReader = new StreamReader(webStream))
  126.     {
  127.         string response = responseReader.ReadToEnd();
  128.     }
  129. }
  130. catch (Exception exception)
  131. {
  132.  
  133. }
  134.    
  135. {
  136.     "Message": "No HTTP resource was found that matches the request URI 'http://localhost/ControlTower2WebAPI/api/PurchaseOrder/UploadRawMaterialData'.",
  137.     "MessageDetail": "No action was found on the controller 'PurchaseOrder' that matches the request."
  138. }
  139.    
  140. http://localhost/ControlTower2WebAPI/api/PurchaseOrder/UploadRawMaterialData?rawMaterialSupplierData=test
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top