Exemple #1
0
        /// <summary>
        /// Updates the status of the shipment
        /// </summary>
        /// <param name="invoiceId">Shipment Id</param>
        public async Task UpdateStatusAsync(int invoiceId)
        {
            var invoice = invoicesRepository.GetById(invoiceId);

            if (invoice != null)
            {
                string postOperatorName = invoicesRepository.GetPostOperatorsIdNames()[invoiceId];
                foreach (var agent in FactoryOfAgents.GetAllAgents(apiKeys))
                {
                    if (postOperatorName == agent.GetName())
                    {
                        string status = await agent.GetStatus(invoice.Number);

                        if (status != "")
                        {
                            invoicesRepository.UpdateStatus(invoiceId, status);
                            break;
                        }
                        else
                        {
                            throw new Exception("Відправлення не знайдено.");
                        }
                    }
                }
            }
            else
            {
                throw new Exception("Відправлення не знайдено.");
            }
        }
Exemple #2
0
        /// <summary>
        /// Search for a shipment by number
        /// </summary>
        /// <param name="number">Shipment number in the information system of the postal operator</param>
        /// <returns>Shipment Dto model</returns>
        public async Task <InvoiceDto> SearchByNumber(string number)
        {
            try
            {
                InvoiceDto invoiceDto = null;
                foreach (var agent in FactoryOfAgents.GetAllAgents(apiKeys))
                {
                    invoiceDto = await agent.SearchByNumber(number);

                    if (invoiceDto != null)
                    {
                        break;
                    }
                }
                return(invoiceDto);
            }
            catch (Exception)
            {
                throw new Exception("Помилка доступу до інформаційної системи поштового оператора.");
            }
        }