private static void SetRelationalProperties()
        {
            foreach (var owner in Owners.Where(o => o.Id.HasValue))
            {
                owner.Apartments = Apartments.Where(a =>
                {
                    if (a.OwnerId != owner.Id.Value)
                    {
                        return(false);
                    }

                    a.Owner   = owner;
                    a.OwnerId = owner.Id.Value;
                    return(true);
                }).ToArray();
            }

            foreach (var building in Buildings.Where(b => b.Id.HasValue))
            {
                building.Apartments = Apartments.Where(a =>
                {
                    if (a.BuildingId != building.Id.Value)
                    {
                        return(false);
                    }

                    a.Building   = building;
                    a.BuildingId = building.Id.Value;
                    return(true);
                }).ToArray();
            }
        }
Beispiel #2
0
        public void AddEntry(string ownerName, string accountName, string ticker, decimal amount, DateTime date)
        {
            var asset = Assets.Where(w => w.Ticker == ticker).FirstOrDefault();

            if (asset == null)
            {
                throw new Exception("unable to find asset with ticker:" + ticker);
            }

            var owner = Owners.Where(w => w.Name == ownerName).FirstOrDefault();

            if (owner == null)
            {
                throw new Exception("unable to find account owner");
            }

            var account = owner.Accounts.Where(w => w.Name == accountName).FirstOrDefault();

            if (account == null)
            {
                throw new Exception("unable to find account owned by:" + owner.Name);
            }

            account.Entries.Add(new AccountEntry {
                Asset = asset, Date = date, Amount = amount
            });
        }
Beispiel #3
0
        public async Task <decimal> GetBalanceAsync(string ownerName, string accountName, string ticker)
        {
            var t = new Task <decimal>(() =>
            {
                var owner = Owners.Where(w => w.Name == ownerName).FirstOrDefault();
                if (owner == null)
                {
                    return(0);
                }
                var account = owner.Accounts.Where(w => w.Name == accountName).FirstOrDefault();
                if (account == null)
                {
                    return(0);
                }

                return(account.GetBalance(ticker));
            });

            t.Start();
            return(await t);
        }
Beispiel #4
0
        public void AddAccount(string ownerName, string accountName)
        {
            var owner = Owners.Where(w => w.Name == ownerName).FirstOrDefault();

            if (owner == null)
            {
                owner = new AccountOwner {
                    Name = ownerName, Accounts = new List <Models.Account>()
                };
                Owners.Add(owner);
            }
            if (owner.Accounts == null)
            {
                owner.Accounts = new List <Account>();
            }

            owner.Accounts.Add(new Account
            {
                Name      = accountName,
                OwnerName = ownerName,
                Entries   = new List <AccountEntry>()
            });
        }
Beispiel #5
0
 public ManagePackageOwnersViewModel(Package package, IPrincipal currentUser)
     : base(package)
 {
     CurrentOwnerUsername = currentUser.Identity.Name;
     OtherOwners          = Owners.Where(o => o.Username != CurrentOwnerUsername);
 }