コード例 #1
0
        public void Create(GoodsSoldCreate request)
        {
            var employee  = _employeeRepository.GetById(request.EmployeeId);
            var goodsSold = MapGoodsSold(request, employee);

            _goodsSoldRepository.Add(goodsSold);
        }
コード例 #2
0
 private static List <GoodsSoldItem> MapItems(GoodsSoldCreate request, IQueryable <Product> products)
 {
     return(request.Items.Select(x => new GoodsSoldItem
     {
         ProductId = x.ProductId,
         ProductName = products.First(p => p.Id == x.ProductId).Name,
         Quantity = x.Quantity,
         Price = x.Price
     }).ToList());
 }
コード例 #3
0
        private GoodsSold MapGoodsSold(GoodsSoldCreate request, Employee employee)
        {
            var productIds = request.Items.Select(x => x.ProductId).ToList();
            var products   = _productRepository.Query().Where(x => productIds.Contains(x.Id));

            return(new GoodsSold
            {
                Employee = employee,
                EmployeeId = employee.Id,
                Amount = -CalculateTotal(request),
                Items = MapItems(request, products)
            });
        }
コード例 #4
0
 private static decimal CalculateTotal(GoodsSoldCreate request)
 {
     return(request.Items.Select(x => x.Quantity * x.Price).DefaultIfEmpty(0).Sum());
 }