public IActionResult Update([FromRoute] int userId, [FromBody] JsonPatchDocument <UserPatch> userPatch) { var user = _userRepositories.Get(userId); if (user == null) { return(NotFound()); } UserPatch patchDTO = _mapper.Map <UserPatch>(user); userPatch.ApplyTo(patchDTO); TryValidateModel(patchDTO); _mapper.Map(patchDTO, user); int result = _userRepositories.Update(user); if (result == -1) { ModelState.AddModelError(nameof(user.EmailId), "EmailId already exist"); return(_apiBehaviorOptions.Value.InvalidModelStateResponseFactory(ControllerContext)); } return(Ok(user)); }
internal void SynchronizeEngine(UserPatch patch) { // no need to queue like with actors, just slap it right on there if (patch.Groups.HasValue) { Groups = patch.Groups.Value; } }
/// <summary> /// Update/Patch User /// HTTP Method: patch /// Endpoint: /scim/{version}/Users/{id} /// Rate Limit Group: Heavy /// App Permission: EditAccounts /// </summary> public async Task <UserResponse> Patch(UserPatch userPatch, RestRequestConfig restRequestConfig = null) { if (id == null) { throw new ArgumentException("Parameter cannot be null", nameof(id)); } return(await rc.Patch <UserResponse>(Path(), userPatch, null, restRequestConfig)); }
internal void SynchronizeUser(UserPatch userPatch) { if (userPatch.IsPatched()) { var payload = new UserUpdate() { User = userPatch }; EventManager.QueueLateEvent(new UserEvent(userPatch.Id, payload)); } }
public IActionResult Post([FromBody] UserPatch value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new User(); value.Patch(user); return(Ok(user)); }
public async void PatchUser() { using (var rc = new RestClient( Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_ID"), Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_SECRET"), Environment.GetEnvironmentVariable("RINGCENTRAL_SERVER_URL") )) { await rc.Authorize( Environment.GetEnvironmentVariable("RINGCENTRAL_USERNAME"), Environment.GetEnvironmentVariable("RINGCENTRAL_EXTENSION"), Environment.GetEnvironmentVariable("RINGCENTRAL_PASSWORD") ); var searchRequest = new SearchRequest { count = 1, filter = "emails eq \"[email protected]\"" }; // search for the SCIM user var userSearchResponse = await rc.Scim().Users().DotSearch().Post(searchRequest); if (userSearchResponse.Resources.Length == 1) { var userResponse = userSearchResponse.Resources[0]; var guid = Guid.NewGuid().ToString(); var userPatch = new UserPatch { schemas = new[] { "urn:ietf:params:scim:api:messages:2.0:PatchOp" }, Operations = new[] { new PatchOperation { op = "replace", path = "name.familyName", value = guid } } }; // patch it var ur = await rc.Scim().Users(userResponse.id).Patch(userPatch); Assert.Equal("*****@*****.**", ur.emails[0].value); // make sure data patched successfully Assert.Equal(guid, ur.name.familyName); } } }
internal void SynchronizeApps() { foreach (var mreApp in _joinedApps) { var userPatch = new UserPatch(Id); // TODO: Write user changes to the patch. if (userPatch.IsPatched()) { mreApp.SynchronizeUser(userPatch); } } }
public async Task <IActionResult> UpdateUser(string id, [FromBody] JsonPatchDocument <UserPatch> patch) { if (!(await _authorizationService.AuthorizeAsync(User, id, AuthPolicies.ManageUserByUserIdPolicy)).Succeeded) { return(new ChallengeResult()); } if (ModelState.IsValid) { if (patch == null) { return(BadRequest($"{nameof(patch)} cannot be null")); } ApplicationUser appUser = await _accountManager.GetUserByIdAsync(id); if (appUser == null) { return(NotFound(id)); } UserPatch userPVM = Mapper.Map <UserPatch>(appUser); patch.ApplyTo(userPVM, ModelState); if (ModelState.IsValid) { Mapper.Map(userPVM, appUser); Tuple <bool, string[]> result = await _accountManager.UpdateUserAsync(appUser); if (result.Item1) { return(NoContent()); } AddErrors(result.Item2); } } return(BadRequest(ModelState)); }
public IHttpActionResult UserActive(UserPatch user) { var userscontext = new ApplicationDbContext(); var userelement = userscontext.Users.FirstOrDefault(u => u.Id == user.Id); if (userelement == null) { return(NotFound()); } else { userelement.IsActive = user.IsActive; userscontext.SaveChangesAsync(); } return(Ok()); }
/// <summary> /// update the user update one user /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id">the id of the user</param> /// <param name="user">the data to update</param> /// <returns>Task of ApiResponse (PatchResponse)</returns> public async System.Threading.Tasks.Task <ApiResponse <PatchResponse> > UpdateUserAsyncWithHttpInfo(string id, UserPatch user) { // verify the required parameter 'id' is set if (id == null) { throw new ApiException(400, "Missing required parameter 'id' when calling UserApi->UpdateUser"); } // verify the required parameter 'user' is set if (user == null) { throw new ApiException(400, "Missing required parameter 'user' when calling UserApi->UpdateUser"); } var localVarPath = "/users/{id}"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new Dictionary <String, String>(); var localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json localVarPathParams.Add("format", "json"); if (id != null) { localVarPathParams.Add("id", Configuration.ApiClient.ParameterToString(id)); // path parameter } if (user != null && user.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(user); // http body (model) parameter } else { localVarPostBody = user; // byte array } // authentication (OAuth) required // oauth required if (!String.IsNullOrEmpty(Configuration.AccessToken)) { localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken; } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath, Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (localVarStatusCode >= 400) { throw new ApiException(localVarStatusCode, "Error calling UpdateUser: "******"Error calling UpdateUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); } return(new ApiResponse <PatchResponse>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (PatchResponse)Configuration.ApiClient.Deserialize(localVarResponse, typeof(PatchResponse)))); }
/// <summary> /// update the user update one user /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id">the id of the user</param> /// <param name="user">the data to update</param> /// <returns>Task of PatchResponse</returns> public async System.Threading.Tasks.Task <PatchResponse> UpdateUserAsync(string id, UserPatch user) { ApiResponse <PatchResponse> localVarResponse = await UpdateUserAsyncWithHttpInfo(id, user); return(localVarResponse.Data); }
/// <summary> /// update the user update one user /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id">the id of the user</param> /// <param name="user">the data to update</param> /// <returns>PatchResponse</returns> public PatchResponse UpdateUser(string id, UserPatch user) { ApiResponse <PatchResponse> localVarResponse = UpdateUserWithHttpInfo(id, user); return(localVarResponse.Data); }
public Task <User> PatchAsync(string id, UserPatch user) { throw new NotImplementedException(); }
/// <summary> /// Updates a single User with one or more values /// </summary> /// <param name="updatedUser">The new data for the User you wish to update</param> /// <returns>Returns a result indicating if the operation succeeded</returns> public async Task <Result> UpdateUser(UserPatch updatedUser) { try { using (var con = new Npgsql.NpgsqlConnection(settings.Connection.DatabaseConnectionString)) { var sqlPatchOperations = new StringBuilder(); var obj = updatedUser; var operationCount = 0; if (obj.RegistrationId != null) { sqlPatchOperations.AppendLine(obj.RegistrationId.Operation == OperationKind.Remove ? "registrationId = NULL," : "registrationId = @RegistrationId," ); operationCount++; } if (obj.FirstName != null) { sqlPatchOperations.AppendLine(obj.FirstName.Operation == OperationKind.Remove ? "firstName = NULL," : "firstName = @FirstName," ); operationCount++; } if (obj.LastName != null) { sqlPatchOperations.AppendLine(obj.LastName.Operation == OperationKind.Remove ? "lastName = NULL," : "lastName = @LastName," ); operationCount++; } if (obj.Email != null) { sqlPatchOperations.AppendLine(obj.Email.Operation == OperationKind.Remove ? "email = NULL," : "email = @Email," ); operationCount++; } if (obj.Dob != null) { sqlPatchOperations.AppendLine(obj.Dob.Operation == OperationKind.Remove ? "dob = NULL," : "dob = @Dob," ); operationCount++; } if (obj.IsVerified != null) { sqlPatchOperations.AppendLine(obj.IsVerified.Operation == OperationKind.Remove ? "isVerified = NULL," : "isVerified = @IsVerified," ); operationCount++; } if (obj.WantAdvertising != null) { sqlPatchOperations.AppendLine(obj.WantAdvertising.Operation == OperationKind.Remove ? "wantAdvertising = NULL," : "wantAdvertising = @WantAdvertising," ); operationCount++; } if (obj.ExternalPaymentProcessorId != null) { sqlPatchOperations.AppendLine(obj.ExternalPaymentProcessorId.Operation == OperationKind.Remove ? "externalPaymentProcessorId = NULL," : "externalPaymentProcessorId = @ExternalPaymentProcessorId," ); operationCount++; } if (obj.AppleUserIdentifier != null) { sqlPatchOperations.AppendLine(obj.AppleUserIdentifier.Operation == OperationKind.Remove ? "appleUserIdentifier = NULL," : "appleUserIdentifier = @AppleUserIdentifier," ); operationCount++; } if (obj.FacebookUserIdentifier != null) { sqlPatchOperations.AppendLine(obj.FacebookUserIdentifier.Operation == OperationKind.Remove ? "facebookUserIdentifier = NULL," : "facebookUserIdentifier = @FacebookUserIdentifier," ); operationCount++; } if (obj.GoogleUserIdentifier != null) { sqlPatchOperations.AppendLine(obj.GoogleUserIdentifier.Operation == OperationKind.Remove ? "googleUserIdentifier = NULL," : "googleUserIdentifier = @GoogleUserIdentifier," ); operationCount++; } var patchOperations = sqlPatchOperations.ToString(); if (operationCount > 0) { // Remove final ", " from StringBuilder to ensure query is valid patchOperations = patchOperations.TrimEnd(System.Environment.NewLine.ToCharArray()); patchOperations = patchOperations.TrimEnd(','); } await con.ExecuteAsync($"UPDATE \"User\" SET {patchOperations} WHERE userId = @ResourceId", new { ResourceId = obj.ResourceId, RegistrationId = (string)(obj.RegistrationId == default ? default : obj.RegistrationId.Value), FirstName = (string)(obj.FirstName == default ? default : obj.FirstName.Value), LastName = (string)(obj.LastName == default ? default : obj.LastName.Value), Email = (string)(obj.Email == default ? default : obj.Email.Value), Dob = (string)(obj.Dob == default ? default : obj.Dob.Value), IsVerified = (bool)(obj.IsVerified == default ? default : obj.IsVerified.Value), WantAdvertising = (bool)(obj.WantAdvertising == default ? default : obj.WantAdvertising.Value), ExternalPaymentProcessorId = (string)(obj.ExternalPaymentProcessorId == default ? default : obj.ExternalPaymentProcessorId.Value), AppleUserIdentifier = (string)(obj.AppleUserIdentifier == default ? default : obj.AppleUserIdentifier.Value), FacebookUserIdentifier = (string)(obj.FacebookUserIdentifier == default ? default : obj.FacebookUserIdentifier.Value), GoogleUserIdentifier = (string)(obj.GoogleUserIdentifier == default ? default : obj.GoogleUserIdentifier.Value) }).ConfigureAwait(false); return(Result.Ok()); }
/// <summary> /// Update/Patch User /// HTTP Method: patch /// Endpoint: /scim/{version}/Users/{id} /// Rate Limit Group: Heavy /// App Permission: EditAccounts /// </summary> public async Task <UserResponse> Patch(UserPatch userPatch, RestRequestConfig restRequestConfig = null) { return(await rc.Patch <UserResponse>(Path(), userPatch, null, restRequestConfig)); }