Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(string id)
        {
            Note note = await _noteStorageService.GetNote(User.Identity.Name, id);

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

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

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

            ViewData["Title"] = $"Edit Note - {note.Title}";

            return(View("Edit", note));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Note> > Get(string username, string id)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                return(BadRequest("Username is required"));
            }

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

            Note note = await _noteStorageService.GetNote(username, id);

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

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

            return(note);
        }