public ActionResult Edit(InventoryDetailViewModel model) { try { string apiUrl = server + "/api/InventoryDetails/" + model.InventoryDetailId; using (var client = new HttpClient()) { client.BaseAddress = new Uri(apiUrl); //HTTP POST var postTask = client.PutAsJsonAsync <InventoryDetailViewModel>(apiUrl, model); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: Product/Create public ActionResult Create() { InventoryDetailViewModel model = new InventoryDetailViewModel(); IEnumerable <ProductViewModel> products = null; IEnumerable <InventoryViewModel> inventories = null; string apiUrlInven = server + "/api/Inventories"; string apiUrlProduct = server + "/api/Products"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(apiUrlProduct); //HTTP GET var responseTask = client.GetAsync(apiUrlProduct); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <IEnumerable <ProductViewModel> >(); readTask.Wait(); products = readTask.Result; model.listProduct = products.ToList(); } else //web api sent error response { //log response status here.. products = Enumerable.Empty <ProductViewModel>(); ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } } using (var client = new HttpClient()) { client.BaseAddress = new Uri(apiUrlInven); //HTTP GET var responseTask = client.GetAsync(apiUrlInven); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <IEnumerable <InventoryViewModel> >(); readTask.Wait(); inventories = readTask.Result; model.listInventory = inventories.ToList(); } else //web api sent error response { //log response status here.. inventories = Enumerable.Empty <InventoryViewModel>(); ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } return(View("Insert", model)); } }
public InventoryDetailPage(Item item) { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); BindingContext = ViewModel = new InventoryDetailViewModel(item); ViewModel.Navigation = Navigation; }
public async Task <IActionResult> Details(string productCode) { return(await resiliencyHelper.ExecuteResilient(async() => { var inventory = await inventoryManagementAPI.GetInventoryByProductCode(productCode); var model = new InventoryDetailViewModel() { Inventory = inventory }; return View(model); }, View("Offline", new InventoryOfflineViewModel()))); }
public ActionResult Create(InventoryDetailViewModel model) { model.InventoryDetailId = model.InventoryDetailId.Trim(); string apiUrl = server + "/api/InventoryDetails"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(apiUrl); //HTTP POST var postTask = client.PostAsJsonAsync <InventoryDetailViewModel>(apiUrl, model); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); return(View(model)); }
public IActionResult Details(int id) { try { var vehicle = _vehicleService.GetVehicle(id, withIncludes: true); if (vehicle == null) { return(RedirectToAction(nameof(Index))); } var viewModel = new InventoryDetailViewModel { Vehicle = _mapper.Map <VehicleViewModel>(vehicle) }; return(View(viewModel)); } catch (Exception ex) { _logger.LogError(ex.Message); return(RedirectToAction(nameof(Index))); } }