예제 #1
0
        public async Task <IActionResult> Delete(
            int id,
            [HttpTrigger(AuthorizationLevel.Anonymous, nameof(HttpMethods.Delete), Route = "notes/{id:int}")] HttpRequest req,
            ILogger log)
        {
            var user = await accessTokenValidator.Validate(req);

            if (!user.Identity.IsAuthenticated)
            {
                return(new UnauthorizedResult());
            }

            var note = await dbContext.Notes.SingleOrDefaultAsync(note => note.Id == id);

            if (note is null)
            {
                log.CouldNotFoundNoteBy(id);

                return(new NotFoundResult());
            }

            log.DeleteNotesBy(id);
            dbContext.Remove(note);
            await dbContext.SaveChangesAsync();

            return(new NoContentResult());
        }