Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostInitializeAsync()
        {
            if ((await CanAdmin()) == false)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            HttpClient      httpclient = clientFactory.CreateClient();
            WorkspaceClient client     = new WorkspaceClient(httpclient);
            await client.InitializeAsync();

            UserMetadata rawUser = new UserMetadata {
                Email = "admin@localhost", Name = "Admin"
            };
            await _userManager.CreateAsync(rawUser, "admin");

            {
                UsersClient  ucli = new UsersClient(httpclient);
                UserMetadata user = await ucli.GetByNameAsync(rawUser.NormalizedName);

                ProblemsClient pcli = new ProblemsClient(httpclient);
                await pcli.CreateAsync(Helpers.Problems.GetAPlusB(user.Id));
            }

            return(RedirectToPage());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostCreateAsync()
        {
            if (!await CheckModel(false))
            {
                if (await GetData(PostData.Metadata.Id))
                {
                    return(Page());
                }
                else
                {
                    return(NotFound());
                }
            }

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

            try
            {
                ProblemMetadata pro = await client.CreateAsync(new API.Models.ProblemData
                {
                    Description = PostData.Description,
                    Metadata    = PostData.Metadata,
                });

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