Beispiel #1
0
        public async Task <IActionResult> Post([FromBody] Product product)
        {
            var data = await _productManager.AddAsync(product);

            if (data)
            {
                return(Ok("Product added"));
            }
            else
            {
                return(BadRequest("Product could not be added."));
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Add(ProductViewModel productViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await productManager.AddAsync(productViewModel.ToEntity());

                    return(RedirectToAction("Index"));
                }

                return(View(productViewModel));
            }
            catch (BusinessException ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);

                return(View(productViewModel));
            }
        }