public async Task <PostFileResponse> PostFile(string guid, IFormFile file, CancellationToken token) { if (string.IsNullOrEmpty(guid)) { throw new WebArgumentException(nameof(PostFile), nameof(guid), guid); } if (file.Length > Configuration.FileSize) { return(PostFileResponse.FileSizeError); } var solutionSet = await SolutionService.FetchSolutionSet(guid, token); if (solutionSet == null) { return(PostFileResponse.IdentificationError); } var problemSet = await ProblemService.FetchProblemAsync(solutionSet.ProblemId, token); if (problemSet == null) { return(PostFileResponse.ProblemIdentificationError); } if (file.Length > problemSet.SolutionSize) { return(PostFileResponse.FileSizeError); } using (var writer = new FileStream(Path.Combine(Configuration.FileLocation, file.FileName), FileMode.CreateNew)) { await file.CopyToAsync(writer, token); await writer.FlushAsync(token); } var result = await SolutionService.FinalizeSolutionSet(guid, token); if (result == SolutionServiceResult.Full) { return(PostFileResponse.Full); } if (result == SolutionServiceResult.Incomplete || result == SolutionServiceResult.StartOver) { return(PostFileResponse.Failure); } return(PostFileResponse.Success); }