public async Task <IActionResult> AddTable(AddTableViewModel tableViewModel) { var user = await _userManager.FindByIdAsync(HttpContext.User.GetUserId()); //ApplicationUser applicationUser = await _context.ApplicationUsers.FirstOrDefaultAsync(w => w.Id == user.Id); //Restaurant restaurantData = await _context.Restaurants.FirstOrDefaultAsync(w => w.ApplicationUser.Id == user.Id); if (user.AccountType == "Restaurant") { Restaurant restaurant = _applicationService.GetRestaurantByUserId(user.Id); if (ModelState.IsValid) { RestaurantTable table = new RestaurantTable() { RestaurantTableSeats = tableViewModel.TableSeats }; //_context.RestaurantTables.Add(table); _applicationService.AddTableByRestaurantId(table, restaurant.Id); if (restaurant == null) { user.RestaurantData = new Restaurant(); } if (restaurant.RestaurantTables == null) { user.RestaurantData.RestaurantTables = new List <RestaurantTable>(); } restaurant.RestaurantTables.Add(table); //_context.SaveChanges(); return(RedirectToAction("Index")); } } return(View(tableViewModel)); }