Esempio n. 1
0
        public async static Task UpdateStore(PurchaseTransactionId id, Store store)
        {
            var connectionString      = ConnectivityService.GetConnectionString("TEMP");
            var context               = new SplurgeStopDbContext(connectionString);
            var repository            = new PurchaseTransactionRepository(context);
            var unitOfWork            = new EfCoreUnitOfWork(context);
            var service               = new PurchaseTransactionService(repository, unitOfWork);
            var transactionController = new PurchaseTransactionController(service);

            var updateCommand = new transaction.Commands.SetPurchaseTransactionStore();

            updateCommand.Id      = id;
            updateCommand.StoreId = store.Id;

            await transactionController.Put(updateCommand);
        }
Esempio n. 2
0
        public double GetPaymentAmount(long customerId, DateTimeOffset fromDate, DateTimeOffset toDate)
        {
            Customer customer = CustomerService.GetCustomerById(customerId);

            if (customer == null)
            {
                return(0);
            }

            IList <Subscription> subscriptions = SubscriptionService.GetSortedSubscriptions(customer.SubscriptionIds);

            if (subscriptions.Count == 0)
            {
                subscriptions.Add(new Subscription
                {
                    Id = 1,
                    SubscriptionType = SubscriptionTypes.Free,
                    Priority         = 1,
                    PriceDetails     = new Dictionary <string, double>
                    {
                        { "FixPrice", 0 },
                        { "OldBookDiscount", 10 },
                        { "NewBookDiscount", 0 },
                        { "NewBookDiscountAmmount", 0 }
                    }
                });
            }

            IList <PurchaseTransaction> purchaseTransactions = PurchaseTransactionService.GetPurchaseTransactions(customerId, fromDate, toDate);

            if (purchaseTransactions == null)
            {
                return(0);
            }

            IList <Book> books = BookService.GetBooks(purchaseTransactions);

            if (books == null)
            {
                return(0);
            }

            double totalSubscriptionPrice = SubscriptionService.GetTotalSubscriptionPrice(subscriptions);
            double totalTransactionPrice  = PurchaseTransactionService.GetTotalTransactionPrice(books, subscriptions);

            return(totalSubscriptionPrice + totalTransactionPrice);
        }
Esempio n. 3
0
        public static async Task UpdatePurchaseDate(PurchaseTransactionId id, DateTime date)
        {
            var connectionString      = ConnectivityService.GetConnectionString("TEMP");
            var context               = new SplurgeStopDbContext(connectionString);
            var repository            = new PurchaseTransactionRepository(context);
            var unitOfWork            = new EfCoreUnitOfWork(context);
            var service               = new PurchaseTransactionService(repository, unitOfWork);
            var transactionController = new PurchaseTransactionController(service);

            var updateCommand = new Commands.SetPurchaseTransactionDate
            {
                Id = id,
                TransactionDate = date
            };

            await transactionController.Put(updateCommand);
        }
Esempio n. 4
0
        public static async Task <PurchaseTransactionId> CreateFullValidPurchaseTransaction()
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new SplurgeStopDbContext(connectionString);
            var repository       = new PurchaseTransactionRepository(context);
            var unitOfWork       = new EfCoreUnitOfWork(context);
            var service          = new PurchaseTransactionService(repository, unitOfWork);

            var command = new Commands.CreateFull
            {
                Id = null,
                TransactionDate = DateTime.Now
            };

            // Add Store
            var store = await StoreHelpers.CreateValidStore();

            command.StoreId = store.Id;

            // Get Product
            var prod = await ProductHelpers.CreateValidProduct();

            // Add one LineItem
            var newLineItem = new LineItemStripped
            {
                Booking                = Booking.Credit,
                Price                  = "1.23",
                CurrencyCode           = "EUR",
                CurrencySymbol         = "€",
                CurrencySymbolPosition = CurrencySymbolPosition.End,
                Notes                  = "New notes",
                ProductId              = prod.Id
            };

            command.LineItems = new List <LineItemStripped>
            {
                newLineItem
            };

            var transactionController = new PurchaseTransactionController(service);
            await transactionController.Post(command);

            return(command.Id);
        }
Esempio n. 5
0
        public async Task Get_All_PurchaseTransactions()
        {
            List <PurchaseTransactionStripped> mockPurchaseTransactions = MockPurchaseTransactions();

            var mockRepository = new Mock <IPurchaseTransactionRepository>();

            mockRepository.Setup(repo => repo.GetAllDtoAsync())
            .Returns(() => Task.FromResult(mockPurchaseTransactions.AsEnumerable()));

            var mockUnitOfWork = new Mock <IUnitOfWork>();

            var purchaseTransactionService = new PurchaseTransactionService(mockRepository.Object, mockUnitOfWork.Object);

            var purchaseTransactionController = new PurchaseTransactionController(purchaseTransactionService);
            var result = await purchaseTransactionController.GetPurchaseTransactions();

            Assert.Equal(10, result.Count());
            mockRepository.Verify(mock => mock.GetAllDtoAsync(), Times.Once());
        }
