コード例 #1
0
        protected async Task <ActionResult> Delete <TEntidad>(int id) where TEntidad : class, IId, new()
        {
            var existe = await context.Set <TEntidad>().AnyAsync(x => x.Id == id);

            if (!existe)
            {
                return(NotFound());
            }

            context.Remove(new TEntidad()
            {
                Id = id
            });
            await context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult> Delete(int reviewId)
        {
            var reviewDB = await context.Reviews.FirstOrDefaultAsync(x => x.Id == reviewId);

            if (reviewDB == null)
            {
                return(NotFound());
            }
            var usuarioId = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value;

            if (reviewDB.UsuarioId != usuarioId)
            {
                return(Forbid());
            }

            context.Remove(reviewDB);
            await context.SaveChangesAsync();

            return(NoContent());
        }