예제 #1
0
        public async Task <IActionResult> OnPostImportAsync()
        {
            if (!await CheckModel(true))
            {
                return(BadRequest());
            }

            HttpClient     httpclient = clientFactory.CreateClient();
            ProblemsClient client     = new ProblemsClient(httpclient);

            try
            {
                string sp = "";
                using (Stream st = PostData.ImportFile.OpenReadStream())
                    using (StreamReader sr = new StreamReader(st))
                        sp = await sr.ReadToEndAsync();
                ProblemPackage package = Newtonsoft.Json.JsonConvert.DeserializeObject <ProblemPackage>(sp);
                package.Metadata.UserId = PostData.Metadata.UserId;
                ProblemMetadata pro = await client.ImportAsync(package);

                return(RedirectToPage(new { id = pro.Id }));
            }
            catch
            {
                return(NotFound());
            }
        }