public async Task PublishAsync(IInvoiceConfirmation invoiceConfirmation) { Validate(invoiceConfirmation); await _publisher.ProduceAsync(invoiceConfirmation); _log.Info("Invoice confirmation is published.", invoiceConfirmation); }
public InvoiceConfirmationEntity(IInvoiceConfirmation invoiceConfirmation) { Sent = DateTime.UtcNow; PartitionKey = GetPartitionKey(Sent); RowKey = GetRowKey(Guid.NewGuid().ToString()); UserEmail = invoiceConfirmation.UserEmail; CashOut = invoiceConfirmation.CashOut; InvoiceList = invoiceConfirmation.InvoiceList; SettledInBlockchainDateTime = invoiceConfirmation.SettledInBlockchainDateTime; BlockchainHash = invoiceConfirmation.BlockchainHash; }
public string Serialize(IInvoiceConfirmation invoiceConfirmation) { XNamespace ns = "http://schemas.datacontract.org/2004/07/LykkeRESTService"; XNamespace nsi = "http://www.w3.org/2001/XMLSchema-instance"; var xmlInvoiceConfirmation = new XElement(ns + "InvoiceConfirmation", new XAttribute(XNamespace.Xmlns + "i", nsi)); CreateIfNotNull(xmlInvoiceConfirmation, "UserEmail", invoiceConfirmation.UserEmail); AddIfNotNull(xmlInvoiceConfirmation, CreateInvoiceList(invoiceConfirmation.InvoiceList)); AddIfNotNull(xmlInvoiceConfirmation, CreateCashOut(invoiceConfirmation.CashOut)); CreateIfNotNull(xmlInvoiceConfirmation, "SettledInBlockchainDateTime", invoiceConfirmation.SettledInBlockchainDateTime?.ToString("s")); CreateIfNotNull(xmlInvoiceConfirmation, "BlockchainHash", invoiceConfirmation.BlockchainHash); return(xmlInvoiceConfirmation.ToString().Replace(" xmlns=\"\"", string.Empty)); }
protected virtual void Validate(IInvoiceConfirmation invoiceConfirmation) { var context = new ValidationContext(invoiceConfirmation); var results = new List <ValidationResult>(); var isValid = Validator.TryValidateObject(invoiceConfirmation, context, results, true); if (!isValid) { var modelErrors = new Dictionary <string, List <string> >(); foreach (ValidationResult validationResult in results) { if (validationResult.MemberNames != null && validationResult.MemberNames.Any()) { foreach (string memberName in validationResult.MemberNames) { AddModelError(modelErrors, memberName, validationResult.ErrorMessage); } } else { AddModelError(modelErrors, string.Empty, validationResult.ErrorMessage); } } throw new InvoiceConfirmationException("Model is invalid.", modelErrors); } if (invoiceConfirmation.InvoiceList != null) { foreach (var invoiceOperation in invoiceConfirmation.InvoiceList) { Validate(invoiceOperation); } } Validate(invoiceConfirmation.CashOut); }
public async Task AddAsync(IInvoiceConfirmation invoiceConfirmation) { await _storage.InsertOrReplaceAsync(new InvoiceConfirmationEntity(invoiceConfirmation)); }