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 = dbCard.CardId }, card);
        }
        public IHttpActionResult PutCard(int id, CardModel card)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            #region

            var dbCard = db.Cards.Find(id);
            dbCard.Update(card);
            db.Entry(dbCard).State = EntityState.Modified;

            #endregion

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 3
0
        public IHttpActionResult PostCard(CardModel cardModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            //Instantiate data Database Card object
            var dbCard = new Card();

            //Fill in Database Card object properties with cardModel properties
            //..
            dbCard.Name = cardModel.Name;
            dbCard.ListId = cardModel.ListId;
            dbCard.Text = cardModel.Text;
            dbCard.CreatedDate = cardModel.CreatedDate;
            dbCard.CardId = cardModel.CardId;
            
            //Save to Database
            db.Cards.Add(dbCard);

            //Update Database
            db.SaveChanges();
                     

            return CreatedAtRoute("DefaultApi", new { id = dbCard.CardId }, cardModel);
        }