Beispiel #1
0
        public void SaveNewCalls()
        {
            var monthCallsInfo = GetCurrentMonthCallsInfo();

            monthCallsInfo.Loading = true;

            _context.SaveChanges();

            var callsLog = new List <CallLog>();

            CallsDTO response = GetCallsByDate(
                new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1),
                new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day),
                monthCallsInfo.Offset);

            if (Convert.ToInt32(response.Results_next_offset) > 0)
            {
                monthCallsInfo.ChangeOffset(Convert.ToInt32(response.Results_next_offset));
            }
            else
            {
                monthCallsInfo.ChangeOffset(
                    monthCallsInfo.Offset + Convert.ToInt32(response.Results_count));
            }

            callsLog.AddRange(response.Results /*.Where(c => c.Client_number == "+79641619304")*/.Select(x => new CallLog()
            {
                Answer_time  = x.Answer_time,
                Answered     = x.Answered,
                ClientName   = x.Client_name,
                ClientNumber = x.Client_number,
                DbCallId     = x.Db_call_id,
                Direction    = x.Direction,
                Duration     = x.Duration,
                EndTime      = x.End_time,
                Recording    = x.Recording,
                UserAccount  = x.User_account,
                StartTime    = x.Start_time,
                SrcNumber    = x.Src_number,
                UserId       = x.User_id,
                SrcId        = x.Src_id,
                SrcSlot      = x.Src_slot
            }));

            while (Convert.ToInt32(response.Results_next_offset) > 0)
            {
                response = GetCallsByDate(
                    new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1),
                    new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day),
                    monthCallsInfo.Offset);
                if (Convert.ToInt32(response.Results_next_offset) > 0)
                {
                    monthCallsInfo.ChangeOffset(Convert.ToInt32(response.Results_next_offset));
                }
                else
                {
                    monthCallsInfo.ChangeOffset(
                        monthCallsInfo.Offset + Convert.ToInt32(response.Results_count));
                }

                callsLog.AddRange(response.Results /*.Where(c => c.Client_number.Contains("+79641619304"))*/.Select(x => new CallLog()
                {
                    Answer_time  = x.Answer_time,
                    Answered     = x.Answered,
                    ClientName   = x.Client_name,
                    ClientNumber = x.Client_number,
                    DbCallId     = x.Db_call_id,
                    Direction    = x.Direction,
                    Duration     = x.Duration,
                    EndTime      = x.End_time,
                    Recording    = x.Recording,
                    UserAccount  = x.User_account,
                    StartTime    = x.Start_time,
                    SrcNumber    = x.Src_number,
                    UserId       = x.User_id,
                    SrcId        = x.Src_id,
                    SrcSlot      = x.Src_slot
                }));
            }

            var managersPhone = _context.Set <Manager>()
                                .Select(x => new Manager()
            {
                Id    = x.Id,
                Phone = PhoneHelper.ConvertToPhone(x.Phone)
            }).ToList();

            var clientPhone = _context.Set <ClientPhone>()
                              .Select(x => new
            {
                ClientId = x.ClientId,
                Phone    = x.Phone
            }).ToList();

            var a = callsLog.Where(x => (x.SrcNumber != "" && x.ClientNumber != "")
                ? managersPhone.Select(z => z.Phone).Contains(PhoneHelper.ConvertToPhone(x.SrcNumber)) &&
                                   clientPhone.Select(z => PhoneHelper.ConvertToPhone(z.Phone)).Contains(PhoneHelper.ConvertToPhone(x.ClientNumber))
                : false).ToList();


            var b = callsLog.Where(x => x.ClientName.Contains("Мир Суши")).ToList();

            b.AddRange(callsLog.Where(x => (x.SrcNumber != "" && x.ClientNumber != "")
                ? managersPhone.Select(z => z.Phone).Contains(PhoneHelper.ConvertToPhone(x.SrcNumber)) &&
                                      managersPhone.Select(z => z.Phone).Contains(PhoneHelper.ConvertToPhone(x.ClientNumber))
                : false).ToList());

            var calls           = new List <CallInfo>();
            var calls1          = new List <CallInfo>();
            var clientContacts  = new List <ClientContact>();
            var managerContacts = new List <ContactManager>();

            var workGroups = _context.Set <WorkGroup>().ToList();

            var dt = new DateTime(1970, 1, 1).AddHours(3);

            List <CallInfo> callInfos = _context.Set <CallInfo>().ToList();


            foreach (var call in a)
            {
                try
                {
                    calls.Add(new CallInfo()
                    {
                        Call = new CallClient()
                        {
                            ClientId = clientPhone
                                       .FirstOrDefault(x => x.Phone.Contains(PhoneHelper.ConvertToPhone(call.ClientNumber))).ClientId,
                            ManagerId = managersPhone
                                        .FirstOrDefault(x => x.Phone.Contains(PhoneHelper.ConvertToPhone(call.SrcNumber))).Id,
                            Duration  = call.Duration,
                            Recording = call.Recording,
                            DateTime  = dt + TimeSpan.FromSeconds(call.StartTime),
                            Direction = call.Direction
                        },
                        CallLog = callsLog.FirstOrDefault(x => x.ClientNumber == call.ClientNumber &&
                                                          x.SrcNumber == call.SrcNumber &&
                                                          x.StartTime == call.StartTime)
                    });
                }
                catch (Exception e)
                {
                }
            }

            foreach (var call in b)
            {
                try
                {
                    calls1.Add(new CallInfo()
                    {
                        Call = new CallManager()
                        {
                            ManagerIdC = managersPhone
                                         .FirstOrDefault(x => x.Phone.Contains(PhoneHelper.ConvertToPhone(call.ClientNumber))).Id,
                            ManagerId = managersPhone
                                        .FirstOrDefault(x => x.Phone.Contains(PhoneHelper.ConvertToPhone(call.SrcNumber))).Id,
                            Duration  = call.Duration,
                            Recording = call.Recording,
                            DateTime  = dt + TimeSpan.FromSeconds(call.StartTime),
                            Direction = call.Direction
                        },
                        CallLog = callsLog.FirstOrDefault(x => x.ClientNumber == call.ClientNumber &&
                                                          x.SrcNumber == call.SrcNumber &&
                                                          x.StartTime == call.StartTime)
                    });
                }
                catch (Exception e)
                {
                }
            }



            _context.Set <CallInfo>()
            .AddRange(calls);
            _context.Set <CallInfo>()
            .AddRange(calls1);
            _context.Set <CallLog>()
            .AddRange(callsLog);


            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
            }

            foreach (var call in calls)
            {
                try
                {
                    var clientContact = new ClientContact(
                        new ClientContactCreate()
                    {
                        ClientId    = ((CallClient)call.Call).ClientId,
                        ContactType = ClientContactType.NoAcceptCall,
                        ManagerId   = ((CallClient)call.Call).ManagerId,
                        ManagerType = workGroups.FirstOrDefault(x => x.EscortManagerId == ((CallClient)call.Call).ManagerId) != null
                            ? ManagerType.EscortManager
                            : workGroups.FirstOrDefault(x => x.RegionalManagerId == ((CallClient)call.Call).ManagerId) != null
                                ? ManagerType.RegionalManager
                                : ManagerType.Undefined,
                    });
                    clientContact.Date      = dt + TimeSpan.FromSeconds(call.CallLog.StartTime);
                    clientContact.Direction = ((CallClient)call.Call).Direction;
                    clientContact.CallId    = call.Call.Id;
                    clientContact.Call      = call.Call;
                    clientContacts.Add(clientContact);
                }
                catch (Exception e)
                {
                }
            }

            var s = clientContacts.Where(c => c.ClientId == 3413);

            foreach (var call in calls1)
            {
                try
                {
                    var managerContact = new ContactManager(
                        new ClientContactCreate()
                    {
                        ClientId    = ((CallManager)call.Call).ManagerIdC,
                        ContactType = ClientContactType.ManagerCall,
                        ManagerId   = ((CallManager)call.Call).ManagerId,
                        ManagerType = workGroups.FirstOrDefault(x => x.EscortManagerId == ((CallManager)call.Call).ManagerId) != null
                            ? ManagerType.EscortManager
                            : workGroups.FirstOrDefault(x => x.RegionalManagerId == ((CallManager)call.Call).ManagerId) != null
                                ? ManagerType.RegionalManager
                                : ManagerType.Undefined
                    });
                    managerContact.Date      = dt + TimeSpan.FromSeconds(call.CallLog.StartTime);
                    managerContact.Direction = ((CallManager)call.Call).Direction;
                    managerContact.CallId    = call.Call.Id;
                    managerContacts.Add(managerContact);
                }
                catch (Exception e)
                {
                }
            }

            _context.Set <ClientContact>()
            .AddRange(clientContacts);
            _context.Set <ContactManager>()
            .AddRange(managerContacts);

            monthCallsInfo.Loading = false;
            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
            }
        }
