Beispiel #1
0
        private string GetPaymentSignature(PaymentActionDto action)
        {
            var data = new
            {
                action.Timestamp,
                action.ActionType,
                EmployeeId             = action.Employee.Id,
                CreditPaymentId        = action.CreditPayment.Id,
                CreditPaymentTimeStamp = action.CreditPayment.Timestamp,
                CreditAccountId        = action.CreditPayment.CreditAccount.Id,
                PaymentSum             = action.CreditPayment.PaymentSum.Value,
                PaymentCurrencyId      = action.CreditPayment.PaymentSum.Currency.Id
            };
            var json = JsonConvert.SerializeObject(data);

            return(_signatureService.Sign(json, action.Employee.User.Key).Value);
        }
Beispiel #2
0
        public async Task <CommandResult> AddPaymentAsync(AddPaymentCommand command)
        {
            var rightsRes = await CheckEmployeeRightsAsync(command.EmployeeId, EmployeeRights.Cashier);

            var employeeRes = await GetEmployeeAsync(command.EmployeeId);

            var accountRes = await GetCreditAccountAsync(command.CreditAccountId);

            var res = CheckPayment(rightsRes, employeeRes, accountRes, command.PaymentSum);

            if (res.IsFailed)
            {
                return(new CommandResult(command, false).From(res));
            }
            var payment = new CreditPaymentDto
            {
                Timestamp     = DateTime.Now,
                PaymentSum    = command.PaymentSum,
                CreditAccount = accountRes.Value,
                Employee      = employeeRes.Value
            };
            var paymentRes = await _creditPaymentService.CreateModelAsync(payment);

            if (paymentRes.IsFailed)
            {
                return(new CommandResult(command, false).From(paymentRes));
            }
            var action = new PaymentActionDto
            {
                Timestamp     = DateTime.Now,
                Employee      = employeeRes.Value,
                CreditPayment = payment,
                ActionType    = GetActionType(command.GetType().Name)
            };

            action.Signature = GetPaymentSignature(action);
            await _paymentActionService.CreateModelAsync(action);

            return(new CommandResult(command, true));
        }