示例#1
0
        // PUT api/Week/5
        public IHttpActionResult PutWeek(int id, Week week)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != week.Id)
            {
                return BadRequest();
            }

            db.Entry(week).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WeekExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
示例#2
0
        public IHttpActionResult PostWeek(Week week)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Week.Add(week);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = week.Id }, week);
        }