public SellApartmentWizard(ApartmentDataGrid SelectedApartment = null) { DataContext = this; InitializeComponent(); SellDate = DateTime.Today; using (var db = new DB.DomenaDBContext()) { BuildingsNames = new ObservableCollection <Building>(db.Buildings.ToList()); ApartmentNames = new ObservableCollection <Apartment>(db.Apartments.ToList()); BuyersList = new ObservableCollection <Owner>(db.Owners.ToList()); } SelectedApartmentName = ApartmentNames.FirstOrDefault(x => x.ApartmentId == SelectedApartment.ApartmentId); SelectedBuildingName = BuildingsNames.FirstOrDefault(x => x.BuildingId == SelectedApartmentName.BuildingId); var owner = BuyersList.FirstOrDefault(x => x.OwnerId == SelectedApartmentName.OwnerId); OwnerFirstName = owner.OwnerName; OwnerSurname = owner.OwnerSurname; LocatorsAmount = 1; }
private void InitializeApartments(IQueryable <Apartment> q) { using (var db = new DB.DomenaDBContext()) { foreach (var apar in q) { var a = new ApartmentDataGrid { ApartmentBinding = apar.BindingParent, BuildingName = db.Buildings.Where(x => x.BuildingId == apar.BuildingId).FirstOrDefault().Name, BulidingAddress = db.Buildings.Where(x => x.BuildingId == apar.BuildingId).FirstOrDefault().GetAddress(), ApartmentId = apar.ApartmentId, ApartmentNumber = apar.ApartmentNumber, ApartmentArea = apar.ApartmentArea, ApartmentAdditionalArea = apar.AdditionalArea, ApartmentTotalArea = apar.ApartmentArea + apar.AdditionalArea, ApartmentOwner = db.Owners.Where(x => x.OwnerId == apar.OwnerId).FirstOrDefault().OwnerName, ApartmentPercentageDistribution = (100 * (apar.ApartmentArea + apar.AdditionalArea) / db.Apartments .Where(x => x.BuildingId == apar.BuildingId && !x.IsDeleted && x.SoldDate == null) .Select(x => x.AdditionalArea + x.ApartmentArea) .Sum()).ToString("0.00") + " %", BoughtDate = apar.BoughtDate, ApartmentOwnerAddress = db.Owners.Where(x => x.OwnerId == apar.OwnerId).FirstOrDefault().MailAddress, LocatorsAmount = apar.Locators, SoldDate = apar.SoldDate, ApartmentAreaSeries = new SeriesCollection { new PieSeries { Title = "Powierzchnia mieszkania (m2)", Values = new ChartValues <ObservableValue> { new ObservableValue(apar.ApartmentArea) }, LabelPoint = chartPoint => string.Format("{0} m2 ({1:P})", chartPoint.Y, chartPoint.Participation) }, new PieSeries { Title = "Powierzchnie przynależne (m2)", Values = new ChartValues <ObservableValue> { new ObservableValue(apar.AdditionalArea) }, LabelPoint = chartPoint => string.Format("{0} m2 ({1:P})", chartPoint.Y, chartPoint.Participation) } }, BuildingAreaSeries = new SeriesCollection { new PieSeries { Title = "Całkowita powierzchnia (m2)", Values = new ChartValues <ObservableValue> { new ObservableValue(apar.ApartmentArea + apar.AdditionalArea) }, LabelPoint = chartPoint => string.Format("{0} m2 ({1:P})", chartPoint.Y, chartPoint.Participation) }, new PieSeries { Title = "Reszta budynku (m2)", Values = new ChartValues <ObservableValue> { new ObservableValue( db.Apartments.Where(x => x.BuildingId == apar.BuildingId && x.ApartmentId != apar.ApartmentId && x.IsDeleted == false && x.SoldDate == null).Select(x => x.ApartmentArea).DefaultIfEmpty(0).Sum() + db.Apartments.Where(x => x.BuildingId == apar.BuildingId && x.ApartmentId != apar.ApartmentId && x.IsDeleted == false && x.SoldDate == null).Select(x => x.AdditionalArea).DefaultIfEmpty(0).Sum() ) }, LabelPoint = chartPoint => string.Format("{0} m2 ({1:P})", chartPoint.Y, chartPoint.Participation) } }, }; a.Balance = Math.Floor(100 * (Payments.CalculateSaldo(DateTime.Today.Year, db.Apartments.FirstOrDefault(x => x.ApartmentId.Equals(a.ApartmentId))))) / 100; a.CostHistory = new ObservableCollection <string>(db.Charges.Include(x => x.Components).Where(x => x.ApartmentId.Equals(a.ApartmentId) && !x.IsDeleted).OrderByDescending(x => x.ChargeDate).Take(5).ToList().Select(x => new { costConc = x.ChargeDate.ToString("dd-MM-yyyy") + " : " + x.Components.Select(y => y.Sum).DefaultIfEmpty(0).Sum() + " zł" }).Select(x => x.costConc).ToList()); a.PaymentHistory = new ObservableCollection <string>(db.Payments.Where(x => !x.IsDeleted && x.ApartmentId.Equals(a.ApartmentId)).OrderByDescending(x => x.PaymentRegistrationDate).Take(5).ToList().Select(x => new { paymConc = x.PaymentRegistrationDate.ToString("dd-MM-yyyy") + " : " + x.PaymentAmount + " zł" }).Select(x => x.paymConc).ToList()); Apartments.Add(a); } } }