Пример #1
0
        public static void AddItem(string name, string description, string price, decimal distributionField)
        {
            using (InvContext context = new InvContext())
            {
                ItemCategory itemCategory = new ItemCategory();
                ItemStock    itemStock    = new ItemStock();
                itemCategory.Name        = name;
                itemCategory.Price       = Convert.ToDecimal(price);
                itemCategory.Description = description;

                itemStock.ItemStored = itemCategory;
                itemStock.Quantity   = 0;
                context.ItemCategories.Add(itemCategory);
                context.ItemStocks.Add(itemStock);
                context.SaveChanges();
            }
        }
Пример #2
0
        public static bool DeleteItem(string itemName)
        {
            using (InvContext context = new InvContext())
            {
                ItemCategory itemCategory = context.ItemCategories.FirstOrDefault(x => x.Name == itemName);
                ItemStock    itemStock    = context.ItemStocks.FirstOrDefault(x => x.ItemStored.Name == itemName);

                if (itemCategory != null && itemStock != null)
                {
                    context.ItemCategories.Remove(itemCategory);
                    context.ItemStocks.Remove(itemStock);
                    context.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }