public static bool AddRecipe(string shawarmaName, IngradientWeight[] ingradientWeightAccordings, int cookingTime = 0)
 {
     using (var ctx = new ShawarmaDBEntities())
     {
         Shawarma shawarma = ctx.Shawarmas.FirstOrDefault(sh => sh.ShawarmaName == shawarmaName) ?? new Shawarma
         {
             ShawarmaName = shawarmaName,
             CookingTime  = cookingTime
         };
         ShawarmaRecipe recipe = ctx.ShawarmaRecipes.Create();
         recipe.Shawarma = shawarma;
         foreach (var ingradientWeightAccording in ingradientWeightAccordings)
         {
             Ingradient ingradient =
                 ctx.Ingradients.FirstOrDefault(
                     ing => ing.IngradientName == ingradientWeightAccording.IngradientName);
             if (ingradient == null)
             {
                 AddIngredient(ingradientWeightAccording.IngradientName, 0);
                 ingradient =
                     ctx.Ingradients.FirstOrDefault(
                         ing => ing.IngradientName == ingradientWeightAccording.IngradientName);
             }
             recipe.IngradientId = ingradient.IngradientId;
             recipe.Weight       = ingradientWeightAccording.Weight;
             ctx.ShawarmaRecipes.Add(recipe);
         }
         return(Commit(ctx));
     }
 }
 public static bool AddPrice(string sellingPointTitle, string shawarmaName, decimal newPrice, string comment)
 {
     using (var ctx = new ShawarmaDBEntities())
     {
         SellingPoint point = ctx.SellingPoints.FirstOrDefault(p => p.ShawarmaTitle == sellingPointTitle);
         if (point == null)
         {
             AddSellingPoint(sellingPointTitle, "", "");
             point = ctx.SellingPoints.FirstOrDefault(p => p.ShawarmaTitle == sellingPointTitle);
         }
         Shawarma shawarma = ctx.Shawarmas.FirstOrDefault(sh => sh.ShawarmaName == shawarmaName);
         if (shawarma == null)
         {
             return(false);                  //there is not specified shawarma
         }
         ctx.PriceControllers.Add(new PriceController
         {
             ShwarmaId      = shawarma.ShawarmaId,
             Price          = newPrice,
             SellingPointId = point.SellingPointId,
             Comment        = comment
         });
         return(Commit(ctx));
     }
 }
 public static bool ShawarmaSelling(string shawarmaName)
 {
     using (var ctx = new ShawarmaDBEntities())
     {
         Shawarma shawarma = ctx.Shawarmas.FirstOrDefault(sh => sh.ShawarmaName == shawarmaName);
         if (shawarma == null)
         {
             throw new Exception("there is not specified shawarma");
         }
         foreach (var recipe in ctx.ShawarmaRecipes.Where(sh => sh.ShawarmaId == shawarma.ShawarmaId))
         {
             if (recipe.Ingradient.TotalWeight >= recipe.Weight)
             {
                 recipe.Ingradient.TotalWeight -= recipe.Weight;
             }
             else
             {
                 throw new Exception("not enough ingradient " + recipe.Ingradient.IngradientName);
             }
         }
         return(Commit(ctx));
     }
 }