Exemple #1
0
        public void ShowSortedCallInfo(Billing billing, ITerminal terminal)
        {
            int actionStopper             = 1;
            var listRecords               = billing.GetReport(terminal.phoneNumber).GetRecords();
            HistoryContainer historyTapes = new HistoryContainer(listRecords);

            while (actionStopper > 0)
            {
                Console.WriteLine("Select the sort type:\n " +
                                  "ByDateOfCall (enter D),\n " +
                                  "ByCost (enter C),\n " +
                                  "ByNumber (enter N),\n " +
                                  "ByCallType (enter T),\n");
                var key = Console.ReadKey().Key;
                if (key == ConsoleKey.D)
                {
                    actionStopper = 0;
                    historyTapes.SortByDate();
                }
                else if (key == ConsoleKey.C)
                {
                    actionStopper = 0;
                    historyTapes.SortByCost();
                }
                else if (key == ConsoleKey.N)
                {
                    actionStopper = 0;
                    historyTapes.SortByNumber();
                }
                else if (key == ConsoleKey.T)
                {
                    actionStopper = 0;
                    historyTapes.SortByCallType();
                }
            }

            foreach (var item in historyTapes.GetRecords())
            {
                Console.WriteLine("\nCalls:\n Type {0} |\n Date: {1} |\n Duration: {2} | Cost: {3} | Number: {4}",
                                  item.CallType, item.Date, item.CallDuration.ToString("mm:ss"), item.Cost, item.ContractNumber);
            }
        }
Exemple #2
0
        public HistoryContainer GetReport(PhoneNumber telephoneNumber)
        {
            var calls = GetInfoList()
                        .Where(x => x.Number == telephoneNumber || x.TargetNumber == telephoneNumber)
                        .ToList();

            var report = new HistoryContainer();

            foreach (var call in calls)
            {
                CallType    callType;
                PhoneNumber number;
                double      cost;

                if (call.Number == telephoneNumber)
                {
                    callType = CallType.Outgoing;
                    number   = call.TargetNumber;
                    cost     = call.GetCost(billingDictionary
                                            .Where(x => x.Key == telephoneNumber)
                                            .Select(x => x.Value)
                                            .ElementAt(0), call.TimeStartCall, call.TimeEndCall);
                }
                else
                {
                    callType = CallType.Incoming;
                    number   = call.Number;
                    cost     = 0;
                }

                var record = new History(billingDictionary
                                         .Where(x => x.Key == telephoneNumber)
                                         .Select(x => x.Key)
                                         .ElementAt(0), callType, call.TimeStartCall, new DateTime((call.TimeEndCall - call.TimeStartCall).Ticks), cost);

                report.AddRecord(record);
            }
            return(report);
        }