public async Task <string> InsertItemAsync(ShipperVM oShipper) { string rc = ""; try { string sUrl = urlServer + "/api/Shipper/Insert"; string jsonData = JsonSerializer.Serialize <ShipperVM>(oShipper); HttpClient http = new HttpClient(); HttpContent content = new StringContent(jsonData, Encoding.UTF8, "application/json"); HttpResponseMessage response = await http.PostAsync(sUrl, content); if (response.IsSuccessStatusCode) { string jRlt = await response.Content.ReadAsStringAsync(); JsonRltInfo oRlt = JsonSerializer.Deserialize <JsonRltInfo>(jRlt); if (oRlt.rltCode == 0) { rc = oRlt.rltMsg; } else { throw new Exception(oRlt.rltMsg); } } } catch (Exception ex) { throw new Exception(ex.Message); } return(rc); }
public async Task <string> DelItemAsync(int ShipperID) { string rc = ""; try { HttpClient client = new HttpClient(); string sUrl = urlServer + "/api/Shipper/Del/" + ShipperID.ToString(); HttpResponseMessage response = await client.GetAsync(sUrl); string jData = await response.Content.ReadAsStringAsync(); JsonRltInfo oRlt = JsonSerializer.Deserialize <JsonRltInfo>(jData); if (oRlt.rltCode == 0) { rc = oRlt.rltMsg; } else { throw new Exception(oRlt.rltMsg); } } catch (Exception ex) { throw new Exception(ex.Message); } return(rc); }
public JsonRltInfo UpdateItem([FromBody] ShipperAM oShipper) { JsonRltInfo oRlt = new JsonRltInfo(); ShipperDao dao = new ShipperDao(); try { string rc = dao.ChgShipper(oShipper); if (rc == "Success") { oRlt.rltCode = 0; oRlt.rltMsg = "更新成功"; } } catch (Exception ex) { oRlt.rltCode = 417; oRlt.rltMsg = ex.Message; } return(oRlt); }
public JsonRltInfo DelItem(int ShipperID) { JsonRltInfo oRlt = new JsonRltInfo(); ShipperDao dao = new ShipperDao(); try { string rc = dao.DelShipper(ShipperID); if (rc == "Success") { oRlt.rltCode = 0; oRlt.rltMsg = "刪除成功"; } } catch (Exception ex) { oRlt.rltCode = 417; oRlt.rltMsg = ex.Message; } return(oRlt); }