|
| 1 | +using Microsoft.AspNetCore.Mvc; |
| 2 | +using System; |
| 3 | +using TestHosts.Database.TestBank; |
| 4 | + |
| 5 | +namespace TestHosts.Controllers |
| 6 | +{ |
| 7 | + using System.Threading; |
| 8 | + using System.Threading.Tasks; |
| 9 | + using Database.PataPawa; |
| 10 | + using Newtonsoft.Json; |
| 11 | + using Shared.General; |
| 12 | + |
| 13 | + [Route("api/developer")] |
| 14 | + [ApiController] |
| 15 | + public class DeveloperController : ControllerBase |
| 16 | + { |
| 17 | + private readonly Func<String, PataPawaContext> ContextResolver; |
| 18 | + |
| 19 | + public DeveloperController(Func<String, PataPawaContext> contextResolver) { |
| 20 | + this.ContextResolver = contextResolver; |
| 21 | + } |
| 22 | + |
| 23 | + [HttpPost] |
| 24 | + [Route("patapawapostpay/createbill")] |
| 25 | + public async Task<IActionResult> CreateHostConfiguration([FromBody] CreatePataPawaPostPayBill request, |
| 26 | + CancellationToken cancellationToken) |
| 27 | + { |
| 28 | + String connectionString = ConfigurationReader.GetConnectionString("PataPawaReadModel"); |
| 29 | + PataPawaContext context = this.ContextResolver(connectionString); |
| 30 | + |
| 31 | + Guid billIdentifier = Guid.NewGuid(); |
| 32 | + |
| 33 | + // TODO: check for a duplicate bill?? |
| 34 | + |
| 35 | + await context.PostPaidBills.AddAsync(new PostPaidBill { |
| 36 | + Amount = request.Amount, |
| 37 | + AccountNumber = request.AccountNumber, |
| 38 | + DueDate = request.DueDate, |
| 39 | + AccountName = request.AccountName, |
| 40 | + IsFullyPaid = false, |
| 41 | + PostPaidBillId = billIdentifier |
| 42 | + }, |
| 43 | + cancellationToken); |
| 44 | + |
| 45 | + await context.SaveChangesAsync(cancellationToken); |
| 46 | + |
| 47 | + return this.Ok(new |
| 48 | + { |
| 49 | + billIdentifier |
| 50 | + }); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + public class CreatePataPawaPostPayBill |
| 55 | + { |
| 56 | + [JsonProperty("due_date")] |
| 57 | + public DateTime DueDate { get; set; } |
| 58 | + [JsonProperty("amount")] |
| 59 | + public Decimal Amount { get; set; } |
| 60 | + |
| 61 | + [JsonProperty("account_number")] |
| 62 | + public String AccountNumber { get; set; } |
| 63 | + [JsonProperty("account_name")] |
| 64 | + public String AccountName { get; set; } |
| 65 | + |
| 66 | + } |
| 67 | +} |
0 commit comments