public async Task <IActionResult> Edit(int id, [Bind("FoodSuggestionId,FoodSuggestionName")] FoodSuggestion foodSuggestion) { if (id != foodSuggestion.FoodSuggestionId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(foodSuggestion); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FoodSuggestionExists(foodSuggestion.FoodSuggestionId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(foodSuggestion)); }
public async Task <IActionResult> Create([Bind("FoodSuggestionId,FoodSuggestionName")] FoodSuggestion model) { if (ModelState.IsValid) { if (FoodSuggestionExists(model.FoodSuggestionName)) { ModelState.AddModelError("", "Der eksister allerrede en ret med det navn"); return(View(model)); } _context.Add(model); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public ActionResult AcceptFoodSuggestion(string restaurantId, string name, string url, string address, string locality, string city, string state, string latitude, string longitude, string zipcode, string country_id, string cuisines, string average_cost_for_two, string price_range) { GetRestaurantViewModel getRestaurantModel = new GetRestaurantViewModel(); int restaurantIdNumber; var result = Int32.TryParse(restaurantId, out restaurantIdNumber); FoodSuggestion foodSuggestionToRecord = new FoodSuggestion { RestaurantId = restaurantIdNumber, Name = name, Address = address, City = city, ZipCode = zipcode, Latitude = latitude, Longitude = longitude, IsChosenByUser = true }; db.FoodSuggestions.Add(foodSuggestionToRecord); db.SaveChanges(); Location location = new Location { Address = address, Locality = locality, City = city, State = state, Latitude = latitude, Longitude = longitude, Zipcode = zipcode, Country_Id = country_id }; Restaurant chosenRestaurant = new Restaurant { Id = restaurantId, Name = name, Url = url, Address = address, Locality = locality, City = city, State = state, Latitude = latitude, Longitude = longitude, Zipcode = zipcode, Country_Id = country_id, Cuisines = cuisines, Average_Cost_For_Two = average_cost_for_two, Price_Range = price_range }; getRestaurantModel.Restaurant = chosenRestaurant; return(View("GetRestaurant", getRestaurantModel)); }