//AanroepenController public class GebruikersController : ODataController { private readonly NoortjeContext Context; public object GebruikerTypedViewRow { get; private set; } public GebruikersController(NoortjeContext context) { Context = context; } [EnableQuery] public IQueryable Get() { return Context.Gebruiker; } //Edit public async Task Patch([FromODataUri] int key, Delta gebruiker) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var entity = await Context.Gebruiker.FindAsync(key); if (entity == null) { return NotFound(); } //Dynamic-Object gebruiker.Patch(entity); try { await Context.SaveChangesAsync(); } catch (Exception) { return NotFound(); } return Updated(entity); } //Delete function. public async Task Delete([FromODataUri] int key) { var Gebruiker = await Context.Gebruiker.FindAsync(key); if (Gebruiker == null) { return NotFound(); } Context.Gebruiker.Remove(Gebruiker); await Context.SaveChangesAsync(); return StatusCode((int)HttpStatusCode.NoContent); } // Gebruiker toevoegen public async Task Post([FromBody]Gebruiker gebruiker) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var Gebruiker = GebruikerTypedViewRow; Context.Gebruiker.Add(gebruiker); await Context.SaveChangesAsync(); return Created(await Context.Gebruiker.FirstOrDefaultAsync(g => g.GebruikerId == gebruiker.GebruikerId)); } } }