Ejemplo n.º 1
0
        // POST: api/Tweets
        // [Authorize]
        // [ResponseType(typeof(Tweet))]
        public async Task <IHttpActionResult> PostTweet([FromBody] TweetViewModel tweetViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            Tweet algo = tweetViewModel.ToTweet();

            db.Tweets.Add(tweetViewModel.ToTweet());
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = tweetViewModel.Id }, algo));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PutTweet(int id, [FromBody] TweetViewModel tweetViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            db.Entry(tweetViewModel.ToTweet()).State = EntityState.Modified;


            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TweetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }