Пример #1
0
        /// <summary>
        /// Add payment code
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel <Guid> > AddPaymentCodeAsync(PaymentCodeViewModel model)
        {
            if (model == null)
            {
                return(new InvalidParametersResultModel <Guid>());
            }


            var paymentCode = _mapper.Map <PaymentCode>(model);

            await _context.PaymentCodes.AddAsync(paymentCode);

            var result = await _context.PushAsync();

            return(result.Map(paymentCode.Id));
        }
Пример #2
0
        /// <summary>
        /// Add payment
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel <Guid> > AddPaymentAsync(AddPaymentViewModel model)
        {
            if (model == null)
            {
                return(new InvalidParametersResultModel <Guid>());
            }

            var organizationRequest = await _organizationService.FindOrganizationByIdAsync(model.OrganizationId);

            if (!organizationRequest.IsSuccess)
            {
                return new ResultModel <Guid> {
                           IsSuccess = false, Errors = organizationRequest.Errors
                }
            }
            ;

            //var productRequest = await _productService.GetProductByIdAsync(model.ProductId);
            //if (!productRequest.IsSuccess)
            //    return new ResultModel<Guid> { IsSuccess = false, Errors = productRequest.Errors };

            var payment = _mapper.Map <Payment>(model);
            await _context.Payments.AddAsync(payment);

            payment.FiscalCode = organizationRequest.Result.FiscalCode;

            var mappedPayment = new PaymentMapped
            {
                OrganizationId = model.OrganizationId,
                ProductId      = model.ProductId,
                PaymentId      = payment.Id,
                PaymentCodeId  = model.PaymentCodeId,
            };

            await _context.PaymentMappers.AddAsync(mappedPayment);

            var addPaymentResult = await _context.PushAsync();


            return(addPaymentResult.IsSuccess
                ? new SuccessResultModel <Guid>(mappedPayment.Id)
                : addPaymentResult.Map <Guid>());
        }
Пример #3
0
        /// <summary>
        /// Add payment
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="payment"></param>
        /// <returns></returns>
        public async Task <ResultModel> AddPaymentAsync(Guid?orderId, Payment payment)
        {
            var orderRequest = await _orderProductService.GetOrderByIdAsync(orderId);

            if (!orderRequest.IsSuccess)
            {
                return(orderRequest.ToBase());
            }
            payment.OrderId = orderId.GetValueOrDefault();
            await _paymentContext.Payments.AddAsync(payment);

            return(await _paymentContext.PushAsync());
        }