Beispiel #2
0
        public void SaveNewCalls()
        {
            var monthCallsInfo = GetCurrentMonthCallsInfo();

            if (monthCallsInfo.Loading)
            {
                return;
            }

            monthCallsInfo.Loading = true;

            _context.SaveChanges();

            var             callsLog = new List <CallLog>();
            CallsDTOAstrics response = null;

            try
            {
                response = GetCallsByDate(monthCallsInfo.LastId,
                                          new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1),
                                          new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
            }
            catch (Exception e)
            {
                File.WriteAllText("123.txt", e.Message);
                monthCallsInfo.Loading = false;
                _context.SaveChanges();
                return;
            }

            callsLog.AddRange(response.Results.Select(x => new CallLog()
            {
                Answer_time  = "",
                Answered     = "1",
                ClientName   = "",
                ClientNumber = x.Src,
                DbCallId     = x.Id,
                Direction    = x.Src.Length >= 4 ? "1": "0",
                Duration     = Convert.ToInt32(x.Billsec),
                EndTime      = (Int32)(Convert.ToDateTime(x.End).Subtract(new DateTime(1970, 1, 1))).TotalSeconds,
                Recording    = $"http://95.181.199.172/admin/getRecordByID.php?uniqueId={x.Filename}",
                UserAccount  = "",
                StartTime    = (Int32)(Convert.ToDateTime(x.Start).Subtract(new DateTime(1970, 1, 1))).TotalSeconds,
                SrcNumber    = x.Dst,
                UserId       = "",
                SrcId        = "",
                SrcSlot      = ""
            }));

            //callsLog = callsLog.Where(x => x.Duration >= 150).ToList();

            var managersPhone = _context.Set <Manager>()
                                .Select(x => new
            {
                ManagerId = x.Id,
                Phone     = PhoneHelper.ConvertToPhone(x.Phone)
            }).ToList();

            var clientPhone = _context.Set <ClientPhone>()
                              .Select(x => new
            {
                ClientId = x.ClientId,
                Phone    = x.Phone
            }).ToList();

            var a = callsLog.Where(x => (x.SrcNumber != "" && x.ClientNumber != "")
                ? managersPhone.Select(z => z.Phone).Contains(PhoneHelper.ConvertToPhone(x.SrcNumber)) &&
                                   (clientPhone.Select(z => PhoneHelper.ConvertToPhone(z.Phone)).Contains(PhoneHelper.ConvertToPhone(x.ClientNumber)) || x.ClientNumber == "143")
                : false).ToList();

            var b = callsLog.Where(x => (x.SrcNumber != "" && x.ClientNumber != "")
                ? managersPhone.Select(z => z.Phone).Contains(PhoneHelper.ConvertToPhone(x.SrcNumber)) &&
                                   x.ClientNumber.Length == 3 && x.ClientNumber != "143" : false).ToList();

            var calls           = new List <CallInfo>();
            var calls1          = new List <CallInfo>();
            var clientContacts  = new List <ClientContact>();
            var managerContacts = new List <ContactManager>();

            List <CallInfo> callInfos  = _context.Set <CallInfo>().ToList();
            var             workGroups = _context.Set <WorkGroup>().ToList();

            var dt = new DateTime(1970, 1, 1).AddHours(3);

            foreach (var call in a)
            {
                calls.Add(new CallInfo()
                {
                    Call = new CallClient()
                    {
                        ClientId = clientPhone
                                   .FirstOrDefault(x => x.Phone.Contains(PhoneHelper.ConvertToPhone(call.ClientNumber))).ClientId,
                        ManagerId = managersPhone
                                    .FirstOrDefault(x => x.Phone.Contains(PhoneHelper.ConvertToPhone(call.SrcNumber))).ManagerId,
                        Duration  = call.Duration,
                        Recording = call.Recording,
                        DateTime  = dt + TimeSpan.FromSeconds(call.StartTime),
                        Direction = call.Direction
                    },
                    CallLog = callsLog.FirstOrDefault(x => x.ClientNumber == call.ClientNumber &&
                                                      x.SrcNumber == call.SrcNumber &&
                                                      x.StartTime == call.StartTime)
                });
            }

            foreach (var call in b)
            {
                try
                {
                    calls1.Add(new CallInfo()
                    {
                        Call = new CallManager()
                        {
                            ManagerIdC = managersPhone
                                         .FirstOrDefault(x => x.Phone.Contains(PhoneHelper.ConvertToPhone(call.ClientNumber))).ManagerId,
                            ManagerId = managersPhone
                                        .FirstOrDefault(x => x.Phone.Contains(PhoneHelper.ConvertToPhone(call.SrcNumber))).ManagerId,
                            Duration  = call.Duration,
                            Recording = call.Recording,
                            DateTime  = dt + TimeSpan.FromSeconds(call.StartTime),
                            Direction = call.Direction
                        },
                        CallLog = callsLog.FirstOrDefault(x => x.ClientNumber == call.ClientNumber &&
                                                          x.SrcNumber == call.SrcNumber &&
                                                          x.StartTime == call.StartTime)
                    });
                }
                catch (Exception e)
                {
                }
            }

            _context.Set <CallInfo>()
            .AddRange(calls);
            _context.Set <CallInfo>()
            .AddRange(calls1);
            _context.Set <CallLog>()
            .AddRange(callsLog);

            _context.SaveChanges();

            foreach (var call in calls)
            {
                var clientContact = new ClientContact(
                    new ClientContactCreate()
                {
                    ClientId    = ((CallClient)call.Call).ClientId,
                    ContactType = ClientContactType.NoAcceptCall,
                    ManagerId   = ((CallClient)call.Call).ManagerId,
                    ManagerType = workGroups.FirstOrDefault(x => x.EscortManagerId == ((CallClient)call.Call).ManagerId) != null
                            ? ManagerType.EscortManager
                            : workGroups.FirstOrDefault(x => x.RegionalManagerId == ((CallClient)call.Call).ManagerId) != null
                                ? ManagerType.RegionalManager
                                : ManagerType.Undefined
                });

                clientContact.Date      = dt + TimeSpan.FromSeconds(call.CallLog.StartTime);
                clientContact.Direction = ((CallClient)call.Call).Direction;
                clientContact.CallId    = call.Call.Id;
                clientContact.Call      = call.Call;
                clientContacts.Add(clientContact);
            }

            foreach (var call in calls1)
            {
                try
                {
                    var managerContact = new ContactManager(
                        new ClientContactCreate()
                    {
                        ClientId    = ((CallManager)call.Call).ManagerIdC,
                        ContactType = ClientContactType.ManagerCall,
                        ManagerId   = ((CallManager)call.Call).ManagerId,
                        ManagerType = workGroups.FirstOrDefault(x => x.EscortManagerId == ((CallManager)call.Call).ManagerId) != null
                            ? ManagerType.EscortManager
                            : workGroups.FirstOrDefault(x => x.RegionalManagerId == ((CallManager)call.Call).ManagerId) != null
                                ? ManagerType.RegionalManager
                                : ManagerType.Undefined
                    });
                    managerContact.Date      = dt + TimeSpan.FromSeconds(call.CallLog.StartTime);
                    managerContact.Direction = ((CallManager)call.Call).Direction;
                    managerContact.CallId    = call.Call.Id;
                    managerContacts.Add(managerContact);
                }
                catch (Exception e)
                {
                }
            }

            _context.Set <ClientContact>()
            .AddRange(clientContacts);
            _context.Set <ContactManager>()
            .AddRange(managerContacts);
            monthCallsInfo.ChangeOffset(Convert.ToInt32(response.LastId));
            monthCallsInfo.Loading = false;
            _context.SaveChanges();
        }