Esempio n. 6
0
        public static async Task <PurchaseTransactionId> CreateValidPurchaseTransaction(decimal price     = 1.00m,
                                                                                        LineItem lineItem = null)
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new SplurgeStopDbContext(connectionString);
            var repository       = new PurchaseTransactionRepository(context);
            var unitOfWork       = new EfCoreUnitOfWork(context);
            var service          = new PurchaseTransactionService(repository, unitOfWork);

            var command = new Commands.CreateFull();

            command.Id = null;
            command.TransactionDate = DateTime.Now;

            // Add Store
            var store = await StoreHelpers.CreateValidStore();

            command.StoreId = store.Id;

            // Get Product
            var prod = await ProductHelpers.CreateValidProduct();

            // Add one LineItem
            command.LineItems = new List <LineItemStripped>
            {
                new LineItemStripped
                {
                    Price                  = price.ToString(CultureInfo.InvariantCulture),
                    CurrencyCode           = "EUR",
                    CurrencySymbol         = "€",
                    CurrencySymbolPosition = CurrencySymbolPosition.End,
                    Booking                = Booking.Credit,
                    Notes                  = lineItem?.Notes,
                    ProductId              = prod.Id
                }
            };

            // Create PurchaseTransaction
            var transactionController = new PurchaseTransactionController(service);
            await transactionController.Post(command);

            return(command.Id);
        }
Esempio n. 7
0
        public async static Task <PurchaseTransactionId> CreateValidPurchaseTransaction(decimal price     = 1.00m,
                                                                                        LineItem lineItem = null)
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new SplurgeStopDbContext(connectionString);
            var repository       = new PurchaseTransactionRepository(context);
            var unitOfWork       = new EfCoreUnitOfWork(context);
            var service          = new PurchaseTransactionService(repository, unitOfWork);

            var command = new transaction.Commands.Create();

            command.Id = null;

            // Create PurchaseTransaction
            var transactionController = new PurchaseTransactionController(service);
            var result = await transactionController.Post(command);

            // Add PurchaseDate
            await UpdatePurchaseDate(result.Value.Id, DateTime.Now);

            var purchaseTransaction = await repository.GetPurchaseTransactionFullAsync(result.Value.Id);

            // Add Store
            var store = await CreateValidStore();

            await UpdateStore(purchaseTransaction.Id, store);

            // Add one LineItem
            var updateLineItemCommand = new transaction.Commands.SetPurchaseTransactionLineItem();

            updateLineItemCommand.Id                     = purchaseTransaction.Id;
            updateLineItemCommand.Price                  = price;
            updateLineItemCommand.Currency               = "EUR";
            updateLineItemCommand.CurrencySymbol         = "€";
            updateLineItemCommand.Booking                = Booking.Credit;
            updateLineItemCommand.CurrencySymbolPosition = CurrencySymbolPosition.end;
            updateLineItemCommand.Notes                  = lineItem?.Notes;

            await transactionController.Put(updateLineItemCommand);

            return(command.Id);
        }
Esempio n. 8
0
        public async static Task <PurchaseTransactionId> CreateFullValidPurchaseTransaction()
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new SplurgeStopDbContext(connectionString);
            var repository       = new PurchaseTransactionRepository(context);
            var unitOfWork       = new EfCoreUnitOfWork(context);
            var service          = new PurchaseTransactionService(repository, unitOfWork);

            var command = new transaction.Commands.CreateFull();

            command.Id = null;

            // Add PurchaseDate
            command.TransactionDate = DateTime.Now;

            // Add Store
            var store = await CreateValidStore();

            command.StoreId = store.Id;

            // Add one LineItem
            var newLineItem = new LineItemStripped
            {
                Booking                = Booking.Credit,
                Price                  = 1.23m,
                CurrencyCode           = "EUR",
                CurrencySymbol         = "€",
                CurrencySymbolPosition = CurrencySymbolPosition.end,
                Notes                  = "New notes"
            };

            command.LineItems = new List <LineItemStripped>();
            command.LineItems.Add(newLineItem);

            var transactionController = new PurchaseTransactionController(service);
            var result = await transactionController.Post(command);

            return(command.Id);
        }
Esempio n. 9
0
        public async static Task UpdateLineItem(PurchaseTransactionId id, LineItem lineItem)
        {
            var connectionString      = ConnectivityService.GetConnectionString("TEMP");
            var context               = new SplurgeStopDbContext(connectionString);
            var repository            = new PurchaseTransactionRepository(context);
            var unitOfWork            = new EfCoreUnitOfWork(context);
            var service               = new PurchaseTransactionService(repository, unitOfWork);
            var transactionController = new PurchaseTransactionController(service);

            var updateCommand = new transaction.Commands.SetPurchaseTransactionLineItem();

            updateCommand.Id                     = id;
            updateCommand.LineItemId             = lineItem.Id;
            updateCommand.Price                  = lineItem.Price.Amount;
            updateCommand.Currency               = lineItem.Price.Currency.CurrencyCode;
            updateCommand.CurrencySymbol         = lineItem.Price.Currency.CurrencySymbol;
            updateCommand.Booking                = lineItem.Price.Booking;
            updateCommand.CurrencySymbolPosition = lineItem.Price.Currency.PositionRelativeToPrice;
            updateCommand.Notes                  = lineItem?.Notes;

            await transactionController.Put(updateCommand);
        }