コード例 #1
0
        public async Task <ActionResult <IngredientDto> > AddUsersRecipeAsync(int userId, UsersRecipeForCreation usersRecipeForCreation)
        {
            var user = await _users.GetAsync(userId);

            if (user == null)
            {
                return(NotFound());
            }

            var recipe = await _recipes.GetAsync(usersRecipeForCreation.RecipeId);

            if (recipe == null)
            {
                return(NotFound());
            }

            var usersRecipeToAdd = _mapper.Map <UsersRecipe>(usersRecipeForCreation);

            usersRecipeToAdd.UserId = userId;

            await _usersRecipes.AddAsync(usersRecipeToAdd);

            await _usersRecipes.SaveAsync();


            return(CreatedAtRoute(
                       "GetUsersRecipe",
                       new { usersRecipeToAdd.UserId, usersRecipeToAdd.RecipeId },
                       recipe));
        }
コード例 #2
0
 public async Task AddAsync(UsersRecipe entity)
 {
     await _dal.AddAsync(entity);
 }