Exemplo n.º 1
0
        public static void EditProduct(Product product)
        {
            switch (Menu.ChooseColumn())
            {
            case Column.Name:
                product.Name = SetInformation.SetName();
                break;

            case Column.Price:
                product.Price = SetInformation.SetPrice();
                break;

            case Column.Quantity:
                product.Quantity = SetInformation.SetAmount();
                break;

            case Column.ManufacturerId:
                product.ManufacturerId = SetInformation.SetManufacturerId();
                break;
            }

            using (var context = new StockContext())
            {
                var changeProduct = context.Products.Find(product.Id);
                context.Products.Remove(changeProduct);
                context.Products.Add(product);
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static void AddProduct()
        {
            string name       = SetInformation.SetName();
            double price      = SetInformation.SetPrice();
            int    amount     = SetInformation.SetAmount();
            Guid   producerId = SetInformation.SetManufacturerId();

            Product newProduct = new Product()
            {
                Name           = name,
                Price          = price,
                Quantity       = amount,
                ManufacturerId = producerId
            };

            using (var context = new StockContext())
            {
                context.Products.Add(newProduct);
                context.SaveChanges();
            }
        }