Beispiel #1
0
        public IActionResult AddReceipt(AddReceiptDto addReceiptDto)
        {
            var createdReceiptId = _receiptRepository.AddReceipt(addReceiptDto);

            if (createdReceiptId != Guid.Empty)
            {
                return(Ok(createdReceiptId));
            }
            return(Forbid());
        }
Beispiel #2
0
 private static bool IsReceiptNonValid(AddReceiptDto receipt)
 {
     return(receipt.TaxFreePrice < 0 ||
            receipt.TotalExciseTax < 0 ||
            receipt.TotalDirectTax < 0 ||
            receipt.TotalPrice < 0 ||
            receipt.Products.Count <= 0 ||
            !receipt.Products.All(p => p.Quantity <= p.AvailableQuantity && p.Price > 0) ||
            receipt.CashRegisterId == 0 ||
            receipt.CashierId == 0);
 }
Beispiel #3
0
        public async Task <IActionResult> AddReceipt(AddReceiptDto newReceipt)
        {
            var serviceResponse = await _receiptService.AddReceipt(newReceipt);

            if (serviceResponse.Success == false)
            {
                return(NotFound(serviceResponse));
            }
            else
            {
                return(Ok(serviceResponse));
            }
        }
Beispiel #4
0
        async public Task <ServiceResponse <List <GetReceiptDto> > > AddReceipt(AddReceiptDto newReceipt)
        {
            ServiceResponse <List <GetReceiptDto> > serviceResponse = new ServiceResponse <List <GetReceiptDto> >();

            var receipt = _mapper.Map <Receipt>(newReceipt);

            receipt.UserId = GetUserId();
            await _context.Receipts.AddAsync(receipt);

            await _context.SaveChangesAsync();

            serviceResponse.Data = (_context.Receipts.Where(c => c.User.Id == GetUserId()).Select(c => _mapper.Map <GetReceiptDto>(c))).ToList();
            return(serviceResponse);
        }
Beispiel #5
0
        private void AddProductsOnReceiptAndChangeAq(Guid receiptId, AddReceiptDto addReceiptDto)
        {
            foreach (var product in addReceiptDto.Products)
            {
                _context.ReceiptProducts
                .Add(new ReceiptProduct(
                         receiptId,
                         product.Id,
                         product.Quantity,
                         product.Price,
                         product.TaxType));

                var addedProduct = _context.Products.Find(product.Id);
                addedProduct.AvailableQuantity -= product.Quantity;
            }
        }
Beispiel #6
0
        public Guid AddReceipt(AddReceiptDto addReceiptDto)
        {
            if (IsReceiptNonValid(addReceiptDto))
            {
                return(Guid.Empty);
            }

            var cashRegister = _context.CashRegisters.Find(addReceiptDto.CashRegisterId);

            if (cashRegister == null)
            {
                return(Guid.Empty);
            }

            var cashier = _context.Cashiers.Find(addReceiptDto.CashierId);

            if (cashier == null)
            {
                return(Guid.Empty);
            }

            var receiptToAdd = new Receipt(
                DateTime.Now,
                addReceiptDto.TaxFreePrice,
                addReceiptDto.TotalExciseTax,
                addReceiptDto.TotalDirectTax,
                addReceiptDto.TotalPrice,
                cashRegister,
                cashier);

            _context.Receipts.Add(receiptToAdd);

            AddProductsOnReceiptAndChangeAq(receiptToAdd.Id, addReceiptDto);

            _context.SaveChanges();
            return(receiptToAdd.Id);
        }