public override void OnException(ExceptionContext filterContext) { //If message is null or empty, then fill with generic message var errorMessage = filterContext.Exception.Message; //Set the response status code to 500 filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; //Needed for IIS7.0 filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; var result = new ApiResultEntity() { Status = ApiStatusEnum.Failure.ToString(), ErrorMessage = errorMessage }; filterContext.Result = new JsonResult { Data = result, ContentEncoding = System.Text.Encoding.UTF8, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; //Let the system know that the exception has been handled filterContext.ExceptionHandled = true; }
private void BtnOrder_Click(object sender, EventArgs e) { SapSalesOrder _SapSalesOrder = setSalesOrder(); string json = JsonConvert.SerializeObject(_SapSalesOrder); string _Action = "Index"; string _Uri = _ConnectionString + _Action; ApiResultEntity _ApiResult = CallWebAPI.Post(json, _Uri); }
private void BtnGet_Click(object sender, EventArgs e) { string _Action = "EdiCustomer"; string _Uri = _ConnectionString + _Action + "?mode=" + _EdiMode.ToString(); ApiResultEntity _ApiResult = CallWebAPI.Get(_Uri, _Token); this._edi_Customerlist = JsonConvert.DeserializeObject <List <Edi_Customer> >(_ApiResult.Data.ToString()); }
private List <Edi_SalesSchedule> getSalesScheduleList(string orderNumber) { string _Action = "EdiSalesSchedule"; string _Uri = _ConnectionString + _Action + "?orderNumber=" + orderNumber; ApiResultEntity _ApiResult = CallWebAPI.Get(_Uri, _Token); return(JsonConvert.DeserializeObject <List <Edi_SalesSchedule> >(_ApiResult.Data.ToString())); }
private List <Edi_SalesHeader> getSalesHeaderList() { string _Action = "EdiSalesHeader"; string _Uri = _ConnectionString + _Action; ApiResultEntity _ApiResult = CallWebAPI.Get(_Uri, _Token); return(JsonConvert.DeserializeObject <List <Edi_SalesHeader> >(_ApiResult.Data.ToString())); }
private string insertEdi_855(Edi_SalesOrder_855 sapSalesOrder) { string json = JsonConvert.SerializeObject(sapSalesOrder); string _Action = "EdiSalesOrder_855"; string _Uri = _ConnectionString + _Action; ApiResultEntity _ApiResult = CallWebAPI.Post(json, _Uri); return(_ApiResult.Data.ToString()); }
/// <summary> /// call webapi to create order & return order number /// </summary> /// <param name="sapSalesOrder"></param> /// <returns></returns> public static string creatOrder(SapSalesOrder sapSalesOrder) { string json = JsonConvert.SerializeObject(sapSalesOrder); string _Action = "BapiOrder"; string _Uri = _ConnectionString + _Action; ApiResultEntity _ApiResult = CallWebAPI.Post(json, _Uri); return(_ApiResult.Data.ToString()); }
public override void OnResultExecuting(ResultExecutingContext filterContext) { if (filterContext.Result is JsonResult) { var result = filterContext.Result as JsonResult; var data = result.Data; ApiResultEntity entity = new ApiResultEntity(); entity.Status = ApiStatusEnum.Success.ToString(); entity.Data = data; result.Data = entity; } }
public static ApiResultEntity Get(string uri, string token) { string result = ""; using (WebClient webClient = new WebClient()) { // 指定 WebClient 編碼 webClient.Encoding = Encoding.UTF8; // 指定 WebClient 的 Content-Type header webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json"); // 指定 WebClient 的 authorization header webClient.Headers.Add("authorization", "Bearer " + token); // 執行 gett 動作 result = webClient.DownloadString(uri); } ApiResultEntity _ApiResult = JsonConvert.DeserializeObject <ApiResultEntity>(result); return(_ApiResult); }
public static string Login(string jsonData, string uri) { string result = ""; using (WebClient webClient = new WebClient()) { // 指定 WebClient 編碼 webClient.Encoding = Encoding.UTF8; // 指定 WebClient 的 Content-Type header webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json"); // 指定 WebClient 的 authorization header //webClient.Headers.Add("authorization", "token {apitoken}"); // 執行 post 動作 result = webClient.UploadString(uri, jsonData); ApiResultEntity _ApiResult = JsonConvert.DeserializeObject <ApiResultEntity>(result); ReturnToken _ReturnToken = JsonConvert.DeserializeObject <ReturnToken>(_ApiResult.Data.ToString()); _Token = _ReturnToken.token; } return(_Token); }