예제 #1
0
        public IHttpActionResult PutCard(int id, CardsModel card)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            var dbCard = db.Cards.Find(id);
            dbCard.Update(card);

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #2
0
        public IHttpActionResult PostCard(CardsModel card)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var addcard = new Card(card);

            db.Cards.Add(addcard);
            db.SaveChanges();

            card.CardID = addcard.CardID;
            card.CreatedDate = addcard.CreatedDate;

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