예제 #1
0
        public Meal Save(Meal rootToSave)
        {
            try
            {
                Find(rootToSave.Id());
                throw new InvalidOperationException("meal with the save business identifier already exists");
            }
            catch (ArgumentException noMealFound)
            {
                ctx.Meals.Add(rootToSave);

                ctx.SaveChanges();

                return(Find(rootToSave.Id()));
            }
        }
        public ItemPurchase Save(ItemPurchase rootToSave)
        {
            try
            {
                Find(rootToSave.Id());
                throw new InvalidOperationException("item purchase with the same business identifier already exists");
            }
            catch (ArgumentException noItemPurchaseFound)
            {
                ctx.ItemPurchases.Add(rootToSave);

                ctx.SaveChanges();

                return(Find(rootToSave.Id()));
            }
        }
        public void Delete(Item rootToDelete)
        {
            ctx.Items.Remove(rootToDelete);

            ctx.SaveChanges();
        }