Пример #1
0
 public void AddShopListItem(string userId, IngredientDto ingredient)
 {
     using (var db = new cookbookdbEntities())
     {
         ShopListItem entity = mapper.Map <ShopListItem>(ingredient);
         var          user   = db.AspNetUsers.Where(x => x.Id == userId).FirstOrDefault();
         entity.AspNetUser = user;
         db.ShopListItems.Add(entity);
         db.SaveChanges();
     }
 }
Пример #2
0
        public void DeleteRecipe(string name)
        {
            using (var db = new cookbookdbEntities())
            {
                foreach (Recipe r in db.Recipes.Where(r => r.name == name))
                {
                    db.Recipes.Remove(r);
                }

                db.SaveChanges();
            }
        }
Пример #3
0
 public void DeleteShopListItem(string userId, string ingredientName)
 {
     using (var db = new cookbookdbEntities())
     {
         var toDelete = db.ShopListItems.Where(x => x.ingredientName == ingredientName && x.userId == userId)
                        .FirstOrDefault();
         if (toDelete != null)
         {
             db.Entry(toDelete).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
         }
     }
 }
Пример #4
0
        public void AddRecipe(RecipeDto recipe)
        {
            using (var db = new cookbookdbEntities())
            {
                Recipe            recipeEntity       = mapper.Map <Recipe>(recipe);
                Preparation       preparationEntity  = mapper.Map <Preparation>(recipe);
                List <Ingredient> ingredientEntities = mapper.Map <List <Ingredient> >(recipe.Ingredients);

                db.Recipes.Add(recipeEntity);
                db.Preparations.Add(preparationEntity);

                db.SaveChanges();
            }
        }