public IHttpActionResult Post([FromBody] PerformanceArea performanceArea) { if (!ModelState.IsValid) { return(BadRequest()); } performanceArea.Id = PerformanceArea.GetNextId(_context); _context.PerformanceAreas.Add(performanceArea); _context.SaveChanges(); return(Created(new Uri(Request.RequestUri + "/" + performanceArea.Id), performanceArea)); }
// GET api/PerformanceArea/5 public IHttpActionResult Get(int id) { PerformanceArea performanceAreaInDB = null; performanceAreaInDB = _context.PerformanceAreas.FirstOrDefault(d => d.Id == id); if (performanceAreaInDB == null) { return(NotFound()); } return(Ok(performanceAreaInDB)); }
public IHttpActionResult Put(int id, [FromBody] PerformanceArea performanceArea) { if (!ModelState.IsValid) { return(BadRequest()); } PerformanceArea performanceAreaInDB = _context.PerformanceAreas.FirstOrDefault(d => d.Id == id); if (performanceAreaInDB == null) { return(NotFound()); } performanceAreaInDB.Name = performanceArea.Name; _context.SaveChanges(); return(Ok(performanceAreaInDB)); }