public static void Run(
            //[BlobTrigger("licenses/{name}", Connection = "AzureWebJobsStorage")]string licenseFileContents,
            //[SendGrid(ApiKey = "SendGridApiKey")] out SendGridMessage message,
            [BlobTrigger("licenses/{orderId}.lic", Connection = "AzureWebJobsStorage")] string licenseFileContents,
            [SendGrid(ApiKey = "SendGridApiKey")] ICollector <SendGridMessage> mailSender,
            [Table("orders", "orders", "{orderId}")] OrderStorage orderStorage, //fetches data from table storage
            string orderId,
            ILogger log)
        {
            log.LogInformation($"Got license file for: {orderStorage.Email}\n License filename: {orderId}");

            var message = new SendGridMessage();

            message.From = new EmailAddress(Environment.GetEnvironmentVariable("EmailSender"));
            message.AddTo(orderStorage.Email);
            var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(licenseFileContents);
            var base64         = Convert.ToBase64String(plainTextBytes);

            message.AddAttachment(orderId, base64, "text/plain");
            message.Subject     = "Your License File";
            message.HtmlContent = "Thank you for you order";

            if (!orderStorage.Email.EndsWith("@test.com"))
            {
                mailSender.Add(message);
            }
        }
Esempio n. 2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            [Queue("orders")] IAsyncCollector <Order> orderQueue,
            [Table("orders")] IAsyncCollector <OrderStorage> orderTable,
            ILogger log)
        {
            log.LogInformation("Recevied a payment");

            //add to queue - queue is created if it doesn't already exist, message is serialized for us too - nice!
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            Order  data        = JsonConvert.DeserializeObject <Order>(requestBody);
            await orderQueue.AddAsync(data);

            //we also store the order in table storage in the same storage location
            //we could also add this to CosmosDB, or our own Db if we wanted to
            OrderStorage orderTableStorageItem = new OrderStorage
            {
                PartitionKey = "orders",
                RowKey       = data.OrderId,
                Email        = data.Email,
                OrderId      = data.OrderId,
                Price        = data.Price,
                ProductId    = data.ProductId
            };

            await orderTable.AddAsync(orderTableStorageItem);

            log.LogInformation($"Order {data.OrderId} received from {data.Email} for productId {data.ProductId}");

            return(new OkObjectResult($"Thank you for your payment"));
        }
Esempio n. 3
0
        public Order(
            Guid orderId,
            Guid billId,
            Guid customerId,
            OrderHistorization orderHistorization,
            OrderStorage orderStorage,
            IDateComponent dateComponent,
            UserHistorizationComponent userHistorizationComponent)
        {
            if (orderHistorization == null)
            {
                throw new ArgumentNullException(nameof(orderHistorization));
            }

            if (orderStorage == null)
            {
                throw new ArgumentNullException(nameof(orderStorage));
            }

            if (dateComponent == null)
            {
                throw new ArgumentNullException(nameof(dateComponent));
            }

            if (userHistorizationComponent == null)
            {
                throw new ArgumentNullException(nameof(userHistorizationComponent));
            }

            _orderId    = orderId;
            _billId     = billId;
            _customerId = customerId;
            OrderState  = new OrderConfirmedState(this, orderHistorization, orderStorage, dateComponent, userHistorizationComponent);
        }
Esempio n. 4
0
 public Lender(string integrationToken) : base(integrationToken)
 {
     Loans    = new LoanStorage(this);
     Orders   = new OrderStorage(this);
     Products = new ProductStorage(this);
     Users    = new UserStorage(this);
     Vendors  = new VendorStorage(this);
     Apps     = new AppStorage(this);
     Evaults  = new EvaultStorage(this);
 }
Esempio n. 5
0
 public SqlOrderFactory(
     ApplicationLog applicationLog,
     OrderHistorization orderHistorization,
     OrderStorage orderStorage,
     IDateComponent dateComponent)
 {
     _applicationLog     = applicationLog ?? throw new ArgumentNullException(nameof(applicationLog));
     _orderHistorization = orderHistorization ?? throw new ArgumentNullException(nameof(orderHistorization));
     _orderStorage       = orderStorage ?? throw new ArgumentNullException(nameof(orderStorage));
     _dateComponent      = dateComponent ?? throw new ArgumentNullException(nameof(dateComponent));
 }
Esempio n. 6
0
 public OrderConfirmedState(
     Order order,
     OrderHistorization orderHistorization,
     OrderStorage orderStorage,
     IDateComponent dateComponent,
     UserHistorizationComponent userHistorizationComponent)
 {
     _order = order ?? throw new ArgumentNullException(nameof(order));
     _orderHistorization         = orderHistorization ?? throw new ArgumentNullException(nameof(orderHistorization));
     _orderStorage               = orderStorage;
     _dateComponent              = dateComponent ?? throw new ArgumentNullException(nameof(dateComponent));
     _userHistorizationComponent = userHistorizationComponent ?? throw new ArgumentNullException(nameof(userHistorizationComponent));
 }
Esempio n. 7
0
        /// <summary>
        /// This method is a facade which simplifies the placement of an order.
        /// It orchestrates the steps needed to place an order.
        /// The OrderPlacement process consists of a validation, price calculation and the storage of the order.
        /// </summary>
        /// <param name="articleId">The article id</param>
        /// <param name="quantity">The quantity</param>
        /// <returns>True if order was succesfully stored and will be shipped</returns>
        public bool PlaceOrder(string articleId, int quantity)
        {
            Order order = new Order
            {
                ArticleId = articleId,
                Quantity  = quantity
            };

            // Validate order
            bool result = OrderValidator.IsValidOrder(order);

            // Calculate Price
            result = result && CalculatePrice(order);

            // Place Order
            result = result & OrderStorage.PlaceOrder(order);

            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Usuwanie zleceniodawcy (Button)
        /// </summary>
        private void buttonDeleteCustomer_Click(object sender, RoutedEventArgs e)
        {
            OrderStorage orderStorage = new OrderStorage();

            if (!orderStorage.Read().Any(o => o.Customer.ID == _customerToEdit.ID))
            {
                MessageBoxResult result = MessageBox.Show("Czy na pewno chcesz usunąć zleceniodawcę: " + _customerToEdit.Name + " ?", "Uwaga!", MessageBoxButton.OKCancel, MessageBoxImage.Question);
                if (result == MessageBoxResult.OK)
                {
                    _customerStorage.Delete(_customerToEdit);
                    this.DialogResult = true;
                    MessageBox.Show("Usunięto!", "Informacja");
                }
            }
            else
            {
                MessageBox.Show("Nie można usunąć zleceniodawcy, ponieważ ma on przypisane zlecenia!", "Uwaga!");
            }
        }
Esempio n. 9
0
 public OrdersController(IConfiguration config)
 {
     _storage = new OrderStorage(config);
 }
Esempio n. 10
0
 public void PerTestPrepare()
 {
     OS = new OrderStorage(_config);
     OR = new OrderRepository(OS);
 }