public async Task <IActionResult> AddImage(RestaurantImageViewModel model) { if (ModelState.IsValid) { var path = string.Empty; if (model.ImageFile != null) { path = await _imageHerlper.UploadImageAsync(model.ImageFile); } var restauranImage = new RestaurantImage { ImageUrl = path, Restaurant = await _dataContext.Restaurants.FindAsync(model.Id) }; _dataContext.RestaurantImages.Add(restauranImage); await _dataContext.SaveChangesAsync(); return(RedirectToAction($"{nameof(DetailsRestaurant)}/{model.Id}")); } return(View(model)); }
public async Task <IActionResult> AddImage(int?id) { if (id == null) { return(NotFound()); } var restaurant = await _dataContext.Restaurants.FindAsync(id.Value); if (restaurant == null) { return(NotFound()); } var model = new RestaurantImageViewModel { Id = restaurant.Id }; return(View(model)); }