コード例 #1
0
 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));
 }
コード例 #2
0
        // 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));
        }
コード例 #3
0
        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));
        }