Beispiel #1
0
        public async Task GetAsync_Sample()
        {
            var requestUri = new Uri("users/test", UriKind.Relative);
            var json       = TestFileProvider.ReadText("user.json");

            clientContext.MockHttpMessageHandler.SetResponse(requestUri, json);

            var user = await client.GetAsync("test");

            Assert.IsNotNull(user);

            var expected = new UserResult
            {
                Id        = 7,
                Username  = "******",
                FullName  = "",
                Email     = "",
                AvatarUrl = "https://secure.gravatar.com/avatar/bb11777b425ba7229a182f446783203d"
            };

            ObjectTreeAssert.AreEqual(expected, user);
        }
Beispiel #2
0
        // GET: User/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            UsersClient api = new UsersClient();

            User user = await api.GetAsync(id);

            if (user == null)
            {
                return(HttpNotFound());
            }

            ViewBag.UserTypeID = LoadUserTypes();

            return(View(user));
        }
Beispiel #3
0
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="id">将删除的用户的ID</param>
        /// <returns>状态码,<see cref="StatusCodes.Status204NoContent"/>代表删除成功,<see cref="StatusCodes.Status404NotFound"/>代表未找到</returns>
        public async Task <int> DeleteUserAsync(int id)
        {
            // 获取用户
            UserData data = await dataContext.FindAsync <UserData>(id);

            if (data == null)
            {
                return(StatusCodes.Status404NotFound);
            }

            do
            {
                // 在Auth0上删除
                await userClient.DeleteAsync(data.StringUserID);
            } while (null != await userClient.GetAsync(data.StringUserID));

            // 在本地数据库中删除
            dataContext.Remove <UserData>(data);
            dataContext.SaveChanges();
            return(StatusCodes.Status204NoContent);
        }
Beispiel #4
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                CurrentUser = await _userManager.GetUserAsync(User);
            }
            else
            {
                HttpClient  httpclient = _clientFactory.CreateClient();
                UsersClient client     = new UsersClient(httpclient);
                try
                {
                    CurrentUser = await client.GetAsync(id);
                }
                catch
                {
                    CurrentUser = null;
                }

                try
                {
                    StatisticsClient sscli = new StatisticsClient(httpclient);
                    Statistics = await sscli.GetUserAsync(id);
                }
                catch
                {
                    Statistics = null;
                }
            }

            if (CurrentUser == null)
            {
                return(NotFound($"Unable to load user with ID '{id ?? _userManager.GetUserId(User)}'."));
            }

            return(Page());
        }
Beispiel #5
0
        public static async Task <ProblemModel> GetAsync(ProblemMetadata metadata, HttpClient client, bool loadDescription, bool loadData)
        {
            ProblemModel res = new ProblemModel
            {
                Metadata = metadata,
            };

            ProblemsClient pcli = new ProblemsClient(client);

            {
                try
                {
                    StatisticsClient stcli = new StatisticsClient(client);
                    res.Statistics = await stcli.GetProblemAsync(metadata.Id);
                }
                catch
                {
                    res.Statistics = null;
                }
            }

            if (loadDescription)
            {
                try
                {
                    res.Description = await pcli.GetDescriptionAsync(metadata.Id);
                }
                catch { }
            }

            if (loadData)
            {
                try
                {
                    res.Samples = await pcli.GetSamplesAsync(metadata.Id);
                }
                catch
                {
                    res.Samples = Array.Empty <TestCaseMetadata>();
                }

                try
                {
                    res.Tests = await pcli.GetTestsAsync(metadata.Id);
                }
                catch
                {
                    res.Tests = Array.Empty <TestCaseMetadata>();
                }
            }

            {
                UsersClient ucli = new UsersClient(client);
                try
                {
                    res.User = await ucli.GetAsync(metadata.UserId);
                }
                catch
                {
                    res.User = null;
                }
            }

            return(res);
        }