예제 #1
0
        public string DoSomethingComplex(DateTime deviceLastCommunicated)
        {
            var deviceStatus = _deviceStatusProvider.GetDeviceStatusBetterMethod(_dateProvider.GetUtcNow(), deviceLastCommunicated, _settingOptionsMonitor.CurrentValue.TimeLapseInMinutesConsideredDeviceOffline);

            if (deviceStatus == Enums.DeviceStatus.Offline)
            {
                return(DeviceOfflineString);
            }

            return(_workerService.DoSomeWork());
        }
예제 #2
0
        public string GenerateString(IDateProvider provider)
        {
            var created = provider.GetUtcNow();
            var expired = created.AddDays(DaysExpire);

            return(string.Format("userName={0}|role={1}|permissions={2}|created-date={3}|expiration-date={4}", User, Role, string.Join(";", Permissions.ToArray()), created, expired));
        }
예제 #3
0
            public async Task <Payment> Handle(ProcessPaymentRequest request, CancellationToken cancellationToken)
            {
                // Check that the payment has approver
                if (request.Payment.ApproverID == Guid.Empty)
                {
                    throw new ApproverMissingException();
                }

                // Make sure that the approver exists and not deleted.
                // This check is required because DB constraints won't throw exception if the approver ID is marked as deleted.
                var approver = await _staffRepo.GetStaffAsync(request.Payment.ApproverID);

                if (approver == null)
                {
                    throw new StaffNotFoundException();
                }

                // Make sure payment and customer exist
                var customer = await _customerRepo.GetCustomerAsync(request.Payment.CustomerID);

                if (customer == null)
                {
                    throw new CustomerNotFoundException();
                }

                var existingPayment = await _paymentRepo.GetPaymentAsync(request.Payment.ID);

                if (existingPayment == null)
                {
                    throw new PaymentNotFoundException();
                }

                // Check payment status, make sure it's pending
                if (existingPayment.PaymentStatus != PaymentStatus.Pending)
                {
                    throw new UnableToProcessNonPendingPaymentException();
                }

                // Give default comment if payment is processed
                if (request.Payment.PaymentStatus == PaymentStatus.Processed)
                {
                    request.Payment.Comment = Payment.ProcessedComment;
                }

                // Process payment
                request.Payment.ProcessedDateUtc = _dateProvider.GetUtcNow();
                await _paymentRepo.UpdatePaymentAsync(request.Payment);

                // If not processed, re-adjust customer's balance
                if (request.Payment.PaymentStatus != PaymentStatus.Processed)
                {
                    customer.CurrentBalance += request.Payment.Amount;
                    await _customerRepo.UpdateCustomerAsync(customer);
                }

                return(request.Payment);
            }
예제 #4
0
            public async Task <Payment> Handle(CreatePaymentRequest request, CancellationToken cancellationToken)
            {
                // Make sure the payment amount is positive
                if (request.Payment.Amount <= 0)
                {
                    throw new AmountMustBeGreaterThanZeroException();
                }

                // Check that the payment has no approver
                if (request.Payment.ApproverID != Guid.Empty)
                {
                    throw new UnexpectedApproverOnPaymentCreationException();
                }

                // Check customer balance
                var customer = await _customerRepo.GetCustomerAsync(request.Payment.CustomerID);

                if (customer == null)
                {
                    throw new CustomerNotFoundException();
                }

                // Call it here so the utc time is consistent between requested and processed dates
                var utcNow = _dateProvider.GetUtcNow();

                request.Payment.RequestedDateUtc = utcNow;

                if (customer.CurrentBalance < request.Payment.Amount)
                {
                    request.Payment.ProcessedDateUtc = utcNow;
                    request.Payment.PaymentStatus    = PaymentStatus.Closed;
                    request.Payment.Comment          = Payment.InsufficientFundComment;
                }
                else
                {
                    // Create payment
                    request.Payment.PaymentStatus = PaymentStatus.Pending;
                }

                await _paymentRepo.CreatePaymentAsync(request.Payment);

                // Adjust customer's balance
                customer.CurrentBalance -= request.Payment.Amount;
                await _customerRepo.UpdateCustomerAsync(customer);

                return(request.Payment);
            }