Exemplo n.º 1
0
        internal async Task <int> CreateAndSaveRecipe(RecipesCreateViewModel viewModel, string userId)
        {
            HttpPostedFileBase file = viewModel.UploadedFile;

            if (UploadedFileExists(file))
            {
                if (IsImage(file))
                {
                    viewModel.ImageReference = new ImageHandler().SaveInitialImageAndGetReference(viewModel.UploadedFile);
                }
            }
            CookBook selectedCookBook = new CookBookRetriever()
                                        .GetUserCookBookByName(userId, viewModel.CookBookName);
            Recipe recipe = new Recipe(viewModel, userId, selectedCookBook);

            repository.AttachCookBookAndAddRecipe(selectedCookBook, recipe);
            return(await repository.SaveChangesAsync());
        }