コード例 #1
0
ファイル: InvoiceService.cs プロジェクト: andres1447/FriMav
        private Customer GetRequestCustomer(InvoiceCreate request)
        {
            var customer = _customerRepository.Get(request.PersonId, x => x.CustomerPrices);

            if (customer == null)
            {
                throw new NotFoundException();
            }
            return(customer);
        }
コード例 #2
0
ファイル: InvoiceService.cs プロジェクト: andres1447/FriMav
        private List <InvoiceItem> MapInvoiceItems(InvoiceCreate request)
        {
            var products = GetInvoiceProducts(request);

            return(request.Items.Join(products, x => x.ProductId, x => x.Id, (x, y) => new InvoiceItem
            {
                Price = x.Price,
                Quantity = x.Quantity,
                ProductId = x.ProductId,
                ProductName = y.Name
            }).ToList());
        }
コード例 #3
0
ファイル: InvoiceService.cs プロジェクト: andres1447/FriMav
        private Invoice MapInvoice(InvoiceCreate request, Customer customer)
        {
            var invoice = new Invoice
            {
                Person          = customer,
                PersonId        = customer.Id,
                CustomerName    = request.CustomerName,
                Shipping        = request.Shipping ?? customer.Shipping ?? Shipping.Self,
                PaymentMethod   = request.PaymentMethod ?? customer.PaymentMethod ?? PaymentMethod.Cash,
                Number          = _documentNumberGenerator.NextForInvoice(),
                DeliveryAddress = request.DeliveryAddress,
                Items           = MapInvoiceItems(request)
            };

            invoice.Total = invoice.CalculateTotal();
            return(invoice);
        }
コード例 #4
0
ファイル: InvoiceService.cs プロジェクト: andres1447/FriMav
        public InvoiceResult Create(InvoiceCreate request)
        {
            var customer = GetRequestCustomer(request);

            var invoice = MapInvoice(request, customer);

            customer.Accept(invoice);

            _invoiceRepository.Add(invoice);

            if (request.PaymentMethod == PaymentMethod.Cash)
            {
                CreateCancellingPayment(invoice, customer);
            }

            UpdateCustomerPrices(customer, invoice);

            return(new InvoiceResult(invoice.Number, invoice.Total, invoice.Balance));
        }
コード例 #5
0
ファイル: InvoiceService.cs プロジェクト: andres1447/FriMav
        private IEnumerable <Product> GetInvoiceProducts(InvoiceCreate request)
        {
            var productIds = request.Items.Select(x => x.ProductId).ToList();

            return(_productRepository.Query().Where(x => productIds.Contains(x.Id)).ToList());
        }