public async Task <AppResponse> CloseAccountAsync(CloseAccountRequest model, CancellationToken cancellationToken = default) { var user = await GetByUsernameAsync(model.UserName); if (user != null) { return(new AppResponse { Status = HttpStatusCode.NotFound, Message = "Could not find a user", }); } //user.IsEnabled = false; //dataContext.Update(user); //await dataContext.SaveChangesAsync(cancellationToken); try { await userRepository.CloseAccountAsync(user); return(new AppResponse { Status = HttpStatusCode.Accepted }); } catch (Exception) { return(new AppResponse { Status = HttpStatusCode.InternalServerError, Message = "Could not process to save a user data.", }); } }
public async Task <CloseAccountResponse> CloseAccount(CloseAccountRequest request) { var logDic = new Dictionary <string, object> { { "AccountIdentifier", request.AccountIdentifier }, { "Option", request.Option.ToString() }, }; var endpointUrl = $"{ConfigManager.Instance.GetApiEndpoint("CRMCoreService")}/Account/closeAccount"; try { var handler = new HttpClientHandler { UseDefaultCredentials = true, PreAuthenticate = true }; _apiClient.Client = new HttpClient(handler); var response = await _apiClient.PostAsync <CloseAccountResponse, CloseAccountRequest>(new Uri(endpointUrl), request, LogOptionEnum.FullLog, logDic); return(HandleNoSuccessResponse <CloseAccountResponse>(response, logDic, MethodBase.GetCurrentMethod().Name) ? null : response); } catch (Exception ex) { logDic.Add("EndPointUrl", endpointUrl); throw new ExternalErrorException( "Error when calling CloseAccount route from CRMcoreService", new LogObject("CRMCoreService_CloseAccount", logDic), ex); throw; } }
/// <summary> /// Post /closeAccount API call /// </summary> /// <param name="closeAccountRequest"></param> /// <returns>CloseAccountResponse</returns> public CloseAccountResponse CloseAccount(CloseAccountRequest closeAccountRequest) { var jsonRequest = Util.JsonOperation.SerializeRequest(closeAccountRequest); var jsonResponse = _closeAccount.Request(jsonRequest); return(JsonConvert.DeserializeObject <CloseAccountResponse>(jsonResponse)); }
public async Task <IActionResult> Delete(CloseAccountRequest model) { if (ModelState.IsValid) { await _userService.Delete(model); return(Ok()); } return(BadRequest("Faild")); }
public void TestCloseAccountSuccess() { var client = CreateMockTestClientNullRequiredFieldsRequest("Mocks/marketpay/account/close-account-success.json"); var account = new Account(client); var closeAccountRequest = new CloseAccountRequest(accountCode: "123456"); var closeAccountResponse = account.CloseAccount(closeAccountRequest); Assert.IsNotNull(closeAccountResponse); Assert.AreEqual(closeAccountResponse.PspReference, "8515810799236011"); Assert.AreEqual(closeAccountResponse.Status, CloseAccountResponse.StatusEnum.Closed); }
public override async Task <CloseAccountResponse> CloseAccount(CloseAccountRequest closeAccountRequest, ServerCallContext context) { Log.Information("CloseAccount called via gRPC remote service {@closeAccountRequest}", closeAccountRequest); var closeAccountCommand = _mapper.Map <CloseAccountCommand>(closeAccountRequest); var result = await _mediator.Send(closeAccountCommand); CloseAccountResponse closeAccountResponse = _mapper.Map <CloseAccountResponse>(result); return(closeAccountResponse); }
/** * Close account. */ internal async Task <APIGatewayProxyResponse> CloseAccount(IDataStores dataStores, IDictionary <string, string> requestHeaders, JObject requestBody) { Debug.Untested(); Debug.AssertValid(dataStores); Debug.AssertValid(requestHeaders); Debug.AssertValidOrNull(requestBody); try { // Log call LoggingHelper.LogMessage($"UserIdentityService::CloseAccount()"); // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Check inputs CloseAccountRequest closeAccountRequest = UserIdentityService_CloseAccount_LogicLayer.CheckValidCloseAccountRequest(requestBody); Debug.AssertValid(closeAccountRequest); // Check authenticated endpoint security string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders); Debug.AssertID(loggedInUserId); // Perform logic await UserIdentityService_CloseAccount_LogicLayer.CloseAccount(dbClient, loggedInUserId, closeAccountRequest); // Respond return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_NO_CONTENT }); } catch (Exception exception) { Debug.Tested(); if (exception.Message == IdentityServiceLogicLayer.ERROR_INCORRECT_PASSWORD) { Debug.Untested(); //??--return StatusCode(APIHelper.STATUS_CODE_UNAUTHORIZED, new GeneralErrorResponse { error = IdentityServiceLogicLayer.INCORRECT_PASSWORD }); //??--return Unauthorized(); return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_UNAUTHORIZED, Body = $"{{ error = \"{IdentityServiceLogicLayer.INCORRECT_PASSWORD}\"}}" }); } else { Debug.Tested(); return(APIHelper.ResponseFromException(exception)); } } }
public async Task AdGroupLeft(int AccountId, int CampaignId, int AdGroupId) { var request = new CloseAccountRequest { AccountKey = $"{AccountId}:{CampaignId}:{AdGroupId}" }; try { await _rpcClient.CloseAccountAsync(request); } catch (RpcException ex) { _log.Error($"Failed to close account {request.AccountKey}", ex); throw new BillingControllerException($"Failed to close account {request.AccountKey}", ex); } }
public async Task Delete(CloseAccountRequest model) { var user = _userManager.Users.SingleOrDefault(x => x.Name == model.Name); if (user != null) { if (model.IsRememberPassword) { bool isChecked = await _userManager.CheckPasswordAsync(user, model.Password); if (isChecked) { // Wait for implement } } var result = await _userManager.DeleteAsync(user); if (result.Succeeded) { var token = GenerateJwtToken(user); } } }
public async Task <IHttpActionResult> CloseAccount([FromBody] CloseAccountRequest request) { var response = await CloseAccountManager.Execute(request); return(CreateResponse(response)); }
/** * Close account. */ public static async Task CloseAccount(AmazonDynamoDBClient dbClient, string loggedInUserId, CloseAccountRequest closeAccountRequest) { Debug.Tested(); Debug.AssertValid(dbClient); Debug.AssertID(loggedInUserId); Debug.AssertValid(closeAccountRequest); Debug.AssertString(closeAccountRequest.password); // Load the user User user = await IdentityServiceLogicLayer.FindUserByID(dbClient, loggedInUserId); Debug.AssertValid(user); Debug.AssertNull(user.Closed); // Check the password if (user.PasswordHash == Helper.Hash(closeAccountRequest.password)) { // Make changes user.Closed = DateTime.Now; // Save the user await IdentityServiceDataLayer.SaveUser(dbClient, user); // Actually log user out await IdentityServiceLogicLayer.InvalidateUserAccessTokens(dbClient, loggedInUserId); } else { Debug.Untested(); throw new Exception(IdentityServiceLogicLayer.ERROR_INCORRECT_PASSWORD); } }