コード例 #1
0
 public IActionResult EditInventoryItem(InventoryItem item)
 {
     user = HttpContext.Session.GetObject <User>("User");
     if (user == null)
     {
         Log.Error("User session was not found");
         return(RedirectToAction("Login", "Home"));
     }
     if (ModelState.IsValid)
     {
         using (var client = new HttpClient())
         {
             client.BaseAddress = new Uri(url);
             var json     = JsonConvert.SerializeObject(item);
             var data     = new StringContent(json, Encoding.UTF8, "application/json");
             var response = client.PutAsync("inventoryitem/update", data);
             response.Wait();
             var result = response.Result;
             if (result.IsSuccessStatusCode)
             {
                 alertService.Success("Successfully updated inventory item");
                 Log.Information($"Successfully updated inventory item: {json}");
                 return(RedirectToAction("GetInventory", new { locationId = 1 }));
             }
             alertService.Danger("Something went wrong. Please try again");
             Log.Error($"Unsuccessfully updated inventory item: {json}");
         }
     }
     Log.Error("ModelState is not valid for Manager/EditInventoryItem");
     return(RedirectToAction("GetInventory", new { locationId = 1 }));
 }