コード例 #1
0
        private async void addButton_Click(object sender, EventArgs e)
        {
            if (!ValidateForm())
            {
                MessageBox.Show("Please provide a name, category and status.");
                return;
            }


            ProductModel model = new ProductModel();

            model.Id                = Guid.NewGuid();
            model.Name              = nameTextbox.Text;
            model.Description       = descriptionTextbox.Text;
            model.Category          = categoryComboBox.Text;
            model.Status            = statusComboBox.Text;
            model.ProductURL        = urlTextbox.Text;
            model.ImagePath         = imagePathTextbox.Text;
            model.DateAdded         = DateTime.Now;
            model.IntialStock       = int.Parse(initialStockTextbox.Text);
            model.StockTransactions = new List <StockTransaction>();

            try
            {
                await _productManager.AddProductAsync(model);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                MessageBox.Show("Oops, something wen't wrong! Please try again.");
                return;
            }

            nameTextbox.Text             = "";
            descriptionTextbox.Text      = "";
            categoryComboBox.Text        = "";
            statusComboBox.Text          = "";
            urlTextbox.Text              = "";
            imagePathTextbox.Text        = "";
            initialStockTextbox.Text     = "";
            imagePreviewPicturebox.Image = null;

            OnUpdateListView();
        }