public async Task <int> Add(Student student) { await _contosoDbContext.Students.AddAsync(student); await _contosoDbContext.SaveChangesAsync(); return(student.StudentId); }
public async Task <IActionResult> Create([Bind("Id,Nome,Sobrenome,DataMatricula")] Aluno aluno) { if (ModelState.IsValid) { _context.Add(aluno); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(aluno)); }
public async Task <IActionResult> Delete(int id) { var person = await _context.People.FindAsync(id); if (person == null) { return(new NotFoundObjectResult($"Person with Id {id} not found.")); } _context.People.Remove(person); var result = await _context.SaveChangesAsync(); var statusCode = result > 0 ? 200 : 500; return(await Task.FromResult(new StatusCodeResult(statusCode))); }