public async Task GenerateTaxes(int realEstateId, TaxesGenerateInputModel inputModel) { var properties = this.propertyRepository .All() .Where(x => x.RealEstateId == realEstateId) .ToList(); var taxes = new List <Tax>(); foreach (var prop in properties) { var tax = new Tax { Year = inputModel.Year, Month = inputModel.Month, RealEstateId = realEstateId, PropertyId = prop.Id, PropertyTax = prop.PropertyFee.Price, ResidentsTax = prop.Residents.Sum(x => x.ResidentFee.Price), AnimalTax = prop.Animals.Sum(x => x.AnimalFee.Price), Total = prop.PropertyFee.Price + prop.Residents.Sum(x => x.ResidentFee.Price), }; await this.taxRepository.AddAsync(tax); } await this.taxRepository.SaveChangesAsync(); }
public async Task <IActionResult> Generate(int realEstateId, TaxesGenerateInputModel inputModel) { this.ViewBag.realEstateId = realEstateId; await this.taxesService.GenerateTaxes(realEstateId, inputModel); return(this.RedirectToAction("All", new { realEstateId })); }