protected string CreateRichMenu(RichMenuModel_FromBackend val) { string result = ""; string CreateRichMenu = appSettings.Value.CreateRichMenuUrl; var client = new RestClient(CreateRichMenu); client.Timeout = -1; var request = new RestRequest(Method.POST); try { string output = JsonConvert.SerializeObject(val); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Authorization", lineAccessToken); request.AddParameter("application/json", output, ParameterType.RequestBody); IRestResponse response = client.Execute(request); result = response.Content; } catch (Exception ex) { result = ex.Message; } return(result); }
public IActionResult Post([FromBody] RichMenuModel_FromBackend val) { bool isSetDefault = false; var result = ""; var resultFromUploadImage = ""; var resultFromSetDeaultMenu = ""; var key = ""; var menuId = ""; var imageBase64 = val.img; isSetDefault = val.setDefault; try { result = CreateRichMenu(val); dynamic value = JsonConvert.DeserializeObject(result); foreach (JProperty item in value) { key = item.Name; menuId = (string)item.Value; } if (key == "richMenuId") { resultFromUploadImage = UploadImageRichMenu(menuId, imageBase64); resultFromSetDeaultMenu = (isSetDefault) ? SetDefaultMenu(menuId) : "Success"; if (resultFromUploadImage != "Success" || resultFromSetDeaultMenu != "Success") { return(NotFound(string.Join(resultFromUploadImage, " ", resultFromSetDeaultMenu))); } } else { return(NotFound(menuId)); } } catch (Exception ex) { return(NotFound(ex.Message)); } return(Ok(result)); }