public ActionResult GetDetails(string id) { #region attempt1 Shopbridge_inventoryModel item_ = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44394/api/"); var responseTask = client.GetAsync("Shopbridge_inventory_1/" + id); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readjob = result.Content.ReadAsAsync <Shopbridge_inventoryModel>(); readjob.Wait(); item_ = readjob.Result; } else { item_ = new Shopbridge_inventoryModel(); ModelState.AddModelError(string.Empty, "Server Error"); } } #endregion return(View("Details", item_)); }
public void Create(Shopbridge_inventoryModel obj) { obj = new Shopbridge_inventoryModel(); obj.Name_ = "apple"; obj.description_ = "Shimla apples"; obj.price = 100; obj.image_name = "apple.png"; obj.thumb_name = "apple_thumb.jpg"; // Arrange ShopBridge_InventoryController controller = new ShopBridge_InventoryController(); // Act ViewResult result = controller.Create(obj) as ViewResult; // Assert Assert.IsNotNull(result); }
public ActionResult Create(Shopbridge_inventoryModel obj) { HttpPostedFileBase file = Request.Files["image_name"]; if (file != null && !string.IsNullOrEmpty(file.FileName)) { obj.image_name = file.FileName; obj.thumb_name = file.FileName.Split('.')[0] + "_thumb.jpg"; UploadFiles(file); } else { obj.image_name = ""; obj.thumb_name = ""; } var json = new JavaScriptSerializer().Serialize(obj); using (var stringContent = new StringContent(json, System.Text.Encoding.UTF8, "application/json")) using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44394/api/"); var postJob = client.PostAsync(client.BaseAddress + "shopbridge_inventory_1", stringContent); postJob.Wait(); var postResult = postJob.Result; if (postResult.IsSuccessStatusCode) { // ModelState.Clear(); return(RedirectToAction("_ListOfItems")); } } return(View("Index")); }