Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public ActionResult RemoveRecipe()
        {
            RecipeDal recipeDal = new RecipeDal();

            recipeDal.DeleteRecipe(Int32.Parse(Request.Params["id"]));
            return(RedirectToAction("DeleteRecipe"));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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"));
        }
Exemplo n.º 6
0
        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"));
        }
Exemplo n.º 7
0
        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);
        }