コード例 #1
0
        public IHttpActionResult PutCard(int id, CardModel card)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != card.CardID)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
        public IHttpActionResult PostCard(CardModel card)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbCard = new Card(card);
            db.Cards.Add(dbCard);
            db.SaveChanges();

            card.CreatedDate = dbCard.CreatedDate;
            card.CardID = dbCard.CardID;

            return CreatedAtRoute("DefaultApi", new { id = card.CardID }, card);
        }