public void ShouldCreateNewProduct()
        {
            var product = ProductBuilder.BuildProduct(_brand, _country);

            product = _productApplicationService.CreateProduct(product);
            product.Id.ShouldNotBeTheSameAs(0);
        }
Esempio n. 2
0
        public ActionResult CreateProduct(Product newProduct, FormCollection formCollection)
        {
            if (_productApplicationService.FindProductByGtinInOwnDatabase(newProduct.GlobalTradeItemNumber, false) != null)
            {
                ModelState.AddModelError("GlobalTradeItemNumber", "Product already exists");
                InitViewData();
                ViewData["Ingredients"] = _ingredientApplicationService.GetAllIngredients();
                return(View(newProduct));
            }
            if (!newProduct.GlobalTradeItemNumber.IsGtin())
            {
                ModelState.AddModelError("GlobalTradeItemNumber", "Not a proper GTIN");
                InitViewData();
                ViewData["Ingredients"] = _ingredientApplicationService.GetAllIngredients();
                return(View(newProduct));
            }

            try
            {
                newProduct = _productApplicationService.CreateProduct(newProduct);

                var certificationMarks = formCollection.GetValues("CertificationMarks") ?? new string[] { };
                _productApplicationService.RemoveAllCertificationMarksFromProduct(newProduct.Id);
                foreach (var certificationMark in certificationMarks)
                {
                    int certificationMarkId;
                    if (int.TryParse(certificationMark, out certificationMarkId))
                    {
                        _productApplicationService.AddCertificationMarkToProduct(newProduct.Id, int.Parse(certificationMark));
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
            }


            InitViewData();
            ViewData["Ingredients"] = _ingredientApplicationService.GetAllIngredients();
            return(View(newProduct));
        }
Esempio n. 3
0
        public async Task <IActionResult> CreateProduct(CreatePrductRequestViewModel viewModel)
        {
            await _productApplicationService.CreateProduct(viewModel);

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 4
0
        public async Task <ActionResult <ProductResponseViewModel> > Create([FromBody] CreatePrductRequestViewModel viewModel)
        {
            var result = await _productApplicationService.CreateProduct(viewModel);

            return(Response(result));
        }