コード例 #1
0
 public void SaveData(Entities.Recipe data)
 {
     if (data.RecipeID == 0)
     {
         context.Recipes.Add(data);
     }
     else
     {
         Entities.Recipe dbEntry = context.Recipes.Find(data.RecipeID);
         if (dbEntry != null)
         {
             dbEntry.Name = data.Name;
             dbEntry.ProcessDescription = data.ProcessDescription;
         }
     }
     context.SaveChanges();
 }
コード例 #2
0
ファイル: UserRepository.cs プロジェクト: BDM30/Fridge
 public void SaveData(User data)
 {
     if (data.UserID == 0)
     {
         context.Users.Add(data);
     }
     else
     {
         User dbEntry = context.Users.Find(data.UserID);
         if (dbEntry != null)
         {
             dbEntry.Name     = data.Name;
             dbEntry.Password = data.Password;
         }
     }
     context.SaveChanges();
 }
コード例 #3
0
 public void SaveData(Entities.Ingredient data)
 {
     if (data.IngredientID == 0)
     {
         context.Ingredients.Add(data);
     }
     else
     {
         Entities.Ingredient dbEntry = context.Ingredients.Find(data.IngredientID);
         if (dbEntry != null)
         {
             dbEntry.CategoryID        = data.CategoryID;
             dbEntry.Amount            = data.Amount;
             dbEntry.ImportanceLevelID = data.ImportanceLevelID;
             dbEntry.RecipeID          = data.RecipeID;
         }
     }
     context.SaveChanges();
 }
コード例 #4
0
 public void SaveData(Entities.Product data)
 {
     if (data.ProductID == 0)
     {
         context.Products.Add(data);
     }
     else
     {
         Entities.Product dbEntry = context.Products.Find(data.ProductID);
         if (dbEntry != null)
         {
             dbEntry.Name          = data.Name;
             dbEntry.AmountDefault = data.AmountDefault;
             dbEntry.Barcode       = data.Barcode;
             dbEntry.UnitMeasureID = data.UnitMeasureID;
             dbEntry.CategoryID    = data.CategoryID;
         }
     }
     context.SaveChanges();
 }
コード例 #5
0
 static void Main(string[] args)
 {
     //addShelfToFridge();
     using (var context = new FridgeContext())
     {
         var newItem = new FridgeItem();
         addItemToFridge(newItem);
         context.FridgeItem.Add(newItem);
         context.SaveChanges();
         Console.WriteLine("Item added to the fridge!");
     }
 }//end of main
コード例 #6
0
 public void SaveData(UserProduct data)
 {
     if (data.UserProductID == 0)
     {
         context.UserProducts.Add(data);
     }
     else
     {
         UserProduct dbEntry = context.UserProducts.Find(data.UserProductID);
         if (dbEntry != null)
         {
             dbEntry.Name           = data.Name;
             dbEntry.UnitMeasureID  = data.UnitMeasureID;
             dbEntry.CategoryID     = data.CategoryID;
             dbEntry.Amount         = data.Amount;
             dbEntry.ExpirationDate = data.ExpirationDate;
             dbEntry.UserID         = data.UserID;
             dbEntry.FridgeID       = data.FridgeID;
             dbEntry.ProductID      = data.ProductID;
             dbEntry.AmountDefault  = data.AmountDefault;
         }
     }
     context.SaveChanges();
 }
コード例 #7
0
        static void Main(string[] args)
        {
            FridgeContext context = new FridgeContext();

            var salt = new Ingredient
            {
                Name        = "Salt",
                Description = "Salty lead of the four flavors of the Alickmylips"
            };

            context.Ingredients.Add(salt);

            var pepper = new Ingredient
            {
                Name        = "Pepper",
                Description = "Spicy."
            };

            context.Add(pepper);

            context.SaveChanges();
        }