Esempio n. 1
0
        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());
            }
        }
Esempio n. 2
0
        // 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));
            }
        }
Esempio n. 3
0
 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())));
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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)));
            }
        }