private void RecalculateCharge(object param)
        {

            using (var db = new DB.DomenaDBContext())
            {
                var q = db.Charges.Include(x => x.Components).Where(y => !y.IsClosed);
                foreach (var charge in q)
                {
                    ChargesOperations.RecalculateCharge(charge);
                }
            }
            InitializeCollection();
        }
Beispiel #2
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);
        }