コード例 #1
0
        public async Task <IActionResult> Get()
        {
            _myCallsApiService.SaveNewCalls();
            _myCallsAPIServiceAstrics.SaveNewCalls();

            var result = await _context.Set <WorkGroup>()
                         .Select(x => new WorkGroupDto()
            {
                Id                = x.Id,
                Title             = x.Title,
                EscortManagerId   = x.EscortManagerId ?? 0,
                RegionalManagerId = x.RegionalManagerId ?? 0,
                ClientIds         = _context.Set <ClientWorkGroup>()
                                    .Where(z => z.WorkGroupId == x.Id)
                                    .Select(z => z.ClientId)
                                    .ToList(),
                EscortManagerName = x.EscortManager != null
                        ? x.EscortManager.Login
                        : "",
                RegionalManagerName = x.RegionalManager != null
                        ? x.RegionalManager.Login
                        : "",
                EscortManagerEfficiency   = 100,
                RegionalManagerEfficiency = 100
            }).ToListAsync();

            return(Ok(result));
        }
コード例 #2
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();
        }
コード例 #3
0
ファイル: ClientController.cs プロジェクト: WorldSushi/Sushi
        public async Task <IActionResult> Get()
        {
            List <CallsComment>  callsComments  = _context.Set <CallsComment>().ToList();
            List <ClientContact> clientContacts = _context.Set <ClientContact>().ToList();
            List <ClientDto>     clientsDto     = new List <ClientDto>();
            List <CallClient>    calls          = _context.Set <CallClient>().ToList();
            var  managerId = _accountInformationService.GetOperatorId();
            User user      = _context.Set <User>().ToList().FirstOrDefault(m => m.Id == managerId);

            _myCallsApiService.SaveNewCalls();
            _myCallsAPIServiceAstrics.SaveNewCalls();

            List <WorkGroup> workGroups = null;

            if (((Data.Entities.Users.Manager)user).typeManager == TypeManager.Manager)
            {
                workGroups = await _context.Set <WorkGroup>()
                             .Where(x => x.RegionalManagerId == managerId ||
                                    x.EscortManagerId == managerId).ToListAsync();
            }
            else if (((Data.Entities.Users.Manager)user).typeManager == TypeManager.Marketolog)
            {
                workGroups = await _context.Set <WorkGroup>().ToListAsync();
            }
            var clientPhones = await _context.Set <ClientPhone>()
                               .ToListAsync();

            foreach (WorkGroup workGroup in workGroups)
            {
                var result = await _context.Set <ClientWorkGroup>()
                             .Where(x => x.WorkGroupId == workGroup.Id)
                             .Select(x => new ClientDto()
                {
                    Id          = x.Client.Id,
                    Title       = x.Client.Title,
                    LegalEntity = x.Client.LegalEntity,
                    Phones      = clientPhones.Where(z => z.ClientId == x.ClientId)
                                  .Select(z => new ClientPhoneDTO
                    {
                        Id    = z.Id,
                        Phone = z.Phone
                    }).ToList(),
                    ClientType           = x.Client.ClientType,
                    NumberOfCalls        = x.Client.NumberOfCalls,
                    NumberOfShipments    = x.Client.NumberOfShipments,
                    Group                = (int)x.Client.Group,
                    NomenclatureAnalysis = new NomenclatureAnalysis()
                    {
                        Id = 1,
                        ReportPrevMonth  = 50,
                        ReportAvg5Months = 50,
                        PrevMonth        = 20,
                        Avg5Months       = 20,
                        ClientId         = x.Id
                    },
                    IsCoverage    = x.Client.IsCoverage != null || x.Client.IsCoverage != "" ? Convert.ToBoolean(x.Client.IsCoverage) : false,
                    CallsComments = callsComments.Where(c => c.ClientId == x.ClientId && c.AcceptControlerCalss == AcceptControlerCalss.ControlerNoAccept)
                                    .Select(z => new CallsCommentDto()
                    {
                        AcceptControlerCalss = z.AcceptControlerCalss,
                        ClientId             = x.ClientId,
                        Comment         = z.Comment,
                        ContactClientId = z.ContactClientId,
                        Date            = clientContacts.FirstOrDefault(c => c.ClientId == x.ClientId && c.Id == z.ContactClientId) != null ? clientContacts.FirstOrDefault(c => c.ClientId == x.ClientId && c.Id == z.ContactClientId).Date.ToString("dd.MM.yyyy hh:mm") : "",
                        ManagerComment  = z.ManagerComment,
                        Durations       = calls.FirstOrDefault(c => c.ClientId == x.ClientId) != null ? calls.FirstOrDefault(c => c.ClientId == x.ClientId).Duration : 0,
                        ColorPen        = z.ColorPen,
                        Type            = z.Type
                    }).ToList()
                })
                             .OrderByDescending(x => x.NumberOfCalls)
                             //.Take(50)
                             .ToListAsync();

                clientsDto.AddRange(result);
            }
            return(Ok(clientsDto));
        }