예제 #1
0
 public List <RecipeSimplifiedDto> GetRecipeList()
 {
     using (var db = new cookbookdbEntities())
     {
         List <RecipeSimplifiedDto> list = mapper.Map <List <RecipeSimplifiedDto> >(db.Recipes);
         return(list);
     }
 }
예제 #2
0
 public List <IngredientDto> GetShopList(string userId)
 {
     using (var db = new cookbookdbEntities())
     {
         List <IngredientDto> list =
             mapper.Map <List <IngredientDto> >(db.ShopListItems.Where(x => x.userId == userId));
         return(list);
     }
 }
예제 #3
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();
     }
 }
예제 #4
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();
            }
        }
예제 #5
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();
         }
     }
 }
예제 #6
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();
            }
        }
예제 #7
0
        public RecipeDto GetRecipe(int id)
        {
            using (var db = new cookbookdbEntities())
            {
                var query = from r in db.Recipes
                            where r.idRecipe == id
                            select r;

                RecipeDto recipe = mapper.Map <RecipeDto>(query.FirstOrDefault());

                if (recipe != null)
                {
                    var query2 = from r in db.Preparations
                                 where r.idRecipe == id
                                 select r;

                    recipe.PreparationDescription = query2.FirstOrDefault()?.description;
                }

                return(recipe);
            }
        }