public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(list).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!listExists(list.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { string NewSchool_Name = list.name.ToLower(); string NewSchool_Address = list.address.ToLower(); var Check_Name = await _context.list.Where(m => m.name.ToLower() == NewSchool_Name.ToLower()).ToListAsync(); var Check_Address = await _context.list.Where(m => m.address.ToLower() == NewSchool_Address.ToLower()).ToListAsync(); if (Check_Name.Count > 0 && Check_Address.Count > 0) { if (Check_Name[0].name.ToLower().ToString() == NewSchool_Name && Check_Address[0].address.ToLower().ToString() == NewSchool_Address) { return(BadRequest(new { ErrorMessage = "This school is already registered" })); } } if (!ModelState.IsValid) { return(Page()); } _context.list.Add(list); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(long?id) { if (id == null) { return(NotFound()); } list = await _context.list.FindAsync(id); if (list != null) { _context.list.Remove(list); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }