public ActionResult Create([Bind(Include = "ID,Name,ImageFile,ImagePath,Description,Price")] MealHelper mealHelper) { Meal meal = new Meal(); if (ModelState.IsValid) { string pic = System.IO.Path.GetFileName(mealHelper.ImageFile.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/Images/"), pic); mealHelper.ImageFile.SaveAs(path); meal.ID = mealHelper.ID; meal.Name = mealHelper.Name; meal.ImagePath = "~/Images/" + pic; // university.ImagePath = path; meal.Price = mealHelper.Price; meal.Description = mealHelper.Description; db.Meals.Add(meal); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(meal)); }
public ActionResult CreatePost(IFormCollection arg, MealWithMealTypesViewModel PostMeal) { if (!ModelState.IsValid) { return(RedirectToAction("Create")); } var ingredientNums = PostMeal.PostIngredients; var queryReadyIngredients = ingredientNums.Select(x => int.Parse(x)); var query = from num in queryReadyIngredients join Ingredient in PostMeal.AllIngredientsFromViewModel on num equals Ingredient.Id select new { Id = Ingredient.Id, Name = Ingredient.Name }; var lista = query.ToList(); List <Ingredient> queryIngredients = new List <Ingredient>(); var counter = 0; foreach (var item in lista) { Ingredient i = new Ingredient(lista.Skip(counter).First().Id, lista.Skip(counter).First().Name); queryIngredients.Add(i); counter++; } PostMeal.meal.Ingredients = queryIngredients; PostMeal.meal.MealType = arg["Type"].ToString(); MealHelper.AddMeal(PostMeal.meal); return(RedirectToAction("Index")); }
public ActionResult Details(string mealType) { var viewModel = new MealWithMealTypesViewModel { meals = MealHelper.GetAllMeals().Where(m => m.MealType.Equals(mealType)).ToList() }; return(View("Meals", viewModel)); }
public ActionResult Index() { var viewModel = new MealWithMealTypesViewModel { meals = MealHelper.GetAllMeals(), }; return(View("Meals", viewModel)); }
// GET: Supply/Create public ActionResult Create() { var viewModel = new SupplyListAndSupplyViewModel { Ingredients = MealHelper.GetAllIngredients().Select(i => new SelectListItem { Value = i.Id.ToString(), Text = i.Name }).ToList() }; return(View(viewModel)); }
public ActionResult Delete(string id) { try { MealHelper.DeleteMeal(id); return(RedirectToAction("Index")); } catch { return(Content("Neche moci delitate ovo")); } }
// GET: Supply/Edit/5 public ActionResult Edit(int id) { var viewModel = new SupplyListAndSupplyViewModel { Supply = SupplyHelper.GetAllSupplies().Where(x => x.Id == id).FirstOrDefault(), Ingredients = MealHelper.GetAllIngredients().Select(i => new SelectListItem { Value = i.Id.ToString(), Text = i.Name }).ToList() }; return(View(viewModel)); }
public ActionResult Create() { var viewModel = new MealWithMealTypesViewModel { MealTypes = MealHelper.GetAllMealTypes(), Ingredients = MealHelper.GetAllIngredients().Select(i => new SelectListItem { Value = i.Id.ToString(), Text = i.Name }).ToList(), PostIngredients = new List <string>() }; return(View("CreateMealForm", viewModel)); }
public ActionResult Edit(int editId, SupplyListAndSupplyViewModel PostSupply) { if (!ModelState.IsValid) { return(RedirectToAction("Edit")); } var ingredientNum = int.Parse(PostSupply.PostIngredient); var selectedIngredient = MealHelper.GetAllIngredients().Where(x => x.Id == ingredientNum).FirstOrDefault(); PostSupply.Supply.Ingredient = selectedIngredient; SupplyHelper.UpdateSupply(editId, PostSupply.Supply); return(RedirectToAction("Index")); }
public ActionResult Create(SupplyListAndSupplyViewModel PostSupply) { if (!ModelState.IsValid) { return(RedirectToAction("Create")); } var ingredientNum = int.Parse(PostSupply.PostIngredient); var selectedIngredient = MealHelper.GetAllIngredients().Where(x => x.Id == ingredientNum).FirstOrDefault(); PostSupply.Supply.Ingredient = selectedIngredient; PostSupply.Supply.Id = SupplyHelper.GetSupplyNextId(); SupplyHelper.AddSupply(PostSupply.Supply); return(RedirectToAction("Index")); }