Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

                _context.Audio.Remove(Audio);
                if (message != null)
                {
                    message.AudioId = 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 '{Audio.ToString()}'.");
            }

            return(RedirectToPage("/Messages/Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Audio = await _context.Audio
                    .Include(a => a.Message).FirstOrDefaultAsync(m => m.Id == id);

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