public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(Movie.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Movie.Add(Movie); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Movie = await _context.Movie.FindAsync(id); if (Movie != null) { _context.Movie.Remove(Movie); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <bool> SaveChangesAsync() { return((await _context.SaveChangesAsync()) > 0); }
public async Task EnsureSeedData() { if (await _userManager.FindByEmailAsync("*****@*****.**") == null) { var NewUser = new WebAppUser() { UserName = "******", Email = "*****@*****.**" }; await _userManager.CreateAsync(NewUser, "P@ssw0rd!"); } if (await _userManager.FindByEmailAsync("*****@*****.**") == null) { var NewUser = new WebAppUser() { UserName = "******", Email = "*****@*****.**" }; await _userManager.CreateAsync(NewUser, "P@qqw3rd!"); } if (!_context.Polls.Any()) { Poll poll1 = new Poll() { DateCreated = DateTime.Now, NumOfOptions = 2, Question = "What should I name my cat?", SumVotes = 1, UserName = "******", Options = new List <Option>() { new Option() { Text = "Micko", Order = 0, Votes = 1 }, new Option() { Text = "Maroje", Order = 1, Votes = 0 } }, History = new List <HistoryPoll>() { new HistoryPoll() { Username = "******" } } }; _context.Polls.Add(poll1); _context.Options.AddRange(poll1.Options); _context.HistoryPolls.AddRange(poll1.History); Poll poll2 = new Poll() { DateCreated = DateTime.Now, NumOfOptions = 3, Question = "Koju marku TV-a odabrati?", SumVotes = 1, UserName = "******", Options = new List <Option>() { new Option() { Text = "Philips", Order = 0, Votes = 0 }, new Option() { Text = "Samsung", Order = 1, Votes = 1 }, new Option() { Text = "LG", Order = 2, Votes = 0 } }, History = new List <HistoryPoll>() { new HistoryPoll() { Username = "******" } } }; _context.Polls.Add(poll2); _context.Options.AddRange(poll2.Options); _context.HistoryPolls.AddRange(poll1.History); } /* * if(!_context.Decisions.Any()) * { * Decision dec1 = new Decision() * { * DateCreated = DateTime.Now, * Text = "Plava ili zelena kravata?", * FirstText = "Bijela", * FirstSumVotes = 0, * SecondText = "Zelena", * SecondSumVotes = 0, * ImageUrl = String.Empty, * UserName = "******" * }; * * _context.Decisions.Add(dec1); * } */ await _context.SaveChangesAsync(); }