Exemplo n.º 1
0
        /// <summary>
        /// Adds a new merchant account
        /// </summary>
        /// <param name="merchant">Details of new merchant</param>
        /// <returns>bool</returns>
        public async Task <bool> CreateMerchantAccountAsync(Merchant merchant)
        {
            await using PaymentControllerDbContext context = DbContextProvider.Create();

            try
            {
                Model.Merchant dbMerchant = merchant.ToDb();
                context.Merchant.Add(dbMerchant);

                int result = await context.SaveChangesAsync().ConfigureAwait(false);

                return(result.Equals(1));
            }
            catch (Exception ex)
            {
                Logger.LogWarning(ex, "An exception has occured in {name}", nameof(CreateMerchantAccountAsync));

                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method for creating a new customer.
        /// </summary>
        /// <param name="customer">The customer details</param>
        /// <returns>Customer object</returns>
        public async Task <Customer> CreateCustomerAsync(Customer customer)
        {
            await using PaymentControllerDbContext context = DbContextProvider.Create();

            Model.Customer dbCustomer = customer.ToDb();
            context.Customers.Add(dbCustomer);

            try
            {
                await context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.LogWarning(ex, "An exception has occured in {name}", nameof(CreateCustomerAsync));
                Logger.LogInformation("Failed to create new customer {@customer}", customer);

                throw;
            }

            return(dbCustomer.ToDto());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method for saving payment details to database.
        /// </summary>
        /// <param name="payment">The payment</param>
        /// <returns>PaymentItem object</returns>
        public async Task <PaymentItem> SavePaymentItemAsync(PaymentItem payment)
        {
            await using PaymentControllerDbContext context = DbContextProvider.Create();

            Model.PaymentItem dbPaymentItem = payment.ToDb();
            context.Payments.Add(dbPaymentItem);

            try
            {
                if (payment.PaymentCustomer.CustomerId.IsValid())
                {
                    context.Customers.Attach(dbPaymentItem.PaymentCustomer);
                }
                if (payment.PaymentCustomer.Address.AddressId.IsValid())
                {
                    context.Address.Attach(dbPaymentItem.PaymentCustomer.Address);
                }
                if (payment.PaymentCard.CardId.IsValid())
                {
                    context.Card.Attach(dbPaymentItem.PaymentCard);
                }

                context.Merchant.Attach(dbPaymentItem.PaymentMerchant);

                await context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.LogWarning(ex, "An exception has occured in {name}", nameof(SavePaymentItemAsync));
                Logger.LogInformation("Payment {PaymentId} failed to process.", payment.PaymentId);

                throw;
            }

            return(dbPaymentItem.ToDto());
        }