public static void Initialize(MiddleServiceContext context) { context.Database.EnsureCreated(); // Look for any existing records. if (context.MiddleRecord.Any()) { return; // DB has been seeded } var startRecords = new MiddleRecord[] { new MiddleRecord { Value = 2001 }, new MiddleRecord { Value = 2002 }, new MiddleRecord { Value = 2003 }, new MiddleRecord { Value = 2004 }, new MiddleRecord { Value = 2005 } }; foreach (MiddleRecord s in startRecords) { context.MiddleRecord.Add(s); } context.SaveChanges(); }
public async Task <IActionResult> PutMiddleRecord([FromRoute] int id, [FromBody] MiddleRecord middleRecord) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != middleRecord.ID) { return(BadRequest()); } _context.Entry(middleRecord).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MiddleRecordExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostMiddleRecord([FromBody] MiddleRecord middleRecord) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.MiddleRecord.Add(middleRecord); await _context.SaveChangesAsync(); return(CreatedAtAction("GetMiddleRecord", new { id = middleRecord.ID }, middleRecord)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } MiddleRecord = await _context.MiddleRecord.FirstOrDefaultAsync(m => m.ID == id); if (MiddleRecord == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } MiddleRecord = await _context.MiddleRecord.FindAsync(id); if (MiddleRecord != null) { _context.MiddleRecord.Remove(MiddleRecord); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }