Exemplo n.º 1
0
        /// <summary>
        /// This method will enqueue active Fortnox invoices that have been
        ///   upserted in Fortnox since a given date to webCRM.
        /// </summary>
        internal async Task EnqueueRecentlyUpsertedInvoices(
            string storageAccountConnectionString,
            string webcrmSystemId,
            DateTime dateTimeSinceUpserted)
        {
            // Convert utc date we pass in to either CEST or CET.
            var dateTimeSinceUpsertedSwedish = dateTimeSinceUpserted.FromUtcToSwedish();

            var upsertedInvoices = await FortnoxClient.GetRecentlyUpsertedInvoices(dateTimeSinceUpsertedSwedish);

            Logger.LogInformation($"Found {upsertedInvoices.Count} Fortnox invoices to sync to webCRM that have been upserted since {dateTimeSinceUpsertedSwedish:yyyy-MM-dd HH:mm:ss}");

            var fortnoxQueue = await FortnoxQueue.Create(storageAccountConnectionString);

            foreach (var filteredInvoice in upsertedInvoices)
            {
                var payload = new FortnoxUpsertWebcrmDeliveryPayload
                {
                    FortnoxCustomerNumber = filteredInvoice.CustomerNumber,
                    FortnoxDocumentNumber = filteredInvoice.DocumentNumber,
                    WebcrmSystemId        = webcrmSystemId
                };
                string serializedPayload = JsonConvert.SerializeObject(payload);

                await fortnoxQueue.Enqueue(new FortnoxQueueMessage
                {
                    Action  = FortnoxQueueAction.UpsertFortnoxDelivery,
                    Payload = serializedPayload
                });
            }
        }
Exemplo n.º 2
0
        public static async Task <FortnoxQueue> Create(string storageAccountConnectionString)
        {
            var fortnoxQueue = new FortnoxQueue(storageAccountConnectionString);
            await fortnoxQueue.Queue.CreateIfNotExistsAsync();

            return(fortnoxQueue);
        }