示例#1
0
        // POST api/Cards
        public HttpResponseMessage PostCard(Card card)
        {
            if (ModelState.IsValid)
            {
                db.Cards.AddObject(card);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, card);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = card.CardId }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
示例#2
0
        // PUT api/Cards/5
        public HttpResponseMessage PutCard(int id, Card card)
        {
            if (ModelState.IsValid && id == card.CardId)
            {
                db.Cards.Attach(card);
                db.ObjectStateManager.ChangeObjectState(card, EntityState.Modified);

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                return Request.CreateResponse(HttpStatusCode.OK, card);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Cards EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCards(Card card)
 {
     base.AddObject("Cards", card);
 }
 /// <summary>
 /// Create a new Card object.
 /// </summary>
 /// <param name="cardId">Initial value of the CardId property.</param>
 /// <param name="lastUpdate">Initial value of the LastUpdate property.</param>
 /// <param name="reviewDate">Initial value of the ReviewDate property.</param>
 public static Card CreateCard(global::System.Int32 cardId, global::System.DateTime lastUpdate, global::System.DateTime reviewDate)
 {
     Card card = new Card();
     card.CardId = cardId;
     card.LastUpdate = lastUpdate;
     card.ReviewDate = reviewDate;
     return card;
 }