示例#1
0
        private void AddApartment(object param)
        {
            Wizards.EditApartmentWizard eaw = new Wizards.EditApartmentWizard();

            //var result = await DialogHost.Show(eaw, "RootDialog", ExtendedOpenedEventHandler, ExtendedClosingEventHandler);
            SwitchPage.SwitchMainPage(eaw, this);
        }
示例#2
0
        private void CancelSettlement(object param)
        {
            //var mw = (((((this.Parent as MahApps.Metro.Controls.TransitioningContentControl).Parent as Grid).Parent as DialogHost).Parent as DialogHost).Parent as DialogHost).Parent as Windows.MainWindow;

            var CurrentPage = _settlementPage;

            SwitchPage.SwitchMainPage(CurrentPage, this);
        }
        private async void Add(object param)
        {
            Wizards.EditChargeWizard ecw;

            ecw = new Wizards.EditChargeWizard(null);
            
            SwitchPage.SwitchMainPage(ecw, this);
        }
 private void Edit(object param)
 {
     if (SelectedInvoice != null)
     {
         var eiw = new Wizards.EditInvoiceWizard(SelectedInvoice);
         SwitchPage.SwitchMainPage(eiw, this);
     }
 }
示例#5
0
 private void AcceptDialog(object param)
 {
     if (!IsValid(this as DependencyObject) || (string.IsNullOrEmpty(this.OwnerFirstName) || string.IsNullOrEmpty(this.OwnerSurname) || string.IsNullOrEmpty(this.MailAddress)))
     {
         return;
     }
     SaveDialog(null);
     SwitchPage.SwitchMainPage(new Pages.OwnersPage(), this);
 }
示例#6
0
 private void ShowPayments(object param)
 {
     //var mw = (((((this.Parent as MahApps.Metro.Controls.TransitioningContentControl).Parent as Grid).Parent as DialogHost).Parent as DialogHost).Parent as DialogHost).Parent as Windows.MainWindow;
     using (var db = new DB.DomenaDBContext())
     {
         var CurrentPage = new PaymentsPage(db.Apartments.FirstOrDefault(x => x.ApartmentId.Equals(SelectedApartment.ApartmentId)));
         SwitchPage.SwitchMainPage(CurrentPage, this);
     }
 }
        private void Summary(object param)
        {
            if (IsValid(ucSettlement as DependencyObject))
            {
                //var mw = (((((this.Parent as MahApps.Metro.Controls.TransitioningContentControl).Parent as Grid).Parent as DialogHost).Parent as DialogHost).Parent as DialogHost).Parent as Windows.MainWindow;

                var CurrentPage = new SettlementSummaryPage(this);
                SwitchPage.SwitchMainPage(CurrentPage, this);
            }
        }
示例#8
0
        private async void ShowDetails(object param)
        {
            if (SelectedCharge != null)
            {
                Wizards.PreviewChargeWizard pcw;

                pcw = new Wizards.PreviewChargeWizard(SelectedCharge);

                SwitchPage.SwitchMainPage(pcw, this);
            }
        }
        private async void Edit(object param)
        {
            if (SelectedCharge != null)
            {
                Wizards.EditChargeWizard ecw;

                ecw = new Wizards.EditChargeWizard(SelectedCharge);

                SwitchPage.SwitchMainPage(ecw, this);
            }
        }
示例#10
0
        private void EditOwner(object param)
        {
            Wizards.EditOwnerWizard eow;
            using (var db = new DB.DomenaDBContext())
            {
                var so = db.Owners.Where(x => x.OwnerId.Equals(SelectedOwner.OwnerId)).FirstOrDefault();
                eow = new Wizards.EditOwnerWizard(so);
            }

            SwitchPage.SwitchMainPage(eow, this);
        }
