예제 #1
0
        public IEnumerable <VoipCallWrapper> GetCalls(string callType, ApiDateTime from, ApiDateTime to, Guid?agent, int?client, int?contactID)
        {
            var voipDao = DaoFactory.VoipDao;

            var filter = new VoipCallFilter
            {
                Type                                     = callType,
                FromDate                                 = from != null ? from.UtcTime : (DateTime?)null,
                ToDate                                   = to != null?to.UtcTime.AddDays(1).AddMilliseconds(-1) : (DateTime?)null,
                                              Agent      = agent,
                                              Client     = client,
                                              ContactID  = contactID,
                                              SortBy     = _context.SortBy,
                                              SortOrder  = !_context.SortDescending,
                                              SearchText = _context.FilterValue,
                                              Offset     = _context.StartIndex,
                                              Max        = _context.Count,
            };

            _context.SetDataPaginated();
            _context.SetDataFiltered();
            _context.SetDataSorted();
            _context.TotalCount = voipDao.GetCallsCount(filter);

            var defaultSmallPhoto = ContactPhotoManager.GetSmallSizePhoto(-1, false);
            var calls             = voipDao.GetCalls(filter).Select(
                r =>
            {
                ContactWrapper contact;
                if (r.ContactId != 0)
                {
                    contact = r.ContactIsCompany
                                          ? (ContactWrapper) new CompanyWrapper(r.ContactId)
                    {
                        DisplayName = r.ContactTitle
                    }
                                          : new PersonWrapper(r.ContactId)
                    {
                        DisplayName = r.ContactTitle
                    };
                    contact.SmallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(contact.ID, contact.IsCompany);
                }
                else
                {
                    contact = new PersonWrapper(-1)
                    {
                        SmallFotoUrl = defaultSmallPhoto
                    };
                }
                return(new VoipCallWrapper(r, contact));
            }).ToList();

            return(calls);
        }
예제 #2
0
        private SqlQuery GetCallsQuery(VoipCallFilter filter)
        {
            var query = Query(callsTable + " ca")
                .Select("ca.id", "ca.number_from", "ca.number_to", "ca.answered_by", "ca.dial_date", "ca.price")
                .Select("ca.status", "ca.contact_id")
                .LeftOuterJoin(contactsTable + " co", Exp.EqColumns("ca.contact_id", "co.id"))
                .Select("co.is_company", "co.company_name", "co.first_name", "co.last_name");

            if (filter.Ids != null && filter.Ids.Any())
            {
                query.Where(Exp.In("ca.id", filter.Ids));
            }

            if (!string.IsNullOrWhiteSpace(filter.SearchText))
            {
                query.Where(Exp.Like("ca.id", filter.SearchText, SqlLike.StartWith));
            }

            if (filter.TypeStatus.HasValue)
            {
                query.Where("ca.status", filter.TypeStatus.Value);
            }

            if (filter.FromDate.HasValue)
            {
                query.Where(Exp.Ge("ca.dial_date", filter.FromDate.Value));
            }

            if (filter.ToDate.HasValue)
            {
                query.Where(Exp.Le("ca.dial_date", filter.ToDate.Value));
            }

            if (filter.Agent.HasValue)
            {
                query.Where("ca.answered_by", filter.Agent.Value);
            }

            return query;
        }
예제 #3
0
        public IEnumerable<VoipCall> GetCalls(VoipCallFilter filter)
        {
            using (var db = GetDb())
            {
                var query = GetCallsQuery(filter);

                if (filter.SortByColumn != null)
                {
                    query.OrderBy(filter.SortByColumn, filter.SortOrder);
                }

                query.SetFirstResult((int)filter.Offset);
                query.SetMaxResults((int)filter.Max);

                var calls = db.ExecuteList(query).ConvertAll(ToCall);
                var history = GetCallHistory(calls.Select(r => r.Id));

                calls = calls.GroupJoin(history, call => call.Id, h => h.ParentID, (call, h) =>
                {
                    call.History.AddRange(h);
                    return call;
                }).ToList();

                return calls;
            }
        }
예제 #4
0
        public int GetCallsCount(VoipCallFilter filter)
        {
            using (var db = GetDb())
            {
                var query = GetCallsQuery(filter);
                var queryCount = new SqlQuery().SelectCount().From(query, "t1");

                return db.ExecuteScalar<int>(queryCount);
            }
        }
예제 #5
0
        public IEnumerable<VoipCallWrapper> GetCalls(string callType, ApiDateTime from, ApiDateTime to, Guid? agent, int? client)
        {
            var voipDao = DaoFactory.GetVoipDao();

            var filter = new VoipCallFilter
                {
                    Type = callType,
                    FromDate = from != null ? from.UtcTime : (DateTime?)null,
                    ToDate = to != null ? to.UtcTime.AddDays(1).AddMilliseconds(-1) : (DateTime?)null,
                    Agent = agent,
                    Client = client,
                    SortBy = _context.SortBy,
                    SortOrder = !_context.SortDescending,
                    SearchText = _context.FilterValue,
                    Offset = _context.StartIndex,
                    Max = _context.Count,
                };

            _context.SetDataPaginated();
            _context.SetDataFiltered();
            _context.SetDataSorted();
            _context.TotalCount = voipDao.GetCallsCount(filter);

            var defaultSmallPhoto = ContactPhotoManager.GetSmallSizePhoto(-1, false);            
            var calls = voipDao.GetCalls(filter).Select(
                r =>
                    {
                        ContactWrapper contact;
                        if (r.ContactId != 0)
                        {
                            contact = r.ContactIsCompany
                                          ? (ContactWrapper)new CompanyWrapper(r.ContactId) {DisplayName = r.ContactTitle}
                                          : new PersonWrapper(r.ContactId) {DisplayName = r.ContactTitle};
                            contact.SmallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(contact.ID, contact.IsCompany);
                        }
                        else
                        {
                            contact = new PersonWrapper(-1) { SmallFotoUrl = defaultSmallPhoto };
                        }            
                        return new VoipCallWrapper(r, contact);
                    }).ToList();
            return calls;
        }