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); }
public async Task <CanteenBalance> TopUpStudentAsync(CanteenBalance canteenBalance) { await _unitOfWork.CanteenBalanceRepository.AddAsync(canteenBalance); var commitAsync = await _unitOfWork.CommitAsync(); if (commitAsync > 0) { return(canteenBalance); } return(null); }