Beispiel #3
0
        private void ReloadClientsCalls(string id)
        {
            _myCallsApiService        = new MyCallsAPIService(_context);
            _myCallsAPIServiceAstrics = new MyCallsAPIServiceAstrics(_context);
            _myCallsApiService.SaveNewCalls();
            _myCallsAPIServiceAstrics.SaveNewCalls();
            ClientInfo clientInfo = _context.Set <ClientInfo>().FirstOrDefault(c => c.OneCId.ToString() == id);

            var managersPhone = _context.Set <Manager>()
                                .Select(x => new Manager()
            {
                Id    = x.Id,
                Phone = PhoneHelper.ConvertToPhone(x.Phone)
            }).ToList();

            var clientPhone = _context.Set <ClientPhone>()
                              .Where(c => c.ClientId == clientInfo.ClientId)
                              .Select(x => new
            {
                ClientId = x.ClientId,
                Phone    = x.Phone
            }).ToList();
            List <CallLog> callsLog = _context.Set <CallLog>().ToList();
            var            a        = callsLog.Where(x => (x.SrcNumber != "" && x.ClientNumber != "")
                ? managersPhone.Select(z => PhoneHelper.ConvertToPhone(z.Phone)).Contains(PhoneHelper.ConvertToPhone(x.SrcNumber)) &&
                                                     clientPhone.Select(z => PhoneHelper.ConvertToPhone(z.Phone)).Contains(PhoneHelper.ConvertToPhone(x.ClientNumber))
                : false).ToList();
            var dt             = new DateTime(1970, 1, 1);
            var clientContacts = new List <ClientContact>();
            var workGroups     = _context.Set <WorkGroup>().ToList();
            var calls          = new List <CallInfo>();
            List <CallClient>    callClients     = _context.Set <CallClient>().ToList();
            List <ClientContact> clientContacts1 = _context.Set <ClientContact>().ToList();

            foreach (var call in a)
            {
                try
                {
                    CallInfo callInfo = _context.Set <CallInfo>().FirstOrDefault(c => c.CallLogId == call.Id);
                    if (callInfo == null)
                    {
                        calls.Add(new CallInfo()
                        {
                            Call = new CallClient()
                            {
                                ClientId = clientPhone
                                           .FirstOrDefault(x => x.Phone.Contains(PhoneHelper.ConvertToPhone(call.ClientNumber))).ClientId,
                                ManagerId = managersPhone
                                            .FirstOrDefault(x => x.Phone.Contains(PhoneHelper.ConvertToPhone(call.SrcNumber))).Id,
                                Duration  = call.Duration,
                                Recording = call.Recording,
                                DateTime  = dt + TimeSpan.FromSeconds(call.StartTime),
                                Direction = call.Direction
                            },
                            CallLog = call
                        });
                    }
                }
                catch (Exception e)
                {
                }
            }
            _context.Set <CallInfo>()
            .AddRange(calls);
            _context.SaveChanges();
            foreach (var call in calls)
            {
                try
                {
                    var clientContact = new ClientContact(
                        new ClientContactCreate()
                    {
                        ClientId    = ((CallClient)call.Call).ClientId,
                        ContactType = ClientContactType.NoAcceptCall,
                        ManagerId   = ((CallClient)call.Call).ManagerId,
                        ManagerType = workGroups.FirstOrDefault(x => x.EscortManagerId == ((CallClient)call.Call).ManagerId) != null
                            ? ManagerType.EscortManager
                            : workGroups.FirstOrDefault(x => x.RegionalManagerId == ((CallClient)call.Call).ManagerId) != null
                                ? ManagerType.RegionalManager
                                : ManagerType.Undefined,
                    });
                    clientContact.Date      = dt + TimeSpan.FromSeconds(call.CallLog.StartTime);
                    clientContact.Direction = ((CallClient)call.Call).Direction;
                    clientContact.CallId    = call.Call.Id;
                    clientContacts.Add(clientContact);
                }
                catch (Exception e)
                {
                }
            }
            _context.Set <ClientContact>()
            .AddRange(clientContacts);
            _context.SaveChanges();
        }