Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PostAnnotatedConversation(AnnotatedConversation annotatedConversation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.AnnotatedConversations.Add(annotatedConversation);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (AnnotatedConversationExists(annotatedConversation.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = annotatedConversation.Id }, annotatedConversation));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PutAnnotatedConversation(int id, AnnotatedConversation annotatedConversation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> GetAnnotatedConversation(int id)
        {
            AnnotatedConversation annotatedConversation = await db.AnnotatedConversations.FindAsync(id);

            if (annotatedConversation == null)
            {
                return(NotFound());
            }

            return(Ok(annotatedConversation));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> DeleteAnnotatedConversation(int id)
        {
            AnnotatedConversation annotatedConversation = await db.AnnotatedConversations.FindAsync(id);

            if (annotatedConversation == null)
            {
                return(NotFound());
            }

            db.AnnotatedConversations.Remove(annotatedConversation);
            await db.SaveChangesAsync();

            return(Ok(annotatedConversation));
        }