示例#1
0
        public async Task PublishAsync(IInvoiceConfirmation invoiceConfirmation)
        {
            Validate(invoiceConfirmation);

            await _publisher.ProduceAsync(invoiceConfirmation);

            _log.Info("Invoice confirmation is published.", invoiceConfirmation);
        }
示例#2
0
        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;
        }
示例#3
0
        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));
        }
示例#4
0
        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));
 }