Пример #1
0
        public void SaveMeal(AllMeals allMeals)
        {
            var first  = dBContext.FirstDishes.FirstOrDefault(x => x.Id == allMeals.Id && x.Name == allMeals.Name);
            var second = dBContext.SecondDishes.FirstOrDefault(x => x.Id == allMeals.Id && x.Name == allMeals.Name);
            var salad  = dBContext.Salads.FirstOrDefault(x => x.Id == allMeals.Id && x.Name == allMeals.Name);

            if (first != null)
            {
                first.Name        = allMeals.Name;
                first.Price       = allMeals.Price;
                first.Description = allMeals.Description;
                dBContext.SaveChanges();
            }
            if (second != null)
            {
                second.Description = allMeals.Description;
                second.Name        = allMeals.Name;
                second.Price       = allMeals.Price;
                dBContext.SaveChanges();
            }
            if (salad != null)
            {
                salad.Description = allMeals.Description;
                salad.Name        = allMeals.Name;
                salad.Price       = allMeals.Price;
                dBContext.SaveChanges();
            }
        }
Пример #2
0
 public void CreateMeal(AllMeals allMeals)
 {
     if (allMeals != null)
     {
         if (allMeals.MealType == "firstDish")
         {
             dBContext.FirstDishes.Add(new Models.FirstDishes
             {
                 Description  = allMeals.Description,
                 Name         = allMeals.Name,
                 PhotoName    = "",
                 CreatingDate = DateTime.Now,
                 Price        = allMeals.Price
             });
         }
         if (allMeals.MealType == "secondDish")
         {
             dBContext.SecondDishes.Add(new Models.SecondDishes
             {
                 Description  = allMeals.Description,
                 Name         = allMeals.Name,
                 PhotoName    = "",
                 CreatingDate = DateTime.Now,
                 Price        = allMeals.Price
             });
         }
         if (allMeals.MealType == "salad")
         {
             dBContext.Salads.Add(new Models.Salads
             {
                 Description  = allMeals.Description,
                 Name         = allMeals.Name,
                 PhotoName    = "",
                 CreatingDate = DateTime.Now,
                 Price        = allMeals.Price
             });
         }
     }
 }