Exemplo n.º 1
0
        public async Task <IActionResult> OnGetDeleteAsync(int id)
        {
            var archiveEntry = await _context.Submissions.SingleOrDefaultAsync(c => c.Id == id);

            var fileUrl  = new Uri(archiveEntry.FileName);
            var fileName = System.IO.Path.GetFileName(fileUrl.LocalPath);
            var result   = await _storage.DeleteFile(fileName, "talentcontest");

            if (result)
            {
                _logger.LogInformation($"{User.Identity.Name} deleted {archiveEntry.FileName} from Azure");
            }
            else
            {
                _logger.LogWarning($"{User.Identity.Name} Unsuccessfully deleted {archiveEntry.FileName} from Azure");
            }

            _context.Remove(archiveEntry);
            await _context.SaveChangesAsync();

            _logger.LogInformation($"{User.Identity.Name} deleted entryId: {archiveEntry.Id}");
            return(RedirectToPage("./Index"));
        }