Exemplo n.º 1
0
        public async Task <ActionResult <Like> > DeleteLike([FromBody] Like like)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var dbLike = await context.Likes.FirstOrDefaultAsync(l => like.Equals(l));

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

            context.Likes.Remove(dbLike);
            await context.SaveChangesAsync();

            return(dbLike);
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Like> > CreateLike([FromBody] Like like)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (await context.Likes.FirstOrDefaultAsync(l => like.Equals(l)) != null)
            {
                return(Conflict());
            }

            await context.Likes.AddAsync(like);

            await context.SaveChangesAsync();

            return(like);
        }