private void UpdateApartmentsNumbers() { if (SelectedBuilding != null) { ApartmentsNumbersCollection = new ObservableCollection <int>(ApartmentsCollection.Where(x => x.BuildingId.Equals(SelectedBuilding.BuildingId)).Select(x => x.ApartmentNumber).ToList().OrderBy(x => x)); SelectedApartmentNumberValue = null; } else { ApartmentsNumbersCollection = new ObservableCollection <int>(); SelectedApartmentNumberValue = null; } }
private void CalculateSum() { double uc; if (!double.TryParse(UnitCost, out uc) || SelectedCategoryName == null || SelectedUnitName == null || SelectedApartmentNumberValue == null || SelectedBuilding == null) { return; } double units; var a = ApartmentsCollection.FirstOrDefault(x => x.BuildingId.Equals(SelectedBuilding.BuildingId) && x.ApartmentNumber.Equals(SelectedApartmentNumber)); switch ((CostDistribution)SelectedUnitName.EnumValue) { case CostDistribution.PerApartment: units = 1; break; case CostDistribution.PerApartmentTotalArea: units = a.AdditionalArea + a.ApartmentArea; break; case CostDistribution.PerApartmentArea: units = a.ApartmentArea; break; case CostDistribution.PerAdditionalArea: units = a.AdditionalArea; break; case CostDistribution.PerLocators: var ap = ApartmentsCollection.FirstOrDefault(x => x.BuildingId.Equals(SelectedBuilding.BuildingId) && x.ApartmentNumber.Equals(SelectedApartmentNumber)); units = ap.Locators; break; default: units = 0; break; } ChargeSum = (Math.Round((units * uc), 2)).ToString(); }