private void AddButton_OnClick(object sender, RoutedEventArgs e)
        {
            Item item;

            switch (_productType)
            {
            case ProductType.Alloywheel:
                item = new Alloywheel(Brand, Model, Stocks, UnitPrice, Dimension);
                break;

            case ProductType.Battery:
                item = new Battery(Brand, Model, Stocks, UnitPrice, Capacity, Voltage);
                break;

            case ProductType.Tyre:
                item = new Tyre(Brand, Model, Stocks, UnitPrice, Dimension, Country);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (item.Validate())
            {
                _productHandler.AddProduct(item);
            }
            else
            {
                MessageBox.Show("Some required information are missing. Please check again.", "Information",
                                MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            DialogResult = true;
            Close();
        }
Exemple #2
0
            /// <summary>
            ///     Updates Alloywheel details
            /// </summary>
            /// <param name="alloywheel"></param>
            /// <param name="model"></param>
            /// <param name="stockqty"></param>
            /// <param name="unitPrice"></param>
            /// <param name="brand"></param>
            /// <param name="dimension"></param>
            public void Update(Alloywheel alloywheel, string model = null, uint?stockqty = null,
                               decimal?unitPrice = null, string brand = null, string dimension = null)
            {
                if (model == null && stockqty == null && unitPrice == null && brand == null && dimension == null)
                {
                    throw new ArgumentNullException(nameof(Update), "No parameters passed to update");
                }
                if (alloywheel.Id == null)
                {
                    throw new ArgumentNullException(nameof(alloywheel.Id), "Updating component does not have Id");
                }
                using (var scope = new TransactionScope())
                {
                    using (var connection = Connector.GetConnection())
                    {
                        var id = alloywheel.Id.Value;
                        if (model != null)
                        {
                            Update(id, model, connection);
                        }
                        if (stockqty != null || unitPrice != null)
                        {
                            Update(id, stockqty, unitPrice, connection);
                        }
                        if (brand != null || dimension != null)
                        {
                            new AlloywheelDal(connection).Update(alloywheel.Id.Value, brand, dimension);
                        }
                    }
                    scope.Complete();
                }

                alloywheel.Model     = model ?? alloywheel.Model;
                alloywheel.StockQty  = stockqty ?? alloywheel.StockQty;
                alloywheel.UnitPrice = unitPrice ?? alloywheel.UnitPrice;
                alloywheel.Brand     = brand ?? alloywheel.Brand;
                alloywheel.Dimension = dimension ?? alloywheel.Dimension;
            }