Ejemplo n.º 1
0
        public async Task <IActionResult> Delete(string id)
        {
            // check the owner of the note
            Note originalNote = await _noteStorageService.GetNote(User.Identity.Name, id);

            if (originalNote == null)
            {
                _logger.LogWarning($"Coulnd't find note with ID '{id}' for user '{User.Identity.Name}'");
                return(NotFound());
            }

            await _noteStorageService.DeleteNote(User.Identity.Name, id);

            _logger.LogInformation($"Deleting note with ID '{id}' for user '{User.Identity.Name}'");

            _eventPublisher.PublishEvent(new Event
            {
                EventType = EventType.NoteDeleted,
                TimeStamp = DateTime.UtcNow,
                Username  = User.Identity.Name,
                NoteId    = id
            });

            return(RedirectToAction("List"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Delete(string username, string id)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                return(BadRequest("Username is required"));
            }

            if (string.IsNullOrWhiteSpace(id))
            {
                return(BadRequest("Note ID is required"));
            }

            // check the owner of the note
            Note originalNote = await _noteStorageService.GetNote(username, id);

            if (originalNote == null)
            {
                _logger.LogWarning($"Couldn't find note with ID '{id}' for user '{username}'");
                return(NotFound());
            }

            await _noteStorageService.DeleteNote(username, id);

            _logger.LogInformation($"Deleting note with ID '{id}' for user '{username}'");

            return(Ok());
        }