예제 #1
0
        public static void AddProduct()
        {
            try
            {
                string   name           = SetInformation.SetName();
                DateTime productionDate = SetInformation.SetProductionDate();
                DateTime expirationDate = SetInformation.SetExpirationDate(productionDate);
                double   price          = SetInformation.SetPrice();
                int      amount         = SetInformation.SetAmount();
                Guid     producerId     = SetInformation.SetProducerId();

                Product newProduct = new Product()
                {
                    Name           = name,
                    ProductionDate = productionDate,
                    ExpirationDate = expirationDate,
                    Price          = price,
                    Amount         = amount,
                    ProducerId     = producerId
                };

                using (var context = new StockContext())
                {
                    context.Products.Add(newProduct);
                    context.SaveChanges();
                }
            }
            catch (ArgumentNullException)
            {
                throw;
            }
        }
예제 #2
0
        public static void AddProducer()
        {
            Producer newProducer = new Producer()
            {
                Name = SetInformation.SetName()
            };

            using (var context = new StockContext())
            {
                context.Producers.Add(newProducer);
                context.SaveChanges();
            }
        }
예제 #3
0
        public static void EditProduct(Product product)
        {
            switch (ChoicesMenu.ChoseColumn())
            {
            case (int)Columns.Name:
                product.Name = SetInformation.SetName();
                break;

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

            case (int)Columns.Amount:
                product.Amount = SetInformation.SetAmount();
                break;

            case (int)Columns.ProductionDate:
                product.ProductionDate = SetInformation.SetProductionDate();
                break;

            case (int)Columns.ExpirationDate:
                product.ExpirationDate = SetInformation.SetExpirationDate(product.ProductionDate);
                break;

            case (int)Columns.ProducerId:
                product.ProducerId = SetInformation.SetProducerId();
                break;

            default:
                Console.WriteLine("Нет такого поля");
                break;
            }

            using (var context = new StockContext())
            {
                var changeProduct = context.Products.Find(product.Id);
                context.Products.Remove(changeProduct);
                context.Products.Add(product);
                context.SaveChanges();
            }
        }