private static void DoCalls(BillingCompany company) { Random random = new Random(); for (int i = 0; i < 300; i++) { var clients = company.GetClientList(); var client = clients[random.Next(clients.Count)]; var number = random.Next(101, 106); if (client.Phone.Number != number) { client.Call(number, (ushort)random.Next(1, 30)); } } }
public void Call(int number, ushort durationOfCall) { var client = company.GetClientList().FirstOrDefault(user => user.Phone.Number == number); if (number == Phone.Number || client == null) { Notify?.Invoke(this, "Wrong Number"); return; } if (DateTime.Now.Subtract(balancePayDate).Days > 30 && Balance < 0) { Notify?.Invoke(this, $"Your account is temporarily blocked. Pay off debt: {Balance}"); return; } if (client.Phone.IsEnable == false) { Notify?.Invoke(this, "The number you have dialed is temporarily unavailable"); return; } if (client.Phone.IsUse == true) { Notify?.Invoke(this, "The number you have dialed is busy"); return; } Phone.IsUse = true; client.Phone.IsUse = true; decimal costPerCall = durationOfCall * (int)TariffPlan; Balance -= costPerCall; DateTime date = DateTime.Now; //Thread.Sleep(10 * durationOfCall); Call call = new Call(number, client.Name, durationOfCall, costPerCall, date); calls.Add(call); Phone.IsUse = false; client.Phone.IsUse = false; }