public async Task ReCalculateChargeAsync(int apartmentId, DateTime from, DateTime?to) { to ??= DateTime.MaxValue; var buildingId = await _buildingRepository.GetBuildingIdByApartmentId(apartmentId); var calculatedCharges = await _chargeRepository.GetBuildingCharges(buildingId, from, to.Value); var expenses = await _expenseRepository.GetChargeExpenseAsync(from, to.Value); var building = await _buildingRepository.GetChargeBuildingAsync(buildingId); var charges = new List <Charge>(); foreach (var charge in calculatedCharges) { charges.AddRange(building.CalculateCharge(charge.From, charge.To, expenses)); } foreach (var charge in charges) { _chargeRepository.AddCharge(charge); } foreach (var charge in calculatedCharges) { _chargeRepository.DeleteCharge(charge.ChargeId); } await _chargeRepository.Commit(); }
public async Task <int> GetBuildingIdOfOwnerTenant(int apartmentId) { var buildingId = await _buildingrepository.GetBuildingIdByApartmentId(apartmentId); return(buildingId); }