public async Task FindAndDeleteFiles(string prefix)
        {
            ListObjectsV2Request request = new ListObjectsV2Request
            {
                BucketName = _bucketName,
                Prefix     = prefix
            };
            ListObjectsV2Response response;

            do
            {
                response = await _s3Client.ListObjectsV2Async(request);

                // Process the response.
                foreach (S3Object entry in response.S3Objects)
                {
                    await FileHandler.DeleteFileS3(entry.Key);
                }

                request.ContinuationToken = response.NextContinuationToken;
            } while (response.IsTruncated);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(int?id, int?coid)
        {
            if (id == null)
            {
                return(Redirect(Url.Content("~/Forbidden")));;
            }


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

            Settings = await _context.Settings.FirstOrDefaultAsync(m => m.CONTESTID == id);

            Questions = await _context.Questions.FirstOrDefaultAsync(m => m.CONTESTID == id);

            Mails = await _context.Mails.FirstOrDefaultAsync(m => m.CONTESTID == id);

            Company = await _context.Company.FirstOrDefaultAsync(m => m.Id == coid);

            AnswersList = await _context.Answers.Where(x => x.CONTESTID == Contest.ID).ToListAsync();

            PlayerList = await _context.Player.Where(x => x.CONTESTID == Contest.ID).ToListAsync();

            if (Contest != null)
            {
                await DeleteFile();

                ListObjectsV2Request request = new ListObjectsV2Request
                {
                    BucketName = _bucketName,
                    Prefix     = _context.Company.FirstOrDefaultAsync(m => m.Id == _userManager.GetUserAsync(User).Result.CompanyId).Result.CompanyName + "/" + Contest.NAME + "/"
                };
                ListObjectsV2Response response;
                do
                {
                    response = await _s3Client.ListObjectsV2Async(request);

                    // Process the response.
                    foreach (S3Object entry in response.S3Objects)
                    {
                        await FileHandler.DeleteFileS3(entry.Key);
                    }

                    request.ContinuationToken = response.NextContinuationToken;
                } while (response.IsTruncated);



                foreach (var item in AnswersList)
                {
                    _context.Answers.Remove(item);
                }
                foreach (var item in PlayerList)
                {
                    _context.Player.Remove(item);
                }

                _context.Contest.Remove(Contest);
                _context.Settings.Remove(Settings);
                _context.Questions.Remove(Questions);
                _context.Mails.Remove(Mails);
                await _context.SaveChangesAsync();
            }


            return(Redirect(Url.Content("~/Contests/") + Company.Id));
        }