public IActionResult EditInventory(Inventory inventory) { manager = HttpContext.Session.GetObject <Manager>("Manager"); if (manager == null) { Log.Error("Manager session not found"); return(RedirectToAction("LoginM", "Home")); } if (ModelState.IsValid) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(url); var json = JsonConvert.SerializeObject(inventory); var data = new StringContent(json, Encoding.UTF8, "application/json"); var response = client.PutAsync("inventory/update", data); response.Wait(); var result = response.Result; if (result.IsSuccessStatusCode) { alertServices.Success("Successfully updated inventory"); Log.Information($"Successfully updated inventory: {json}"); return(RedirectToAction("GetInventory", new { locationId = 1 })); } alertServices.Danger("Something went wrong"); Log.Error($"Unsuccessfully updated inventory item: {json}"); } } Log.Error("ModelState is not valid"); return(RedirectToAction("GetInventory", new { locationId = 1 })); }
public IActionResult EditCustomer(Customer newCust) { customer = HttpContext.Session.GetObject <Customer>("Customer"); Log.Information($"About to get information for {customer.email}"); if (customer == null) { Log.Error("Customer session was not found"); return(RedirectToAction("LoginC", "Home")); } if (ModelState.IsValid) { newCust.location = customer.location; newCust.orders = customer.orders; using (var client = new HttpClient()) { client.BaseAddress = new Uri(url); var json = JsonConvert.SerializeObject(newCust); var data = new StringContent(json, Encoding.UTF8, "application/json"); var response = client.PutAsync("customer/update", data); response.Wait(); var result = response.Result; if (result.IsSuccessStatusCode) { // Successfully edited user HttpContext.Session.SetObject("Customer", newCust); alertServices.Success("Succesfully updated information"); Log.Information($"Succesfully updated customer: {newCust}"); return(View(newCust)); } else { alertServices.Danger("Something went wrong"); } } return(View("Get Inventory")); } Log.Error($"State is not valid {ModelState}"); return(RedirectToAction("GetInventory")); }