示例#1
0
        public async Task <IActionResult> Account(AccountViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                var user = await _usersProvider.GetUser(User.GetUserId());

                user.GithubAliases = model.GitHubAliases?.Split(',');
                if (model.GitHubLogin != user.GitHubAccount)
                {
                    var apiClient = new GithubApiClient();
                    if (!apiClient.UserExists(model.GitHubLogin))
                    {
                        throw new Exception("GitHub User with provided login does not exist.");
                    }
                }
                user.GitHubAccount = model.GitHubLogin;
                if (model.GitHubToken != user.GitHubToken)
                {
                    var client = new GithubApiClient(user.GitHubAccount, model.GitHubToken);
                    if (!client.CredentialsAreValid())
                    {
                        throw new Exception("Specified token is not valid");
                    }
                }
                user.GitHubToken = model.GitHubToken;
                user.Name        = model.Name;
                await _usersProvider.UpdateUser(user);
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
            }
            return(View(model));
        }
示例#2
0
 Task <IUser> IUsersService.UpdateUserAsync(IUser user, string username, string fullname)
 {
     return(Task.Run(() => _usersProvider.UpdateUser(user.Id, username, fullname).ToEntity()));
 }
 public async Task <bool> UpdateUser([FromBody] User userToUpdate)
 {
     return(await _usersProvider.UpdateUser(userToUpdate));
 }
示例#4
0
        public HttpResponseMessage UpdateById(UsersUpdateRequest request, int id)
        {
            var resp = _usersProvider.UpdateUser(request, id);

            return(Request.CreateResponse(HttpStatusCode.OK, resp));
        }