示例#11
0
        private async void EditApartment(object param)
        {
            Wizards.EditApartmentWizard eaw;
            using (var db = new DB.DomenaDBContext())
            {
                var sa = db.Apartments.Include(x => x.MeterCollection.Select(y => y.MeterTypeParent)).Include(x => x.MeterCollection).Where(x => x.ApartmentId.Equals(SelectedApartment.ApartmentId)).FirstOrDefault();
                eaw = new Wizards.EditApartmentWizard(sa);
            }

            //var result = await DialogHost.Show(eaw, "RootDialog", ExtendedOpenedEventHandler, ExtendedClosingEventHandler);
            SwitchPage.SwitchMainPage(eaw, this);
        }
示例#12
0
        private void SaveDialog(object param)
        {
            if (!IsValid(this as DependencyObject) || SelectedBuilding == null || ChargeDate == null)
            {
                return;
            }

            var charges = new List <Charge>();

            using (var db = new DB.DomenaDBContext())
            {
                var apartments = db.Apartments.Where(x => !x.IsDeleted && x.SoldDate == null && x.BuildingId == SelectedBuilding.BuildingId).ToList();

                foreach (var ap in apartments)
                {
                    var newCharge = new LibDataModel.Charge();
                    newCharge.SettlementId = Guid.Empty;
                    newCharge.ChargeId     = Guid.NewGuid();
                    newCharge.ApartmentId  = ap.ApartmentId;
                    newCharge.CreatedDate  = DateTime.Today;
                    newCharge.ChargeDate   = ChargeDate;
                    newCharge.IsClosed     = false;
                    newCharge.IsDeleted    = false;
                    newCharge.OwnerId      = ap.OwnerId;

                    db.Charges.Add(newCharge);
                    charges.Add(newCharge);
                }
                db.SaveChanges();
            }

            foreach (var c in charges)
            {
                ChargesOperations.RecalculateCharge(c);
            }

            SwitchPage.SwitchMainPage(new Pages.ChargesPage(), this);
        }
