Beispiel #1
0
        /// <inheritdoc/>
        public async Task <SalesItemDetails> AddItemToSaleAsync(SaleItemModel saleItem, CancellationToken cancellationToken)
        {
            // ToDo: Cache products.
            var product = await this.productService.GetProductByIdAsync(saleItem.ProductId, cancellationToken);

            return(await this.salesRepository.AddItemToSaleAsync(
                       new SaleItem()
            {
                ProductId = saleItem.ProductId,
                Price = product.SalesPrice,
                Vat = 00.00m,
                Quantity = saleItem.Quantity,
                Total = saleItem.Quantity *product.SalesPrice,
            },
                       cancellationToken));
        }
Beispiel #2
0
        private static SaleItem ToEntity(Repository repository, IEnumerable <Product> products, SaleItemModel model)
        {
            if (!model.IsValid())
            {
                return(null);
            }

            return(new SaleItem
            {
                Product = products.FirstOrDefault(it => it.Name == model.ProductName)
                          ?? repository.Products.Add(new Product {
                    Name = model.ProductName
                }),
                Quantity = decimal.Parse(model.Quantity),
                Price = decimal.Parse(model.Price),
            });
        }