public async Task <IActionResult> OnPostAsync() { if (Recipe.RecipeId == null) { Recipe.RecipeId = Guid.NewGuid(); } Recipe.UpdateDateTime = DateTime.UtcNow; if (!ModelState.IsValid) { return(Page()); } if (RecipesExists(Recipe.RecipeId)) { _context.Attach(Recipe).State = EntityState.Modified; } else { _context.Recipes.Add(Recipe); } foreach (RecipeFood rf in _context.RecipeFood.Where(r => r.RecipeId == Recipe.RecipeId).ToList()) { RecipeFood RF2 = RecipeFoods.Where(f => f.FoodId == rf.FoodId && f.RecipeId == rf.RecipeId && f.Grams != rf.Grams).FirstOrDefault(); if (RF2 != null) { rf.Grams = RF2.Grams; _context.Attach(rf).State = EntityState.Modified; } } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecipesExists(Recipe.RecipeId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(AspNetUsers).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AspNetUsersExists(AspNetUsers.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }