public async Task <IActionResult> Create([Bind("ID,Description")] CookingMethod cookingMethod) { if (ModelState.IsValid) { _context.Add(cookingMethod); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(cookingMethod)); }
public ActionResult Create([Bind(Include = "CookingMethodId,CookingMethodName,Description,Difficulty")] CookingMethod cookingMethod) { if (ModelState.IsValid) { _db.CookingMethods.Add(cookingMethod); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cookingMethod)); }
public async Task <IActionResult> Edit(int id, EditMealViewModel editMealViewModel) { if (id != editMealViewModel.mealID) { return(NotFound()); } if (ModelState.IsValid) { try { WeatherType newWeatherType = _context.WeatherTypes.Single(w => w.ID == editMealViewModel.WeatherTypeID); CookingMethod newCookingMethod = _context.CookingMethods.Single(m => m.ID == editMealViewModel.CookingMethodID); CookingMethod newAltCookingMethod = _context.CookingMethods.Single(a => a.ID == editMealViewModel.AltCookingMethodID); CookingTime newCookingTime = _context.CookingTimes.Single(t => t.ID == editMealViewModel.CookingTimeID); PrepTime newPrepTime = _context.PrepTimes.Single(p => p.ID == editMealViewModel.PrepTimeID); //Add the new default meal to the default meal table Meal editMeal = new Meal { ID = editMealViewModel.mealID, Name = editMealViewModel.Name, Description = editMealViewModel.Description, Location = editMealViewModel.Location, UserID = editMealViewModel.UserID, WeatherType = newWeatherType, CookingMethod = newCookingMethod, AltCookingMethod = newAltCookingMethod, CookingTime = newCookingTime, PrepTime = newPrepTime }; _context.Update(editMeal); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MealExists((editMealViewModel.mealID))) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(editMealViewModel)); }
// GET: CookingMethods/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CookingMethod cookingMethod = _db.CookingMethods.Find(id); if (cookingMethod == null) { return(HttpNotFound()); } return(View(cookingMethod)); }
public async Task CreateAsync(string name, IFormFile image) { var imageUrl = await this.cloudinaryService .UploadAsync(image, image.FileName, CloudinaryFolderName); var cookingMethod = new CookingMethod { Name = name, ImageUrl = imageUrl, }; await this.cookingMethodsRepository.AddAsync(cookingMethod); await this.cookingMethodsRepository.SaveChangesAsync(); }
public bool CreateCookingMethod(CookingMethodCreate model) { var entity = new CookingMethod() { CookingMethodName = model.CookingMethodName, Description = model.Description, Difficulty = model.Difficulty }; using (var ctx = new ApplicationDbContext()) { ctx.CookingMethods.Add(entity); return(ctx.SaveChanges() == 1); } }
public static void Execute() { CookingMethod cookMethod = new CookingMethod(); Console.WriteLine("What food would you like to cook?\n"); var food = Console.ReadLine(); cookMethod.SetFood(food); Console.WriteLine("\nWhat cooking strategy would you like to use?\n"); Console.WriteLine("1 - Grilling"); Console.WriteLine("2 - Oven baking"); Console.WriteLine("3 - Deep frying"); int input = int.Parse(Console.ReadKey().KeyChar.ToString()); switch (input) { case 1: cookMethod.SetCookStrategy(new Grilling()); cookMethod.Cook(); break; case 2: cookMethod.SetCookStrategy(new OvenBaking()); cookMethod.Cook(); break; case 3: cookMethod.SetCookStrategy(new DeepFrying()); cookMethod.Cook(); break; default: Console.WriteLine("Invalid Selection!"); Execute(); break; } Console.ReadKey(); }
private static void StartCookingWithStrategy(CookingMethod cookMethod, CookStrategy cookStrategy) { cookMethod.SetCookStrategy(cookStrategy); cookMethod.Cook(); }