public RecipeServiceTests()
 {
     this.service = new RecipeService();
     service.Add(new Recipe { Name = "Pie" }
         );
     service.Add(new Recipe { Name = "Cake" }
         );
 }
Example #2
0
 public RecipeServiceTests()
 {
     this.service = new RecipeService();
     service.Add(new Recipe {
         Name = "Pie"
     }
                 );
     service.Add(new Recipe {
         Name = "Cake"
     }
                 );
 }
        public void Create(DetailedRecipeViewModel model)
        {
            model.Time = new TimeSpan(0, model.Minutes, model.Seconds);
            var recipe = _mapper
                         .Map <RecipeDto>(model);

            _service.Add(recipe);
        }
        //delete and update can use httppost
        public IActionResult Add(Recipe recipe)
        {
            var result = _recipeService.Add(recipe);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Example #5
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         recipe.UserId = user.id;
         _service.Add(recipe);
         return(Redirect(Url.Page("/Index", new { login = user.Login })));
     }
     return(Page());
 }
Example #6
0
        public void AddTest()
        {
            var name      = Guid.NewGuid().ToString();
            var NewRecipe = new Recipe
            {
                Name = name
            };
            var AddedRecipe = service.Add(NewRecipe);

            Assert.IsNotNull(AddedRecipe);
            Assert.IsTrue(AddedRecipe.Id > 0);
            Assert.AreEqual(AddedRecipe.Name, name);
        }
Example #7
0
 public IActionResult Add([FromBody] RecipeModel recipeModel)
 {
     //ModelState.AddModelError("AddQuestion", "Not Implemented!");
     //return NotFound(ModelState);
     try
     {
         var savedRecipe = _recipeService.Add(recipeModel.ToDomainModel());
         return(CreatedAtAction("Get", new { Id = savedRecipe.Id }, savedRecipe.ToApiModel()));
     }
     catch (System.Exception ex)
     {
         ModelState.AddModelError("AddRecipe", ex.Message);
         return(BadRequest(ModelState));
     }
 }
Example #8
0
        public IHttpActionResult PostRecipe(RecipeModel recipeModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var recipe = new Recipe();

            ObjectFactory.Parse(recipeModel, recipe);

            _recipeService.Add(recipe);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = recipe.Id }, recipe));
        }
Example #9
0
        public async Task <IActionResult> Create(Recipe recipe, string category, string complexity)
        {
            bool isCreated = false;

            if (ModelState.IsValid)
            {
                isCreated = _recipeService.Add(recipe, category, complexity);
            }

            if (isCreated)
            {
                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
        public IActionResult Add([FromBody] RecipeModel recipeModel)
        {
            try
            {
                // add the new author
                _recipeService.Add(recipeModel.ToDomainModel());
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("AddRecipe", ex.GetBaseException().Message);
                return(BadRequest(ModelState));
            }

            // return a 201 Created status. This will also add a "location" header
            // with the URI of the new author. E.g., /api/authors/99, if the new is 99
            return(CreatedAtAction("Get", new { Id = recipeModel.Id }, recipeModel));
        }
Example #11
0
        public ActionResult Create(
            RecipeViewModel recipe)
        {
            //User.Identity.Name;
            if (ModelState.IsValid)
            {
                var recipeMap = MapViewToEntity(recipe);
                recipeMap.CreatedDate = DateTime.Now;
                _recipeService.Add(recipeMap);
                return(RedirectToAction("Index"));
            }


            ViewBag.CuisineId   = new SelectList(_cuisineService.GetAll(), "CuisineId", "Name", recipe.CuisineId);
            ViewBag.DificultyId = new SelectList(_difficultyService.GetAll(), "DificultyId", "Name", recipe.DificultyId);

            return(View(recipe));
        }
Example #12
0
        public async Task <IActionResult> New(RecipeVM recipeVM)
        {
            try
            {
                Recipe recipeEntity = _recipeMapper.ToModel(recipeVM);
                await _recipeService.Add(recipeEntity);

                if (recipeEntity.Id != Guid.Empty)
                {
                    return(RedirectToAction("List"));
                }
                return(View(recipeVM));
            }
            catch
            {
                return(View());
            }
        }
Example #13
0
        public ActionResult CreateRecipe([FromBody] RecipeRequest recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Model State is Not Valid!!"));
            }

            Category category = _categoryService.GetById(recipe.CategoryId);

            Recipe newRecipe = new Recipe
            {
                RecipeName  = recipe.RecipeName,
                Category    = category,
                Description = recipe.Description,
                CookTime    = recipe.CookTime,
                PrepareTime = recipe.PrepareTime,
                Steps       = recipe.Steps
            };

            _recipeService.Add(newRecipe);

            return(Ok(newRecipe));
        }
Example #14
0
        public async Task <IActionResult> Add([FromBody] UpsertRecipeModel model)
        {
            var result = await _recipeService.Add(model);

            return(Ok(result));
        }