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)); }
public IActionResult OnPost() { if (ModelState.IsValid) { recipe.UserId = user.id; _service.Add(recipe); return(Redirect(Url.Page("/Index", new { login = user.Login }))); } return(Page()); }
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); }
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)); } }
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)); }
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)); }
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)); }
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()); } }
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)); }
public async Task <IActionResult> Add([FromBody] UpsertRecipeModel model) { var result = await _recipeService.Add(model); return(Ok(result)); }