Esempio n. 1
0
        public bool Add(ProductDto product)
        {
            try
            {
                if (!_product.GetAll().Any(i => i.Name == product.Name || i.Alias == product.Alias)
                    && product.Price_per_unit > 0)
                {
                    _product.Add(new Products
                    {
                        Name = product.Name,
                        Price_per_unit = product.Price_per_unit,
                        Unit = product.Unit,
                        Alias = product.Alias
                    });

                    _unitOfWork.Commit();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
Esempio n. 2
0
        public bool Update(ProductDto product)
        {
            if (product.Price_per_unit > 0)
            {
                foreach (var item in _product.GetAll().Where(i => i.ID == product.ID))
                {
                    item.Name = product.Name;
                    item.Price_per_unit = product.Price_per_unit;
                    item.Unit = product.Unit;
                    item.Alias = product.Alias;
                }

                _unitOfWork.Commit();
                return true;
            }
            return false;
        }
Esempio n. 3
0
        public ActionResult AddProduct(ProductViewModel productModel)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            ProductDto _productDto = new ProductDto();

            _productDto.Name = productModel.viewModel.ProductName;
            _productDto.Price_per_unit = productModel.viewModel.Price_per_unit;
            _productDto.Unit = productModel.viewModel.Unit;
            _productDto.Alias = productModel.viewModel.Alias;

            if (_productService.Add(_productDto))
            {
                errors.Add("Dodano produkt.");
            }
            else
            {
                errors.Add("Błąd. Spróbuj ponownie.");
            }
            Session["val"] = errors.ToArray<string>();

            return RedirectToAction("Admin");
        }