Example #1
0
        /// <summary>
        /// Registers this instance.
        /// </summary>
        /// <returns></returns>
        public IActionResult Register()
        {
            StockRegisterViewModel model = new StockRegisterViewModel()
            {
                Products = GetProducts()
            };

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> Register(StockRegisterViewModel model, string productSearchString)
        {
            try
            {
                if (string.IsNullOrEmpty(productSearchString))
                {
                    ModelState.AddModelError("Products", "Please select a product");
                    model.Products = this.GetProducts();
                    return(View(model));
                }

                Stock s = new Stock()
                {
                    Quantity  = model.Quantity,
                    Price     = model.Price,
                    ProductId = int.Parse(productSearchString)
                };

                var recordAdded = await this.PutAsync <int>(HttpUriFactory.GetNewStockRequest(this.options.Value.APIUrl), s);

                if (recordAdded > 0)
                {
                    ViewBag.Message = "Added successful";
                }
                else
                {
                    ViewBag.Message = TempData["Message"];
                }

                model.Products = this.GetProducts();
                return(View(model));
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
                Utilities.LogAppError(this.logger, ex);
                return(View(model));
            }
        }