public async Task <ShopConfigurationModel> CreateShopConfig(ShopConfigurationModel shop) { using (HttpClient httpClient = new HttpClient()) { string content = JsonConvert.SerializeObject(shop).ToString(); var stringContent = new StringContent(content, Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Current.Session["AccessToken"].ToString()); var response = await httpClient.PostAsync(uri + "ShopConfigurations", stringContent); if (response.IsSuccessStatusCode != true) { return(null); } var shopResponse = await response.Content.ReadAsStringAsync(); dynamic json = JsonConvert.DeserializeObject(shopResponse); ShopConfigurationModel ShopConfig = new ShopConfigurationModel(); ShopConfig.ShopId = Convert.ToInt64(json["ShopId"]); ShopConfig.BgColor = json["BgColor"].ToString(); ShopConfig.MenuColor = json["MenuColor"].ToString(); ShopConfig.MenuTextColor = json["MenuTextColor"].ToString(); ShopConfig.LayoutId = Convert.ToInt32(json["LayoutId"]); return(ShopConfig); } }
public async Task <HttpResponseMessage> EditShopConfig(ShopConfigurationModel shopConfig) { using (HttpClient httpClient = new HttpClient()) { string content = JsonConvert.SerializeObject(shopConfig).ToString(); var stringContent = new StringContent(content, Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Current.Session["AccessToken"].ToString()); var response = await httpClient.PutAsync(uri + "ShopConfigurations/" + shopConfig.ShopId, stringContent); return(response); } }
public async Task <ActionResult> EditConfig(ShopConfigurationModel shopConfigForEdit) { var response = await service.EditShopConfig(shopConfigForEdit); if (response.IsSuccessStatusCode) { var responseAfterPut = await service.GetOwnShopConfig(); return(View("ConfigSuccess", responseAfterPut)); } HttpResponseModel resp = new HttpResponseModel(); resp.ReasonMessage = response.ReasonPhrase; return(View("Failure", resp)); }
public async Task <ActionResult> CreateConfig(ShopConfigurationModel shopConfig) { ShopModel shop = await service.GetOwnShop(); if (shop == null) { HttpResponseModel resp = new HttpResponseModel(); resp.ReasonMessage = "No webshop present on account."; return(View("Failure", resp)); } shopConfig.ShopId = shop.Id; var response = await service.CreateShopConfig(shopConfig); if (response != null) { return(View("ConfigSuccess", response)); } else { HttpResponseModel resp = new HttpResponseModel(); resp.ReasonMessage = "Something went wrong!"; return(View("Failure", resp)); } }