コード例 #1
0
        public static void AddShelf(string name)
        {
            using (ShelvesContext context = new ShelvesContext())
            {
                if (context.Shelves.Where(x => x.Name.ToUpper() == name.Trim().ToUpper()).Count() != 0)
                {
                    throw new Exception("That shelf already exists.");
                }


                //  context.Shelves.Add(new Shelves() { Name = name.Trim() });


                // context.Add(context.ShelfMaterials.Include(b => b.ID));

                var s1 = context.ShelfMaterials.Include(b => b.Shelves).First();
                var s2 = new Shelves {
                    Name = name.Trim()
                };

                s1.Shelves.Add(s2);

                context.SaveChanges();
            }
        }
コード例 #2
0
 public static void AddMaterial(string shelfMaterial)
 {
     using (ShelvesContext context = new ShelvesContext())
     {
         string materialName = shelfMaterial;
         if (context.ShelfMaterials.Where(x => x.MaterialName == materialName.Trim()).Count() != 0)
         {
             throw new Exception("That material already exists.");
         }
         context.ShelfMaterials.Add(new ShelfMaterials {
             MaterialName = materialName.Trim()
         });
         context.SaveChanges();
         Console.WriteLine($"Self MaterialName is {materialName}");
     }
 }