コード例 #1
0
        public async Task <IActionResult> AddToReceipt(ReceiptForCreationDto receiptForCreation)
        {
            var itemToRepo      = _mapper.Map <Receipt>(receiptForCreation);
            var productFromRepo = await _productRepo.AllItems.Where(p => p.ProductName == receiptForCreation.ProductName).FirstOrDefaultAsync();

            if (productFromRepo != null)
            {
                itemToRepo.ProductId        = productFromRepo.Id;
                itemToRepo.Sum              = itemToRepo.Quantity * productFromRepo.Cost;
                productFromRepo.IsAvailable = true;
            }
            if (await _repo.AddItemAsync(itemToRepo))
            {
                return(Ok());
            }
            return(BadRequest());
        }