public ActionResult Creation() { RecetteModel model = new RecetteModel(); model.DifficulteList = new SelectList(BM.Recette.GetDifficulteList(), "Id", "Value"); model.CategorieList = new SelectList(BM.Recette.GetCategorieList(), "Id", "Value"); return View(model); }
public ActionResult Creation(RecetteModel model) { model.DifficulteList = new SelectList(BM.Recette.GetDifficulteList(), "Id", "Value"); model.CategorieList = new SelectList(BM.Recette.GetCategorieList(), "Id", "Value"); if (!ModelState.IsValid) return View(model); DBO.User user = BM.User.GetUserByName(User.Identity.Name); DBO.Recette recette = new DBO.Recette() { Nom = model.Nom, idCreateur = user.Id, Categorie = BM.Recette.GetCategorieList().ElementAt(model.CategorieSelected - 1).Value, Difficulte = BM.Recette.GetDifficulteList().ElementAt(model.DifficulteSelected - 1).Value, Intro = model.Intro, Photo = model.Photo, Realisation = model.Realisation, TempsRepos = model.TempsRepos == null ? -1 : model.TempsRepos.Value, TempsCuisson = model.TempsCuisson == null ? -1 : model.TempsCuisson.Value, TempsPreparation = model.TempsPreparation }; string result = BM.Recette.NewRecette(recette); if (result == string.Empty) { recette = BM.Recette.GetRecetteByNom(model.Nom); string[] ingredients = model.Ingredients.Split(','); foreach (string ingredient in ingredients) { DBO.Ingredient ing = new DBO.Ingredient(); ing.Nom = ingredient; ing.idRecette = recette.Id; BM.Ingredient.NewIngredient(ing); } return RedirectToAction("Fiche", "Recette", new { id = recette.Id }); } ModelState.AddModelError("", result); return View(model); }