示例#13
0
        public void Accept(object param)
        {
            // Edit building
            if (_localBuildingCopy != null)
            {
                using (var db = new DB.DomenaDBContext())
                {
                    var selectedBuilding = db.Buildings.Include(x => x.CostCollection).Include(x => x.MeterCollection).FirstOrDefault(x => x.BuildingId == _localBuildingCopy.BuildingId);

                    #region MasterData

                    selectedBuilding.BuildingNumber = masterDataView.BuildingRoadNumber;
                    selectedBuilding.City           = masterDataView.BuildingCity;
                    selectedBuilding.FullName       = masterDataView.BuildingFullName;
                    selectedBuilding.Name           = masterDataView.BuildingName;
                    selectedBuilding.RoadName       = masterDataView.BuildingRoadName;
                    selectedBuilding.ZipCode        = masterDataView.BuildingZipCode;

                    #endregion

                    #region Charges

                    while (selectedBuilding.CostCollection.Count > 0)
                    {
                        db.Entry(selectedBuilding.CostCollection[0]).State = EntityState.Deleted;
                    }

                    List <BuildingChargeBasis> costs = new List <BuildingChargeBasis>();
                    foreach (var c in chargesView.CostCollection)
                    {
                        var catId = db.CostCategories.Where(x => x.CategoryName.Equals(c.CategoryName)).FirstOrDefault().BuildingChargeBasisCategoryId;
                        var cost  = new BuildingChargeBasis {
                            BuildingChargeBasisId = Guid.NewGuid(), BegginingDate = c.BegginingDate.Date, EndingDate = c.EndingDate.Date, CostPerUnit = c.Cost, BuildingChargeBasisDistribution = c.CostUnit.EnumValue, BuildingChargeBasisCategoryId = catId, BuildingChargeGroupNameId = c.CostGroup.BuildingChargeGroupNameId
                        };
                        costs.Add(cost);
                    }
                    selectedBuilding.CostCollection = costs;

                    var buildingBankAddresses = db.BuildingChargeGroupBankAccounts.Where(x => x.Building.BuildingId == selectedBuilding.BuildingId).ToList();

                    //Add new
                    foreach (var bba in chargesView.GroupBankAccounts)
                    {
                        if (!buildingBankAddresses.Any(x => x.BuildingChargeGroupBankAccountId == bba.BuildingChargeGroupBankAccountId))
                        {
                            bba.Building = selectedBuilding;
                            db.BuildingChargeGroupBankAccounts.Add(bba);
                            db.Entry(bba.GroupName).State = EntityState.Unchanged;
                            db.Entry(bba.Building).State  = EntityState.Unchanged;
                        }
                    }
                    //Remove necessary
                    for (int i = buildingBankAddresses.Count - 1; i >= 0; i--)
                    {
                        if (!chargesView.GroupBankAccounts.Any(x => x.BuildingChargeGroupBankAccountId.Equals(buildingBankAddresses[i].BuildingChargeGroupBankAccountId)))
                        {
                            buildingBankAddresses[i].IsDeleted = true;
                        }
                        else
                        {
                            // Change names
                            buildingBankAddresses[i].BankAccount = chargesView.GroupBankAccounts.FirstOrDefault(x => x.BuildingChargeGroupBankAccountId == buildingBankAddresses[i].BuildingChargeGroupBankAccountId).BankAccount;
                            buildingBankAddresses[i].GroupName   = chargesView.GroupBankAccounts.FirstOrDefault(x => x.BuildingChargeGroupBankAccountId == buildingBankAddresses[i].BuildingChargeGroupBankAccountId).GroupName;

                            //db.Entry(buildingBankAddresses[i].Building).State = EntityState.Unchanged;
                            db.Entry(buildingBankAddresses[i].GroupName).State = EntityState.Unchanged;
                        }
                    }

                    #endregion

                    #region Meters

                    //Add new
                    foreach (var m in countersView.MetersCollection)
                    {
                        if (!selectedBuilding.MeterCollection.Any(x => x.MeterId.Equals(m.MeterId)))
                        {
                            selectedBuilding.MeterCollection.Add(m);
                        }
                    }
                    //Remove necessary
                    for (int i = selectedBuilding.MeterCollection.Count - 1; i >= 0; i--)
                    {
                        if (!countersView.MetersCollection.Any(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)))
                        {
                            selectedBuilding.MeterCollection.RemoveAt(i);
                        }
                        else
                        {
                            // Change names
                            selectedBuilding.MeterCollection[i].Name = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).Name;
                            if (selectedBuilding.MeterCollection[i].LastMeasure != countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure)
                            {
                                var nm = new MetersHistory
                                {
                                    MeterHistoryId = Guid.NewGuid(),
                                    Apartment      = null,
                                    ApartmentMeter = null,
                                    Building       = selectedBuilding,
                                    MeterType      = selectedBuilding.MeterCollection[i],
                                    ModifiedDate   = DateTime.Now,
                                    NewValue       = selectedBuilding.MeterCollection[i].LastMeasure,
                                    OldValue       = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure,
                                };
                                db.MetersHistories.Add(nm);
                                db.Entry(nm.Building).State = EntityState.Unchanged;

                                selectedBuilding.MeterCollection[i].LastMeasure = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure;
                            }
                            selectedBuilding.MeterCollection[i].IsBuilding  = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).IsBuilding;
                            selectedBuilding.MeterCollection[i].IsApartment = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).IsApartment;
                        }
                    }

                    #endregion

                    #region Invoices

                    foreach (var inv in invoicesView.BuildingInvoiceBindings)
                    {
                        var binding = db.BuildingInvoceBindings.FirstOrDefault(x => x.BindingId == inv.BindingId);
                        if (binding == null) // add new
                        {
                            db.BuildingInvoceBindings.Add(
                                new BuildingInvoiceBinding()
                            {
                                BindingId       = inv.BindingId,
                                Building        = selectedBuilding,
                                Distribution    = inv.Distribution,
                                InvoiceCategory = inv.InvoiceCategory,
                                IsDeleted       = inv.IsDeleted,
                            });
                            db.Entry(inv.InvoiceCategory).State = EntityState.Unchanged;
                            //db.Entry(selectedBuilding).State = EntityState.Unchanged;
                        }
                        else // edit existing
                        {
                            binding.Distribution                = inv.Distribution;
                            binding.InvoiceCategory             = inv.InvoiceCategory;
                            binding.IsDeleted                   = inv.IsDeleted;
                            db.Entry(inv.InvoiceCategory).State = EntityState.Unchanged;
                        }
                    }

                    // Mark IsDeleted deleted entries
                    var bindings = db.BuildingInvoceBindings.Where(x => !x.IsDeleted && x.Building.BuildingId == selectedBuilding.BuildingId);
                    foreach (var b in bindings)
                    {
                        if (!invoicesView.BuildingInvoiceBindings.Any(x => x.BindingId == b.BindingId))
                        {
                            b.IsDeleted = true;
                        }
                    }

                    #endregion

                    db.SaveChanges();

                    // Add meters to building

                    #region Meters

                    selectedBuilding = db.Buildings.Include(x => x.CostCollection).Include(x => x.MeterCollection).FirstOrDefault(x => x.BuildingId == _localBuildingCopy.BuildingId);

                    if (selectedBuilding.MeterCollection != null || selectedBuilding.MeterCollection.Count > 0)
                    {
                        foreach (var a in db.Apartments.Include(x => x.MeterCollection).Where(x => !x.IsDeleted && x.BuildingId == selectedBuilding.BuildingId))
                        {
                            if (a.MeterCollection == null || a.MeterCollection.Count == 0)
                            {
                                a.MeterCollection = new List <ApartmentMeter>();
                                foreach (var m in selectedBuilding.MeterCollection.Where(x => !x.IsDeleted && x.IsApartment))
                                {
                                    a.MeterCollection.Add(new ApartmentMeter()
                                    {
                                        IsDeleted = m.IsDeleted, MeterTypeParent = m, MeterId = Guid.NewGuid(), LegalizationDate = DateTime.Today.AddDays(-1)
                                    });
                                }
                            }
                            else if (a.MeterCollection != null && a.MeterCollection.Count > 0)
                            {
                                for (int i = selectedBuilding.MeterCollection.Count - 1; i >= 0; i--)
                                {
                                    if (!a.MeterCollection.Any(x => x.MeterTypeParent.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)) && selectedBuilding.MeterCollection[i].IsApartment)
                                    {
                                        a.MeterCollection.Add(new ApartmentMeter()
                                        {
                                            MeterId = Guid.NewGuid(), MeterTypeParent = selectedBuilding.MeterCollection[i], IsDeleted = false, LastMeasure = 0, LegalizationDate = DateTime.Today.AddDays(-1)
                                        });
                                    }
                                    else if (selectedBuilding.MeterCollection[i].IsApartment)
                                    {
                                        a.MeterCollection.FirstOrDefault(x => x.MeterTypeParent.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).IsDeleted = false;
                                    }
                                }
                                for (int i = a.MeterCollection.Count - 1; i >= 0; i--)
                                {
                                    if (!selectedBuilding.MeterCollection.Any(x => x.MeterId.Equals(a.MeterCollection[i].MeterTypeParent.MeterId)))
                                    {
                                        a.MeterCollection.RemoveAt(i);
                                    }
                                }
                            }
                        }
                        db.SaveChanges();
                    }

                    #endregion
                }
            }
            // New building
            else
            {
                using (var db = new DB.DomenaDBContext())
                {
                    var selectedBuilding = new Building()
                    {
                        BuildingId = Guid.NewGuid(),
                    };

                    #region MasterData

                    selectedBuilding.BuildingNumber = masterDataView.BuildingRoadNumber;
                    selectedBuilding.City           = masterDataView.BuildingCity;
                    selectedBuilding.FullName       = masterDataView.BuildingFullName;
                    selectedBuilding.Name           = masterDataView.BuildingName;
                    selectedBuilding.RoadName       = masterDataView.BuildingRoadName;
                    selectedBuilding.ZipCode        = masterDataView.BuildingZipCode;

                    #endregion

                    db.Buildings.Add(selectedBuilding);
                    db.SaveChanges();

                    selectedBuilding = db.Buildings.Include(x => x.CostCollection).Include(x => x.MeterCollection).FirstOrDefault(x => x.BuildingId == selectedBuilding.BuildingId);

                    #region Charges

                    while (selectedBuilding.CostCollection.Count > 0)
                    {
                        db.Entry(selectedBuilding.CostCollection[0]).State = EntityState.Deleted;
                    }

                    List <BuildingChargeBasis> costs = new List <BuildingChargeBasis>();
                    foreach (var c in chargesView.CostCollection)
                    {
                        var catId = db.CostCategories.Where(x => x.CategoryName.Equals(c.CategoryName)).FirstOrDefault().BuildingChargeBasisCategoryId;
                        var cost  = new BuildingChargeBasis {
                            BuildingChargeBasisId = Guid.NewGuid(), BegginingDate = c.BegginingDate.Date, EndingDate = c.EndingDate.Date, CostPerUnit = c.Cost, BuildingChargeBasisDistribution = c.CostUnit.EnumValue, BuildingChargeBasisCategoryId = catId, BuildingChargeGroupNameId = c.CostGroup.BuildingChargeGroupNameId
                        };
                        costs.Add(cost);
                    }
                    selectedBuilding.CostCollection = costs;

                    var buildingBankAddresses = db.BuildingChargeGroupBankAccounts.Where(x => x.Building.BuildingId == selectedBuilding.BuildingId).ToList();

                    //Add new
                    foreach (var bba in chargesView.GroupBankAccounts)
                    {
                        if (!buildingBankAddresses.Any(x => x.BuildingChargeGroupBankAccountId == bba.BuildingChargeGroupBankAccountId))
                        {
                            bba.Building = selectedBuilding;
                            db.BuildingChargeGroupBankAccounts.Add(bba);
                            db.Entry(bba.GroupName).State = EntityState.Unchanged;
                            db.Entry(bba.Building).State  = EntityState.Unchanged;
                        }
                    }
                    //Remove necessary
                    for (int i = buildingBankAddresses.Count - 1; i >= 0; i--)
                    {
                        if (!chargesView.GroupBankAccounts.Any(x => x.BuildingChargeGroupBankAccountId.Equals(buildingBankAddresses[i].BuildingChargeGroupBankAccountId)))
                        {
                            buildingBankAddresses[i].IsDeleted = true;
                        }
                        else
                        {
                            // Change names
                            buildingBankAddresses[i].BankAccount = chargesView.GroupBankAccounts.FirstOrDefault(x => x.BuildingChargeGroupBankAccountId == buildingBankAddresses[i].BuildingChargeGroupBankAccountId).BankAccount;
                            buildingBankAddresses[i].GroupName   = chargesView.GroupBankAccounts.FirstOrDefault(x => x.BuildingChargeGroupBankAccountId == buildingBankAddresses[i].BuildingChargeGroupBankAccountId).GroupName;

                            //db.Entry(buildingBankAddresses[i].Building).State = EntityState.Unchanged;
                            db.Entry(buildingBankAddresses[i].GroupName).State = EntityState.Unchanged;
                        }
                    }

                    #endregion

                    #region Meters

                    //Add new
                    foreach (var m in countersView.MetersCollection)
                    {
                        if (!selectedBuilding.MeterCollection.Any(x => x.MeterId.Equals(m.MeterId)))
                        {
                            selectedBuilding.MeterCollection.Add(m);
                        }
                    }
                    //Remove necessary
                    for (int i = selectedBuilding.MeterCollection.Count - 1; i >= 0; i--)
                    {
                        if (!countersView.MetersCollection.Any(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)))
                        {
                            selectedBuilding.MeterCollection.RemoveAt(i);
                        }
                        else
                        {
                            // Change names
                            selectedBuilding.MeterCollection[i].Name = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).Name;
                            if (selectedBuilding.MeterCollection[i].LastMeasure != countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure)
                            {
                                var nm = new MetersHistory
                                {
                                    MeterHistoryId = Guid.NewGuid(),
                                    Apartment      = null,
                                    ApartmentMeter = null,
                                    Building       = selectedBuilding,
                                    MeterType      = selectedBuilding.MeterCollection[i],
                                    ModifiedDate   = DateTime.Now,
                                    NewValue       = selectedBuilding.MeterCollection[i].LastMeasure,
                                    OldValue       = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure,
                                };
                                db.MetersHistories.Add(nm);
                                db.Entry(nm.Building).State = EntityState.Unchanged;

                                selectedBuilding.MeterCollection[i].LastMeasure = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure;
                            }
                            selectedBuilding.MeterCollection[i].IsBuilding  = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).IsBuilding;
                            selectedBuilding.MeterCollection[i].IsApartment = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).IsApartment;
                        }
                    }

                    #endregion

                    #region Invoices

                    foreach (var inv in invoicesView.BuildingInvoiceBindings)
                    {
                        var binding = db.BuildingInvoceBindings.FirstOrDefault(x => x.BindingId == inv.BindingId);
                        if (binding == null) // add new
                        {
                            db.BuildingInvoceBindings.Add(
                                new BuildingInvoiceBinding()
                            {
                                BindingId       = inv.BindingId,
                                Building        = selectedBuilding,
                                Distribution    = inv.Distribution,
                                InvoiceCategory = inv.InvoiceCategory,
                                IsDeleted       = inv.IsDeleted,
                            });
                            db.Entry(inv.InvoiceCategory).State = EntityState.Unchanged;
                            //db.Entry(selectedBuilding).State = EntityState.Unchanged;
                        }
                        else // edit existing
                        {
                            binding.Distribution                = inv.Distribution;
                            binding.InvoiceCategory             = inv.InvoiceCategory;
                            binding.IsDeleted                   = inv.IsDeleted;
                            db.Entry(inv.InvoiceCategory).State = EntityState.Unchanged;
                        }
                    }

                    // Mark IsDeleted deleted entries
                    var bindings = db.BuildingInvoceBindings.Where(x => !x.IsDeleted && x.Building.BuildingId == selectedBuilding.BuildingId);
                    foreach (var b in bindings)
                    {
                        if (!invoicesView.BuildingInvoiceBindings.Any(x => x.BindingId == b.BindingId))
                        {
                            b.IsDeleted = true;
                        }
                    }

                    #endregion

                    db.SaveChanges();
                }
            }

            SwitchPage.SwitchMainPage(new Pages.BuildingsPage(), this);
        }
        private void SaveDialog(object param)
        {
            var newApartment = new Apartment(SelectedApartmentName);

            newApartment.ApartmentId           = Guid.NewGuid();
            newApartment.Locators              = LocatorsAmount;
            newApartment.OwnerId               = BuyerName.OwnerId;
            newApartment.CorrespondenceAddress = null;
            newApartment.BoughtDate            = SellDate;
            var meters = new List <ApartmentMeter>();

            foreach (var meter in newApartment.MeterCollection)
            {
                var m = new ApartmentMeter()
                {
                    IsDeleted        = meter.IsDeleted,
                    LastMeasure      = meter.LastMeasure,
                    LegalizationDate = meter.LegalizationDate,
                    MeterId          = Guid.NewGuid(),
                    MeterTypeParent  = meter.MeterTypeParent,
                };
            }

            using (var db = new DB.DomenaDBContext())
            {
                db.Apartments.Add(newApartment);
                var soldApartment = db.Apartments.FirstOrDefault(x => x.ApartmentId == SelectedApartmentName.ApartmentId);
                soldApartment.OnSellCreatedApartmentGuid = newApartment.ApartmentId;
                soldApartment.SoldDate = SellDate;

                var dateToCompare = new DateTime(SellDate.Year, SellDate.Month, 1);
                var charges       = db.Charges.Include(x => x.Components).Where(x => x.ApartmentId == SelectedApartmentName.ApartmentId && x.ChargeDate >= dateToCompare && !x.IsDeleted);
                // Charges after sold date to new apartment
                foreach (var charge in charges)
                {
                    charge.ApartmentId = newApartment.ApartmentId;
                    charge.OwnerId     = newApartment.OwnerId;
                }
                charges = charges.Where(x => x.ChargeDate.Month == SellDate.Month && x.ChargeDate.Year == SellDate.Year);
                var ratio = (double)SellDate.Day / (double)DateTime.DaysInMonth(SellDate.Year, SellDate.Month);

                // Charges in month of sale split to 2
                foreach (var charge in charges)
                {
                    var soldApartmentCharge = new Charge()
                    {
                        ApartmentId  = soldApartment.ApartmentId,
                        AutoChargeId = charge.AutoChargeId,
                        ChargeDate   = charge.ChargeDate,
                        ChargeId     = Guid.NewGuid(),
                        CreatedDate  = DateTime.Today,
                        IsClosed     = charge.IsClosed,
                        IsDeleted    = charge.IsDeleted,
                        OwnerId      = soldApartment.OwnerId,
                        SettlementId = charge.SettlementId,
                        Components   = new List <ChargeComponent>(),
                    };

                    foreach (var cc in charge.Components)
                    {
                        var chargeComponent = new ChargeComponent()
                        {
                            ChargeComponentId = Guid.NewGuid(),
                            CostCategoryId    = cc.CostCategoryId,
                            CostDistribution  = cc.CostDistribution,
                            CostPerUnit       = cc.CostPerUnit,
                            GroupName         = cc.GroupName,
                            Sum = Math.Round(cc.Sum * Convert.ToDecimal(ratio), 0),
                        };
                        soldApartmentCharge.Components.Add(chargeComponent);
                        cc.Sum -= chargeComponent.Sum;
                    }

                    db.Charges.Add(soldApartmentCharge);
                }
                db.SaveChanges();
            }

            SwitchPage.SwitchMainPage(new Pages.ApartmentsPage(), this);
        }
