diff --git a/Controllers/ValuesController.cs b/Controllers/ValuesController.cs index 8d0ae16..3fce368 100644 --- a/Controllers/ValuesController.cs +++ b/Controllers/ValuesController.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -36,5 +37,63 @@ namespace TestApplication.Controllers return NotFound(); } } + + [HttpPost] + public async Task> Post_Values(Values values) + { + _context.Values.Add(values); + await _context.SaveChangesAsync(); + + return CreatedAtAction("GetValues", new { id = values.Id }, values); + } + + [HttpDelete("{id}")] + public async Task> Delete_values(int id) + { + var values = await _context.Values.FindAsync(id); + if (values == null) + { + return NotFound(); + } + + _context.Values.Remove(values); + await _context.SaveChangesAsync(); + + return values; + } + + [HttpPut("{id}")] + public async Task Put_Values(int id, Values values) + { + if (id != values.Id) + { + return BadRequest(); + } + + _context.Entry(values).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!ValuesExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + private bool ValuesExists(int id) + { + return _context.Values.Any(e => e.Id == id); + } } } \ No newline at end of file