/// <summary> /// Calculates the costs of claim and debt /// </summary> public void CostCalculation() { // CLAIM Claim.Clear(); foreach (Purchase purchase in Session.Household.Purchases) { if (purchase.UserPayed.Contains(Session.User.Name)) { foreach (string user in purchase.UsersInvolved) { if (user != Session.User.Name) { if (!purchase.UsersInvolvedPayed.Contains(user)) { if (!_claim_dictionary.ContainsKey(user)) { _claim_dictionary.Add(user, purchase.Price / purchase.UsersInvolved.Count); } else { _claim_dictionary[user] += (purchase.Price / purchase.UsersInvolved.Count); } } } } } } foreach (KeyValuePair <string, double> entry in _claim_dictionary) { Claim.Add(new UserClaim() { Name = entry.Key, Total = entry.Value }); Netto += entry.Value; } // DEBT Debt.Clear(); foreach (Purchase purchase in Session.Household.Purchases) { if (purchase.UsersInvolved.Contains(Session.User.Name) && !purchase.UsersInvolvedPayed.Contains(Session.User.Name)) { if (!_debt_dictionary.ContainsKey(purchase.UserPayed)) { _debt_dictionary.Add(purchase.UserPayed, purchase.Price / purchase.UsersInvolved.Count); } else { _debt_dictionary[purchase.UserPayed] += (purchase.Price / purchase.UsersInvolved.Count); } } } foreach (KeyValuePair <string, double> entry in _debt_dictionary) { Debt.Add(new UserDebt() { Name = entry.Key, Total = entry.Value }); Netto -= entry.Value; } }