Ejemplo n.º 1
0
        public async Task <Reaction> Post([FromBody] Reaction reaction)
        {
            using (var db = new ReactionContext())
            {
                db.Reactions.Add(reaction);
                await db.SaveChangesAsync();

                return(reaction);
            }
        }
Ejemplo n.º 2
0
        public async Task <Reaction> Update(int id, [FromBody] Reaction newReaction)
        {
            using (var db = new ReactionContext())
            {
                var oldReaction = db.Reactions.Single(reaction => reaction.Id == id);
                oldReaction.Word  = newReaction.Word;
                oldReaction.Emoji = newReaction.Emoji;
                await db.SaveChangesAsync();

                return(oldReaction);
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Delete(int id)
        {
            using (var db = new ReactionContext())
            {
                var deleteReaction = db.Reactions.FirstOrDefault(reaction => reaction.Id == id);
                if (deleteReaction != null)
                {
                    db.Reactions.Remove(deleteReaction);
                    await db.SaveChangesAsync();

                    return(Ok());
                }
                else
                {
                    return(NotFound());
                }
            }
        }