Пример #1
0
 public Item(int unit, Iingridient ingridient)
 {
     Unit            = unit;
     this.ingridient = ingridient as Ingridient;
 }
Пример #2
0
        /// <summary>
        /// Adds ingredients if there is not one in the database.
        /// </summary>
        /// <param name="ingridient"></param>
        public void AddIndgredients(Iingridient ingridient = null)
        {
            if (ingridient == null)
            {
                using (CockTailsContext context = new CockTailsContext(@"Cocktails"))
                {
                    List <Liquid> liquids = new List <Liquid> {
                        new Liquid("green", false, "lime jucie"),
                        new Liquid("white", false, "triplesec"),
                        new Liquid("yellow", true, "tequila")
                    };
                    foreach (var item in liquids)
                    {
                        if (!context.liquidContext.Any(e => e.Name == item.Name))
                        {
                            Console.WriteLine("Added " + item.Name);
                            context.liquidContext.AddOrUpdate(item);
                        }
                    }


                    List <Accessory> accessories = new List <Accessory> {
                        new Accessory("rim", "salt"),
                        new Accessory("crushed", "ice"),
                        new Accessory("segment", "lime")
                    };
                    foreach (var item in accessories)
                    {
                        if (!context.accessoriesContext.Any(e => e.Name == item.Name))
                        {
                            Console.WriteLine("Added " + item.Name);
                            context.accessoriesContext.AddOrUpdate(item);
                        }
                    }
                    context.SaveChanges();
                }
            }
            else
            {
                using (CockTailsContext context = new CockTailsContext(@"Cocktails"))
                {
                    switch (ingridient)
                    {
                    case Liquid l:
                        var temp = ingridient as Liquid;
                        if (!context.liquidContext.Any(e => e.Name == temp.Name))
                        {
                            context.liquidContext.AddOrUpdate(temp);
                        }
                        break;

                    case Accessory a:
                        var tempA = ingridient as Accessory;
                        if (!context.accessoriesContext.Any(e => e.Name == tempA.Name))
                        {
                            context.accessoriesContext.AddOrUpdate(tempA);
                        }
                        break;

                    default:
                        break;
                    }
                    context.SaveChanges();
                }
            }
        }