Esempio n. 1
0
        public async Task <AUser_User> GetUserAsync(string userId)
        {
            using var log = BeginFunction(nameof(UserAdminService), nameof(GetUserAsync), userId);
            try
            {
                await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false);

                using var ctx = QuiltContextFactory.Create();

                var dbAspNetUser = await ctx.AspNetUsers
                                   .Include(r => r.AspNetUserRoles)
                                   .ThenInclude(r => r.Role)
                                   .Include(r => r.AspNetUserLogins)
                                   .Where(r => r.Id == userId)
                                   .FirstOrDefaultAsync().ConfigureAwait(false);

                if (dbAspNetUser == null)
                {
                    log.Result(null);
                    return(null);
                }

                var squareCustomerReference = CreateSquareCustomerReference.FromUserId(userId);
                var squareCustomerId        = await SquareMicroService.LookupSquareCustomerIdAsync(squareCustomerReference).ConfigureAwait(false);

                var mSquareCustomerSummaryList = squareCustomerId != null
                    ? await SquareMicroService.GetSquareCustomerSummariesAsync(squareCustomerId.Value, null).ConfigureAwait(false)
                    : null;

                var mSquarePaymentSummaryList = squareCustomerId != null
                    ? await SquareMicroService.GetSquarePaymentSummariesAsync(squareCustomerId, null, null).ConfigureAwait(false)
                    : null;

                var ordererReference = CreateOrdererReference.FromUserId(userId);
                var ordererId        = await OrderMicroService.LookupOrdererAsync(ordererReference).ConfigureAwait(false);

                var mOrderSummaryList = ordererId != null
                    ? await OrderMicroService.GetOrderSummariesAsync(null, null, MOrder_OrderStatus.MetaAll, ordererId, null).ConfigureAwait(false)
                    : null;

                var result = Create.AUser_User(
                    dbAspNetUser,
                    mOrderSummaryList,
                    mSquareCustomerSummaryList?.Summaries.FirstOrDefault(),
                    mSquarePaymentSummaryList);

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
Esempio n. 2
0
        public async Task CreateCustomer()
        {
            var originalSquareCustomerReference = CreateSquareCustomerReference.FromTimestamp(GetUniqueNow());
            var originalSquareCustomerId        = await SquareMicroService.AllocateSquareCustomerAsync(originalSquareCustomerReference);

            var squareCustomerId = await SquareMicroService.LookupSquareCustomerIdAsync(originalSquareCustomerReference);

            Assert.AreEqual(originalSquareCustomerId, squareCustomerId);

            var squareCustomer = await SquareMicroService.GetSquareCustomerAsync(originalSquareCustomerId);

            Assert.IsNotNull(squareCustomer);
            Assert.AreEqual(originalSquareCustomerReference, squareCustomer.SquareCustomerReference);
        }