public IActionResult Load([FromBody] WalletLoadRequest request) { // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { // get the wallet folder DirectoryInfo walletFolder = this.GetWalletFolder(); Wallet wallet = this.walletManager.LoadWallet(request.Password, request.Name); return(this.Ok()); } catch (FileNotFoundException e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.NotFound, "This wallet was not found at the specified location.", e.ToString())); } catch (SecurityException e) { // indicates that the password is wrong return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, "Wrong password, please try again.", e.ToString())); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult Load([FromBody] WalletLoadRequest walletLoad) { // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { var wallet = this.walletWrapper.Load(walletLoad.Password, walletLoad.FolderPath, walletLoad.Name); return(this.Json(wallet)); } catch (FileNotFoundException e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Conflict, "This wallet already exists.", e.ToString())); } catch (SecurityException e) { // indicates that the password is wrong return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, "Wrong password, please try again.", e.ToString())); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult Load([FromBody] WalletLoadRequest request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { return(BuildErrorResponse(this.ModelState)); } try { Wallet wallet = this.walletManager.LoadWallet(request.Password, request.Name); return(this.Ok()); } catch (FileNotFoundException e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.NotFound, "This wallet was not found at the specified location.", e.ToString())); } catch (SecurityException e) { // indicates that the password is wrong this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, "Wrong password, please try again.", e.ToString())); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public async Task <IActionResult> Load([FromBody] WalletLoadRequest request, CancellationToken cancellationToken = default(CancellationToken)) { return(await this.Execute(request, cancellationToken, async (req, token) => { await this.walletService.LoadWallet(req, token); return Ok(); })); }