public ActionResult FileUpload(HttpPostedFileBase file, Recipe recipe) { if (file != null) { string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/images/profile"), pic); //file is uploaded file.SaveAs(path); // save the image path path to the database or you can send image // directly to database // in-case if you want to store byte[] ie. for DB using (MemoryStream ms = new MemoryStream()) { file.InputStream.CopyTo(ms); //here we create a byte array from our photo byte[] myImage = ms.GetBuffer(); RecipeImage image = new RecipeImage(); image.RecipeID = recipe.RecipeID; image.imagedata = myImage; db.Image.Add(image); //save changes db.SaveChanges(); } } // after successfully uploading redirect the user //to add ingredients //recipe.RecipeID; return RedirectToAction("AddIngredients", recipe); }
public ActionResult Search(Recipe rcp) { var recipes = from r in db.Recipe select r; //TODO add logic to search by main ingredient if (rcp.MainIngredient != null) { recipes = db.Recipe.Where(s => s.MainIngredient.Contains(rcp.MainIngredient)); //create a list of recipes and pass to displayresults List<Recipe> recipeList = new List<Recipe>(); recipeList = recipes.ToList(); //Recipe rec = new Recipe(); //rec.MainIngredient = "cheese"; //recipeList.Add(rec); return View("DisplayResults", recipeList); } return View("Index"); }
public ActionResult FileUpload(Recipe recipe) { return View(recipe); }