Exemplo n.º 1
0
        public void AddProduct(Product product, Core.Entities.ProductCategory category)
        {
            var newProduct = new Product();
            

            var currentUser = UserManager.FindById(User.Identity.GetUserId());
            var prfileId = currentUser.UserProfile.Id;
            var supplierId = _merchantService.FindSupplierBy(prfileId).Id;

            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                newProduct.ProductName = product.ProductName;
                newProduct.ProductDescLong = product.ProductDescLong;
                newProduct.ProductDescShort = product.ProductDescShort;
                newProduct.ProductImgLargeUrl = "/Content/Assets/Images/product_default_lg.png";
                newProduct.ProductImgSmallUrl = "/Content/Assets/Images/product_default_sm.png";
                newProduct.UnitName = product.UnitName;
                newProduct.Notes = product.Notes;
                newProduct.UnitsInStock = 0;//Not implemented
                newProduct.UnitPrice = product.UnitPrice;
                newProduct.SupplierId = supplierId;
                newProduct.ProductAvailable = product.ProductAvailable;
                newProduct.CreateDate = DateTime.Now;
                newProduct.UpdateDate = DateTime.Now;


                _productServices.AddNewProduct(newProduct, category);
            }

        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public void Execute(string[] commands)
        {
            if (commands.Length != 4)
            {
                Console.WriteLine("Command parameters not valid!");
                return;
            }
            _productCode = commands[1];
            int.TryParse(commands[2], out _price);
            int.TryParse(commands[3], out _stock);

            _productService.AddNewProduct(_productCode, _price, _stock);
        }
Exemplo n.º 3
0
        private void AddNewProduct(object sender, EventArgs e)
        {
            var viewModel = new ProductModel
            {
                BaseCost    = Convert.ToDecimal(txtBaseCost.Text),
                InputCost   = Convert.ToDecimal(txtBaseCost.Text),
                CategoryId  = (int)cbxCategory.SelectedValue,
                SupplierId  = (int)cbxSupplier.SelectedValue,
                Stock       = Convert.ToInt32(txtStock.Text),
                Name        = txtName.Text,
                IssuedDate  = dtPickerIssuedDate.Value,
                ExpiredDate = dtPickerExpiredDate.Value,
                Status      = cbxStatus.SelectedValue.ToString()
            };

            try
            {
                if (_productServices.AddNewProduct(Mapper.Map <ProductModel>(viewModel)) > 0)
                {
                    if (YesNoDialog("Thành Công!", "Bạn có muốn tiếp tục không ?") == DialogResult.Yes)
                    {
                        ClearForm();
                    }
                    else
                    {
                        Close();
                    }
                }
                else
                {
                    ErrorMessage("Lỗi!", "Mặt hàng này đã tồn tại trong hệ thống!");
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                ErrorMessage();
            }
        }