示例#15
0
        private void ShowDetails(object param)
        {
            var eiw = new Wizards.EditInvoiceWizard(SelectedInvoice);

            SwitchPage.SwitchMainPage(eiw, this);
        }
 private void AcceptDialog(object param)
 {
     SaveDialog(null);
     SwitchPage.SwitchMainPage(new Pages.ApartmentsPage(), this);
 }
示例#17
0
 private void AddBuildingCharge(object param)
 {
     Wizards.AddBuildingCharge abc;
     abc = new Wizards.AddBuildingCharge();
     SwitchPage.SwitchMainPage(abc, this);
 }
示例#18
0
        private void Add(object param)
        {
            Wizards.EditPaymentWizard eow = new Wizards.EditPaymentWizard();

            SwitchPage.SwitchMainPage(eow, this);
        }
示例#19
0
 private void SellApartment(object param)
 {
     Wizards.SellApartmentWizard saw = new Wizards.SellApartmentWizard(SelectedApartment);
     SwitchPage.SwitchMainPage(saw, this);
 }
示例#20
0
        private void AddMultiPayment(object param)
        {
            Wizards.EditMultiPaymentWizard emp = new Wizards.EditMultiPaymentWizard();

            SwitchPage.SwitchMainPage(emp, this);
        }
示例#21
0
        private void ShowDetails(object param)
        {
            Wizards.EditPaymentWizard eow = new Wizards.EditPaymentWizard(SelectedPayment);

            SwitchPage.SwitchMainPage(eow, this);
        }
 private void CancelDialog(object param)
 {
     SwitchPage.SwitchMainPage(new Pages.MonthlyChargesPage(), this);
 }
示例#23
0
        private void Add(object param)
        {
            var eiw = new Wizards.EditInvoiceWizard();

            SwitchPage.SwitchMainPage(eiw, this);
        }
 private void CancelDialog(object param)
 {
     SwitchPage.SwitchMainPage(new Pages.InvoicesPage(), this);
 }
 public void Cancel(object param)
 {
     SwitchPage.SwitchMainPage(new Pages.BuildingsPage(), this);
 }
示例#26
0
        private void AddOwner(object param)
        {
            Wizards.EditOwnerWizard eow = new Wizards.EditOwnerWizard();

            SwitchPage.SwitchMainPage(eow, this);
        }