public async Task <ActionResult> Edit(UpdateResourceOwnerViewModel viewModel) { if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } await TranslateUserEditView(DefaultLanguage); var authenticatedUser = await SetUser(); if (!ModelState.IsValid) { ViewBag.IsUpdated = false; return(View(viewModel)); } var resourceOwner = await _userActions.GetUser(authenticatedUser); var subject = authenticatedUser.GetSubject(); if (resourceOwner == null) { var record = viewModel.ToAddUserParameter(); await _userActions.AddUser(record); } else { var parameter = viewModel.ToParameter(); foreach (var newClaim in resourceOwner.Claims.Where(uc => !parameter.Claims.Any(pc => pc.Type == uc.Type))) { parameter.Claims.Add(newClaim); } parameter.Login = subject; await _userActions.UpdateUser(parameter); } ViewBag.IsUpdated = true; return(View(viewModel)); }