public new async Task <IActionResult> Create(IFormCollection files)
        {
            Recipe recipe = new Recipe();


            if (ModelState.IsValid)
            {
                String wwwroot       = @"C:\Users\Seba\Desktop\PSSC_Unpublished-master\MVC_CookBook_PSSC\MVC_CookBook_PSSC\wwwroot\";
                var    userConnected = new User()
                {
                    strPassword = "******", strUsername = "******", strEmail = "*****@*****.**", strMoney = 0, strName = "name", strSurename = "surename", strPremium = false, strIsLogged = false, strIpAddress = ":::1", strCNP = "1234567890123", strCookie = "cookie", strIBAN = "ibanuuu"
                };

                string recipeName = files["strRecipeName"];



                if (await recipe.CreateValueObjectRecipeAsync(files, userConnected, wwwroot) == 0)
                {
                    ViewBag.ErrorCode = 2;
                    return(View("ErrorPage"));
                }
                else
                {
                    recipe.CreateDatabaseObject();
                }



                await _recipeRepository.CreateAsync(recipe);

                return(View("CreationSuccess"));
            }
            return(View(recipe));
        }
Exemple #2
0
        public async Task <IActionResult> CreateAsync([FromBody] RecipeCreateDto dto)
        {
            var recipe = new Recipe(dto.Title, dto.Description, dto.Instructions);

            var id = await _recipeRepository.CreateAsync(recipe);

            return(Created($"v1/recipe/{id}", null));
        }
        public async Task <IActionResult> Create(IFormCollection files)
        {
            Recipe recipe = new Recipe();


            if (ModelState.IsValid)
            {
                String wwwroot       = @"C:\Users\Seba\Desktop\PSSC_Unpublished-master\MVC_CookBook_PSSC\MVC_CookBook_PSSC\wwwroot\";
                var    userConnected = await _userRepository.GetUsersAsDbSet().FirstOrDefaultAsync(u => u.strUsername == "Usernam");

                ViewBag.CrtUser = userConnected;
                string recipeName = files["strRecipeName"];

                var rec = await _recipeRepository.GetRecipesAsDbSet().FirstOrDefaultAsync(u => u.strRecipeName == recipeName && u.strCreatorUsername == userConnected.strUsername);

                if (rec != null)
                {
                    ViewBag.ErrorCode = 1;
                    return(View("ErrorPage"));
                }


                if (await recipe.CreateValueObjectRecipeAsync(files, userConnected, wwwroot) == 0)
                {
                    ViewBag.ErrorCode = 2;
                    return(View("ErrorPage"));
                }
                else
                {
                    recipe.CreateDatabaseObject();
                }


                ViewBag.CrtUser = userConnected;

                await _recipeRepository.CreateAsync(recipe);

                var getRecipe = await _recipeRepository.GetRecipesAsDbSet().FirstOrDefaultAsync(m => m.strRecipeName == recipe.strRecipeName);

                ViewBag.rec = getRecipe;
                return(View("CreationSuccess"));
            }
            return(View(recipe));
        }
Exemple #4
0
 public async Task <IActionResult> Post([FromBody] Recipe recipe)
 {
     return((await _recipeRepository.CreateAsync(recipe)).ToActionResult());
 }
Exemple #5
0
 /// <inheritdoc />
 public async Task <long> CreateEmptyAsync()
 {
     return(await _repo.CreateAsync(new Recipe()));
 }
Exemple #6
0
        public async Task <IActionResult> CreateRecipe(Recipe recipe)
        {
            await _repository.CreateAsync(recipe);

            return(CreatedAtAction("GetRecipes", new { id = recipe.Id }, recipe));
        }