public async ValueTask <IActionResult> GetBranches(string code, [FromQuery] string city, [FromQuery] Paging page = null, CancellationToken cancellation = default) { if (string.IsNullOrEmpty(code)) { return(this.BadRequest()); } if (string.IsNullOrEmpty(city)) { return(this.BadRequest()); } if (page == null) { page = Paging.Page(1, 50); } var result = await AuthorityFactory.GetAuthority().GetBranchesAsync(code, city, page, cancellation); if (page.TotalCount > 0) { this.Response.Headers.Add("X-Paging", page.ToString()); this.Response.Headers.Add("X-Pagination", page.ToString()); return(this.Ok(result)); } return(this.NotFound()); }
public async ValueTask <IActionResult> Find(string code, CancellationToken cancellation = default) { if (string.IsNullOrEmpty(code)) { return(this.BadRequest()); } var result = await AuthorityFactory.GetAuthority().FindAsync(code, cancellation); return(result != null?this.Ok(result.Value) : this.NotFound()); }
public async ValueTask <IActionResult> UploadAsync(string name = null, CancellationToken cancellation = default) { if (this.Request.ContentLength == null || this.Request.ContentLength == 0) { return(this.BadRequest()); } var filePath = await ReadAsStringAsync(this.Request); if (string.IsNullOrEmpty(filePath)) { return(this.BadRequest()); } var result = await AuthorityFactory.GetAuthority(name).UploadAsync(filePath, cancellation); return(result.Succeed ? this.Content(result.Value) : this.BadRequest(result.Failure)); }
public async ValueTask <IActionResult> Get(BankUtility.BankKind kind, [FromQuery] Paging page = null, CancellationToken cancellation = default) { if (page == null) { page = Paging.Page(1, 50); } var result = await AuthorityFactory.GetAuthority().GetBanksAsync(kind, page, cancellation); if (page.TotalCount > 0) { this.Response.Headers.Add("X-Paging", page.ToString()); this.Response.Headers.Add("X-Pagination", page.ToString()); return(this.Ok(result)); } return(this.NotFound()); }
private IAuthority GetAuthority(string key) { var authority = AuthorityFactory.GetAuthority(key); if (authority != null) { return(authority); } foreach (var provider in _providers ??= this.ServiceProvider.ResolveAll <IServiceProvider <IAuthority> >()) { authority = provider.GetService(key); if (authority != null) { return(authority); } } return(null); }
public static PaymentManager Get(string name, IAuthority authority) { if (authority == null) { throw new ArgumentNullException(nameof(authority)); } if (string.IsNullOrEmpty(authority.Code)) { throw new ArgumentException("Invalid authority of the wechat."); } var master = AuthorityFactory.GetAuthority(name) ?? throw new InvalidOperationException($"The specified '{name}' authority does not exist."); return(_services.GetOrAdd(name + ':' + authority.Code, (key, state) => { return new PaymentManager() { Payment = new PaymentService.BrokerPaymentService(state.master, state.authority), Refundment = new RefundmentService.BrokerRefundmentService(state.master, state.authority), }; }, new { master, authority })); }
public async ValueTask <IActionResult> GetCertificateAsync(string code = null, CancellationToken cancellation = default) { var certificate = await AuthorityFactory.GetAuthority().GetCertificateAsync(code, cancellation); return(certificate == null?this.NotFound() : this.Ok(certificate)); }