Beispiel #1
0
        public async Task <BillStudentResourceDto> BillStudent(BillStudentResourceDto bill)
        {
            var studentByRefAsync = await _unitOfWork.Students.GetStudentByRefAsync(bill.StudentRef);

            var canteenPriceList = await _unitOfWork.CanteenPriceListRepository.GetByIdAsync(bill.Amount);

            var canteenBalances =
                CanteenBalances(studentByRefAsync);
            var calculatedBalance = await CalculateBalance(canteenBalances);

            if (calculatedBalance - Double.Parse(canteenPriceList.Price) >= 0)
            {
                var canteenBalance = new CanteenBalance();
                canteenBalance.Student = studentByRefAsync.Id;
                canteenBalance.Date    = DateTime.Now;
                canteenBalance.Dr      = Double.Parse(canteenPriceList.Price);
                await _unitOfWork.CanteenBalanceRepository.AddAsync(canteenBalance);

                await _unitOfWork.CommitAsync();

                return(bill);
            }

            return(null);
        }
Beispiel #2
0
        public async Task <IActionResult> BillStudent([FromBody] BillStudentResourceDto bill)
        {
            var billStudentResourceDto = await _canteenService.BillStudent(bill);

            if (billStudentResourceDto != null)
            {
                return(Ok());
            }
            return(BadRequest("Insufficient funds"));
        }