public IHttpActionResult PutRecipe(long id, RecipeDal.Recipe recipe) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != recipe.RecipeId) { return BadRequest(); } db.Entry(recipe).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RecipeExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public string FilterRecipesByType() { string type = Request.Params["type"]; RecipeDal recipeDal = new RecipeDal(); List <Recipe> recipes = recipeDal.GetAllRecipesByType(type); ViewData["recipes"] = recipes; string result = "<table><thead><th>ID</th><th>Author</th><th>Name</th><th>Type</th><th>Description</th></thead>"; foreach (Recipe recipe in recipes) { result += "<tr>" + "<td>" + recipe.Id + "</td>" + "<td>" + recipe.Author + "</td>" + "<td>" + recipe.Name + "</td>" + "<td>" + recipe.Type + "</td>" + "<td>" + recipe.Description + "</td>" + "</tr>"; } result += "</table>"; return(result); }
public ActionResult RemoveRecipe() { RecipeDal recipeDal = new RecipeDal(); recipeDal.DeleteRecipe(Int32.Parse(Request.Params["id"])); return(RedirectToAction("DeleteRecipe")); }
public IHttpActionResult PostRecipe(RecipeDal.Recipe recipe) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Recipes.Add(recipe); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = recipe.RecipeId }, recipe); }
public ActionResult SaveRecipe() { Recipe recipe = new Recipe(); recipe.Author = Request.Params["author"]; recipe.Name = Request.Params["name"]; recipe.Type = Request.Params["type"]; recipe.Description = Request.Params["description"]; RecipeDal recipeDal = new RecipeDal(); recipeDal.SaveRecipe(recipe); return(RedirectToAction("AddRecipe")); }
public ActionResult ChangeRecipe() { Recipe recipe = new Recipe(); recipe.Id = Int32.Parse(Request.Params["id"]); recipe.Author = Request.Params["author"]; recipe.Name = Request.Params["name"]; recipe.Type = Request.Params["type"]; recipe.Description = Request.Params["description"]; RecipeDal recipeDal = new RecipeDal(); recipeDal.UpdateRecipe(recipe); return(RedirectToAction("UpdateRecipe")); }
public string GetRecipes() { RecipeDal recipeDal = new RecipeDal(); List <Recipe> recipes = recipeDal.GetAllRecipes(); ViewData["recipes"] = recipes; string result = "<table><thead><th>ID</th><th>Author</th><th>Name</th><th>Type</th><th>Description</th></thead>"; foreach (Recipe recipe in recipes) { result += "<tr>" + "<td>" + recipe.Id + "</td>" + "<td>" + recipe.Author + "</td>" + "<td>" + recipe.Name + "</td>" + "<td>" + recipe.Type + "</td>" + "<td>" + recipe.Description + "</td>" + "</tr>"; } result += "</table>"; return(result); }