예제 #1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Notes = await _context.Notes.FindAsync(id);

            if (Notes != null)
            {
                var message = await _context.Message.FindAsync(Notes.MessageId);

                _context.Notes.Remove(Notes);
                if (message != null)
                {
                    message.NotesId = null;
                    _context.Message.Update(message);
                    await _context.SaveChangesAsync();

                    return(RedirectToPage("/Messages/Edit", new { id = message.Id }));
                }
                await _context.SaveChangesAsync();

                _logger.LogCritical($"User '{User.Identity.Name}' deleted '{Notes.ToString()}'.");
            }

            return(RedirectToPage("/Messages/Index"));
        }
예제 #2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Notes = await _context.Notes
                    .Include(n => n.Message).FirstOrDefaultAsync(m => m.Id == id);

            if (Notes == null)
            {
                return(NotFound());
            }
            return(Page());
        }