Esempio n. 1
0
 public static List <GroupDb> GetAllGroups()
 {
     using (var ctx = new NovaAlertContext())
     {
         return(ctx.GroupDbs.Where(g => g.DeletedDate == null).ToList());
     }
 }
Esempio n. 2
0
        public static List <UnitPhone> LoadUnitPhones(int?id = null)
        {
            var list = new List <UnitPhone>();

            using (var ctx = new NovaAlertContext())
            {
                var query = ctx.PhoneNumbers.OfType <PhoneNumber>().Where(u => u.DeletedDate == null);
                if (id.HasValue)
                {
                    query = query.Where(u => u.PhoneNumberId == id.Value);
                }

                foreach (var item in query.ToList())
                {
                    var up = new UnitPhone(item.PhoneNumberId, item.NameAbbr)
                    {
                        AreaCode      = item.AreaCode,
                        Number        = item.Number,
                        ListOrder     = -1,
                        PhoneNumberId = item.PhoneNumberId,
                        Password      = item.Password,
                        TSLAreaCode   = item.TSLAreaCode,
                        TSLNumber     = item.TSLNumber
                    };

                    list.Add(up);
                }
            }

            return(list);
        }
Esempio n. 3
0
        public List <ContactGroup> GetAllContactGroups()
        {
            using (var ctx = new NovaAlertContext())
            {
                var list   = new List <ContactGroup>();
                var groups = ctx.GroupDbs.Where(g => g.DeletedDate == null).ToList();
                foreach (var g in groups)
                {
                    var cg = new ContactGroup()
                    {
                        Id = g.GroupId, Name = g.Name, Contacts = new List <ContactInGroup>()
                    };
                    foreach (var item in g.GroupUnits.Where(u => u.IsDeleted == false).ToList())
                    {
                        cg.Contacts.Add(new ContactInGroup()
                        {
                            ListOrder = item.ListOrder,
                            Contact   = Mapper.Map <PhoneNumber, Contact>(item.PhoneNumber)
                        });
                    }

                    list.Add(cg);
                }

                return(list);
            }
        }
Esempio n. 4
0
        //List<PhoneNumber> _phoneNumbers;
        //public List<PhoneNumber> GetPhoneNumbers()
        //{
        //    if (_phoneNumbers == null) _phoneNumbers = _ctx.PhoneNumbers.AsNoTracking().OfType<PhoneNumber>().ToList();
        //    return _phoneNumbers;
        //}
        //public void SaveChanges()
        //{
        //    _ctx.SaveChanges();
        //}

        public static List <HostPhone> LoadPhones()
        {
            var list = new List <HostPhone>();

            using (var ctx = new NovaAlertContext())
            {
                foreach (var c in ctx.ChannelDbs.Include("HostPhoneNumber").Where(c => c.HostPhoneNumber != null && c.HostPhoneNumber.Address != null).ToList())
                {
                    var phone = new HostPhone(c.PhoneNumberId, string.Format("{0}", c.PhoneNumberId))
                    {
                        AreaCode         = c.HostPhoneNumber.AreaCode,
                        Number           = c.HostPhoneNumber.Number,
                        Address          = c.HostPhoneNumber.Address,
                        IsRestricted     = c.HostPhoneNumber.IsRestricted,
                        AutoRecording    = c.AutoRecording,
                        MultiDestEnabled = c.MultiDestEnabled,
                        CCPKEnabled      = c.CCPKEnabled,
                        AlertEnabled     = c.AlertEnabled,
                        //TSLEnabled = c.TSLEnabled,
                        HotUnitId = c.HotUnitId
                    };
                    list.Add(phone);
                }
            }
            return(list);
        }
Esempio n. 5
0
        public List <Channel> GetAllChannels()
        {
            using (var ctx = new NovaAlertContext())
            {
                var list     = new List <Channel>();
                var channels = ctx.ChannelDbs.ToList();
                foreach (var c in channels)
                {
                    var cc = new Channel()
                    {
                        ChannelId        = c.ChannelId,
                        Number           = c.HostPhoneNumber.Number,
                        AreaCode         = c.HostPhoneNumber.AreaCode,
                        IsRestricted     = c.HostPhoneNumber.IsRestricted,
                        AlertEnabled     = c.AlertEnabled,
                        MultiDestEnabled = c.MultiDestEnabled,
                        CCPKEnabled      = c.CCPKEnabled,
                        AutoRecording    = c.AutoRecording,
                        //TypeCde = c.HostPhoneNumber.TypeCde
                        //TSLEnabled = c.TSLEnabled,
                        HotUnitId = c.HotUnitId
                    };

                    list.Add(cc);
                }

                return(list);
            }
        }
Esempio n. 6
0
        public List <LogItem> SearchLog(DateTime start, DateTime end, byte?panelId = null, string searchText = null, int startIndex = 0, int numOfRecords = 0)
        {
            var list = new List <LogItem>();

            using (var ctx = new NovaAlertContext())
            {
                var query = BuildSearchQuery(start, end, panelId, searchText, ctx);

                List <DbLog> logList;
                if (numOfRecords == 0)
                {
                    logList = query.ToList();
                }
                else
                {
                    logList = query.OrderByDescending(l => l.CreatedDate).Skip(startIndex).Take(numOfRecords).ToList();
                }

                foreach (var item in logList)
                {
                    list.Add(Mapper.Map <DbLog, LogItem>(item));
                }
            }

            return(list);
        }
Esempio n. 7
0
        public static void SaveSubResult(int phoneNumberId, ResultData re)
        {
            using (var ctx = new NovaAlertContext())
            {
                var sr = new SubResult()
                {
                    DisplayId     = re.DisplayId,
                    CreatedDate   = DateTime.Now,
                    ParentId      = phoneNumberId,
                    PhoneNumberId = re.PhoneNumberId,
                    UnitName      = re.UnitName,
                    TaskType      = (byte)re.TaskType,
                    Task          = (byte)re.Task,
                    Level         = (byte)re.Level,
                    Result        = (byte)re.Result,
                    TimeReceive   = re.TimeReceive,
                    TimeChange    = re.TimeChange
                };

                if (re.IntervalReceive.HasValue)
                {
                    sr.IntervalReceive = (long)re.IntervalReceive.Value.TotalSeconds;
                }

                if (re.IntervalChange.HasValue)
                {
                    sr.IntervalChange = (long)re.IntervalChange.Value.TotalSeconds;
                }

                ctx.SubResults.Add(sr);
                ctx.SaveChanges();
            }
        }
Esempio n. 8
0
        public void SaveContact(Contact ct)
        {
            using (var ctx = new NovaAlertContext())
            {
                PhoneNumber ph = null;
                if (ct.PhoneNumberId == 0)
                {
                    ph = new PhoneNumber();
                    ctx.PhoneNumbers.Add(ph);
                }
                else
                {
                    ph = ctx.PhoneNumbers.OfType <PhoneNumber>().Where(p => p.PhoneNumberId == ct.PhoneNumberId).FirstOrDefault();
                    if (ph == null)
                    {
                        throw new InvalidOperationException("Invalid phone number id.");
                    }
                }

                Mapper.Map <Contact, PhoneNumber>(ct, ph);
                ctx.SaveChanges();

                if (OnContactChanged != null)
                {
                    OnContactChanged(this, new EntityChangedEventArgs(ph.PhoneNumberId));
                }
            }
        }
Esempio n. 9
0
        public List <SearchCallLogResult> Search(SearchCallLogCriteria cr)
        {
            if (!cr.CanSearch())
            {
                return(null);
            }

            using (var ctx = new NovaAlertContext())
            {
                var query = BuildCallLogSearchQuery(cr, ctx);
                var list  = new List <SearchCallLogResult>();

                List <CallLogDb> dbList;
                if (cr.NumOfRecords > 0)
                {
                    dbList = query.OrderByDescending(det => det.StartTime).Skip(cr.StartIndex).Take(cr.NumOfRecords).ToList();
                }
                else
                {
                    dbList = query.ToList();
                }

                foreach (var call in dbList)
                {
                    var result = new SearchCallLogResult();
                    Mapper.Map <CallLogDb, SearchCallLogResult>(call, result);
                    list.Add(result);
                }

                return(list);
            }
        }
Esempio n. 10
0
 public uint CountLog(DateTime start, DateTime end, byte?panelId = null, string searchText = null)
 {
     using (var ctx = new NovaAlertContext())
     {
         var query = BuildSearchQuery(start, end, panelId, searchText, ctx);
         return((uint)query.Count());
     }
 }
Esempio n. 11
0
 public List <Contact> GetAllContacts()
 {
     using (var ctx = new NovaAlertContext())
     {
         var list = new List <Contact>();
         foreach (var item in ctx.PhoneNumbers.OfType <PhoneNumber>().Where(c => c.DeletedDate == null).ToList())
         {
             list.Add(Mapper.Map <PhoneNumber, Contact>(item));
         }
         return(list);
     }
 }
Esempio n. 12
0
 public void DeleteCallLog(Guid id)
 {
     using (var ctx = new NovaAlertContext())
     {
         var cl = new CallLogDb()
         {
             CallLogId = id
         };
         ctx.CallLogDbs.Attach(cl);
         cl.DeletedDate = DateTime.Now;
         ctx.SaveChanges();
     }
 }
Esempio n. 13
0
        public uint Count(SearchCallLogCriteria cr)
        {
            if (!cr.CanSearch())
            {
                return(0);
            }

            using (var ctx = new NovaAlertContext())
            {
                var query = BuildCallLogSearchQuery(cr, ctx);

                return((uint)query.Count());
            }
        }
Esempio n. 14
0
        public static List <DisplayData> GetDisplayData()
        {
            var list = new List <DisplayData>();

            using (var ctx = new NovaAlertContext())
            {
                foreach (var item in ctx.DisplayDataDbs.ToList())
                {
                    list.Add(Mapper.Map <DisplayDataDb, DisplayData>(item));
                }
            }

            return(list);
        }
Esempio n. 15
0
 public void AddLog(byte panelId, int userId, string info)
 {
     using (var ctx = new NovaAlertContext())
     {
         var log = new DbLog()
         {
             CreatedDate = DateTime.Now,
             PanelId     = panelId,
             UserId      = userId,
             Info        = info
         };
         ctx.DbLogs.Add(log);
         ctx.SaveChanges();
     }
 }
Esempio n. 16
0
        private NovaAlertCommon()
        {
            _ctx = new NovaAlertContext();

            Mapper.CreateMap <DayTypeConfigDb, DayTypeConfig>().ReverseMap();
            Mapper.CreateMap <PODb, PO>().ReverseMap();
            Mapper.CreateMap <AlarmDb, Alarm>().ReverseMap();
            //Mapper.CreateMap<CallLogDb, CallLog>().ReverseMap();
            Mapper.CreateMap <EnumDb, NovaAlert.Entities.Enum>().ReverseMap();
            Mapper.CreateMap <PanelDb, Panel>().ReverseMap();

            Mapper.CreateMap <PhoneNumber, Contact>().ReverseMap();//.ForMember(c => c.PhoneNumberId, m => m.MapFrom(pn => pn.PhoneNumberId));
            Mapper.CreateMap <DisplayData, DisplayDataDb>().ReverseMap();
            Mapper.CreateMap <RadioTimeDb, RadioTime>().ReverseMap();
        }
Esempio n. 17
0
 public void UpdateStatus(int phoneNumberId, eTslStatusType type, eTslStatus status)
 {
     using (var ctx = new NovaAlertContext())
     {
         var st = new TslStatusDb()
         {
             CreatedDate   = DateTime.Now,
             PhoneNumberId = phoneNumberId,
             Type          = (byte)type,
             Status        = (byte)status
         };
         ctx.TslStatusDbs.Add(st);
         ctx.SaveChanges();
     }
 }
Esempio n. 18
0
 public static List <PO> GetPOes()
 {
     using (var ctx = new NovaAlertContext())
     {
         var list = new List <PO>();
         foreach (var item in ctx.PODbs.ToList())
         {
             list.Add(new PO()
             {
                 Id = item.Id, Address = item.Address
             });
         }
         return(list);
     }
 }
Esempio n. 19
0
        //public static List<UnitPhone> LoadUnitPhones(int? groupId = null)
        //{
        //    var list = new List<UnitPhone>();
        //    using (var ctx = new NovaAlertContext())
        //    {
        //        var query = ctx.GroupUnit.AsQueryable();
        //        if (groupId.HasValue) query = query.Where(g => g.GroupId == groupId.Value);
        //        //int key = 1;

        //        foreach (var item in query.ToList())
        //        {
        //            var up = new UnitPhone(item.PhoneNumberId, item.PhoneNumber.NameAbbr)
        //            {
        //                AreaCode = item.PhoneNumber.AreaCode,
        //                Number = item.PhoneNumber.Number,
        //                ListOrder = item.ListOrder,
        //                GroupId = item.GroupId,
        //                PhoneNumberId = item.PhoneNumberId,
        //                Password = item.PhoneNumber.Password
        //            };

        //            GetLastestTask(up);
        //            list.Add(up);
        //        }
        //    }
        //    return list;
        //}

        //public static List<UnitPhone> LoadUnitPhonesByGroup(int groupId)
        //{
        //    var list = new List<UnitPhone>();
        //    using (var ctx = new NovaAlertContext())
        //    {
        //        var query = ctx.GroupUnit.Where(g => g.GroupId == groupId);

        //        foreach (var item in query.ToList())
        //        {
        //            var up = new UnitPhone(item.PhoneNumberId, item.PhoneNumber.NameAbbr)
        //            {
        //                AreaCode = item.PhoneNumber.AreaCode,
        //                Number = item.PhoneNumber.Number,
        //                ListOrder = item.ListOrder,
        //                GroupId = item.GroupId,
        //                PhoneNumberId = item.PhoneNumberId,
        //                Password = item.PhoneNumber.Password
        //            };

        //            GetLastestTask(up);
        //            list.Add(up);
        //        }
        //    }
        //    return list;
        //}

        public static List <GroupUnit> GetUnitsInGroup(int id)
        {
            var list = new List <GroupUnit>();

            using (var ctx = new NovaAlertContext())
            {
                foreach (var item in ctx.GroupUnitDbs.Where(g => g.GroupId == id && g.IsDeleted == false).ToList())
                {
                    list.Add(new GroupUnit()
                    {
                        GroupId = id, UnitId = item.PhoneNumberId, ListOrder = item.ListOrder
                    });
                }
            }

            return(list);
        }
Esempio n. 20
0
        public void SaveCallLogDetail(CallLogDetail en)
        {
            lock (syncRoot)
            {
                using (var ctx = new NovaAlertContext())
                {
                    var cl = ctx.CallLogDetailDbs.Where(c => c.CallLogDetailId == en.CallLogDetailId).FirstOrDefault();
                    if (cl == null)
                    {
                        cl = new CallLogDetailDb();
                        ctx.CallLogDetailDbs.Add(cl);
                    }

                    Mapper.Map <CallLogDetail, CallLogDetailDb>(en, cl);
                    ctx.SaveChanges();
                }
            }
        }
Esempio n. 21
0
        //public static void GetLastestTask(UnitPhone unit, eTaskType taskType = eTaskType.CTT)
        //{
        //    using (var ctx = new NovaAlertContext())
        //    {
        //        var dt = ctx.GroupUnitTasks.Where(t => t.PhoneNumberId == unit.PhoneNumberId && t.TaskType == (byte)taskType)
        //            .OrderByDescending(t => t.Id).FirstOrDefault();
        //        if (dt != null)
        //        {
        //            unit.Task = new Task()
        //            {
        //                CurrentTask = (eTask)dt.Task,
        //                Level = (eTaskLevel)dt.Level,
        //                Result = (eTaskResult)dt.Result,
        //                CreatedDate = dt.CreatedDate
        //            };
        //        }
        //    }
        //}

        public static Task GetLastestTask(int phoneNumberId, eTaskType taskType)
        {
            using (var ctx = new NovaAlertContext())
            {
                var task = new Task();

                var dt = ctx.GroupUnitTasks.Where(t => t.PhoneNumberId == phoneNumberId && t.TaskType == (byte)taskType)
                         .OrderByDescending(t => t.Id).FirstOrDefault();
                if (dt != null)
                {
                    task.CurrentTask = (eTask)dt.Task;
                    task.Level       = (eTaskLevel)dt.Level;
                    task.Result      = (eTaskResult)dt.Result;
                    task.CreatedDate = dt.CreatedDate;
                }

                return(task);
            }
        }
Esempio n. 22
0
        public static void UpdateTask(UnitPhone unit, long?duration, eTaskType taskType)
        {
            Entities.Task task = NovaAlert.Dal.NovaAlertCommon.GetLastestTask(unit.Id, Entities.eTaskType.CTT);
            using (var ctx = new NovaAlertContext())
            {
                var dt = new GroupUnitTask()
                {
                    GroupId       = 0, //unit.GroupId,
                    TaskType      = (byte)taskType,
                    PhoneNumberId = unit.PhoneNumberId,
                    Task          = (byte)unit.Task.CurrentTask,
                    Level         = (byte)unit.Task.Level,
                    Result        = (byte)unit.Task.Result,
                    CreatedDate   = DateTime.Now,
                    Duration      = duration
                };

                ctx.GroupUnitTasks.Add(dt);
                ctx.SaveChanges();
            }
        }
Esempio n. 23
0
        public void SaveGroup(ContactGroup cg)
        {
            using (var ctx = new NovaAlertContext())
            {
                var g = ctx.GroupDbs.Where(gr => gr.GroupId == cg.Id).FirstOrDefault();
                if (g == null)
                {
                    g = new GroupDb();
                    ctx.GroupDbs.Add(g);
                }
                g.Name = cg.Name;
                if (cg.IsDeleted)
                {
                    g.DeletedDate = DateTime.Now;
                }
                else
                {
                    foreach (var item in cg.Contacts)
                    {
                        var gu = g.GroupUnits.Where(u => u.PhoneNumberId == item.Contact.PhoneNumberId).FirstOrDefault();
                        if (gu == null)
                        {
                            gu = new GroupUnitDb();
                            g.GroupUnits.Add(gu);
                        }
                        gu.PhoneNumberId = item.Contact.PhoneNumberId;
                        gu.ListOrder     = item.ListOrder;
                        gu.IsDeleted     = item.IsDeleted;
                    }
                }

                ctx.SaveChanges();
                //if(cg.Id == 0) cg.Id = g.GroupId;
                if (OnGroupChanged != null)
                {
                    OnGroupChanged(this, new EntityChangedEventArgs(cg.Id));
                }
            }
        }
Esempio n. 24
0
        public static List <ResultData> GetSubResults(int phoneNumberId, eTaskType type)
        {
            using (var ctx = new NovaAlertContext())
            {
                var sql        = string.Format("EXEC GetSubResult {0}, {1}", phoneNumberId, (byte)type);
                var subResults = ctx.Database.SqlQuery <SubResult>(sql).ToList();

                var list = new List <ResultData>();
                foreach (var item in subResults)
                {
                    var r = new ResultData()
                    {
                        DisplayId     = item.DisplayId,
                        PhoneNumberId = item.PhoneNumberId,
                        UnitName      = item.UnitName,
                        TaskType      = (eTaskType)item.TaskType,
                        Task          = (eTask)item.Task,
                        Level         = (eTaskLevel)item.Level,
                        Result        = (eTaskResult)item.Result,
                        TimeReceive   = item.TimeReceive,
                        TimeChange    = item.TimeChange
                    };

                    if (item.IntervalReceive.HasValue)
                    {
                        r.IntervalReceive = TimeSpan.FromSeconds(item.IntervalReceive.Value);
                    }
                    if (item.IntervalChange.HasValue)
                    {
                        r.IntervalChange = TimeSpan.FromSeconds(item.IntervalChange.Value);
                    }

                    list.Add(r);
                }

                return(list);
            }
        }
Esempio n. 25
0
        public static void SaveDisplayData(List <DisplayData> list)
        {
            using (var ctx = new NovaAlertContext())
            {
                foreach (var item in list)
                {
                    var dbItem = ctx.DisplayDataDbs.Where(d => d.DisplayId == item.DisplayId).FirstOrDefault();
                    if (dbItem != null)
                    {
                        if (dbItem.PhoneNumber_1 != item.PhoneNumber_1)
                        {
                            dbItem.PhoneNumber_1 = item.PhoneNumber_1;
                        }

                        if (dbItem.PhoneNumber_2 != item.PhoneNumber_2)
                        {
                            dbItem.PhoneNumber_2 = item.PhoneNumber_2;
                        }
                    }
                }
                ctx.SaveChanges();
            }
        }
Esempio n. 26
0
        public void SaveChannels(List <Channel> list)
        {
            using (var ctx = new NovaAlertContext())
            {
                foreach (var c in list)
                {
                    //ctx.ChannelDbs.ToList();
                    var obj = ctx.ChannelDbs.Where(ch => ch.ChannelId == c.ChannelId).FirstOrDefault();

                    obj.HostPhoneNumber.Number       = c.Number;
                    obj.HostPhoneNumber.AreaCode     = c.AreaCode;
                    obj.HostPhoneNumber.IsRestricted = c.IsRestricted;
                    obj.AlertEnabled     = c.AlertEnabled;
                    obj.MultiDestEnabled = c.MultiDestEnabled;
                    obj.CCPKEnabled      = c.CCPKEnabled;
                    obj.AutoRecording    = c.AutoRecording;
                    obj.HotUnitId        = c.HotUnitId;
                    //obj.TSLEnabled = c.TSLEnabled;
                    //obj.HostPhoneNumber.TypeCde = c.TypeCde;
                }
                ctx.SaveChanges();
            }
        }
Esempio n. 27
0
        public void DeleteContact(int id)
        {
            using (var ctx = new NovaAlertContext())
            {
                var ct = ctx.PhoneNumbers.OfType <PhoneNumber>().Where(c => c.PhoneNumberId == id).FirstOrDefault();
                if (ct == null)
                {
                    return;
                }

                ct.DeletedDate = DateTime.Now;
                var groupUnits = ctx.GroupUnitDbs.Where(g => g.PhoneNumberId == id);
                foreach (var item in groupUnits)
                {
                    item.IsDeleted = true;
                }

                ctx.SaveChanges();
                if (OnContactChanged != null)
                {
                    OnContactChanged(this, new EntityChangedEventArgs(ct.PhoneNumberId));
                }
            }
        }
Esempio n. 28
0
        public TslStatus GetLatestStatus(int phoneNumberId, eTslStatusType type)
        {
            using (var ctx = new NovaAlertContext())
            {
                var st = ctx.TslStatusDbs.Where(t => t.PhoneNumberId == phoneNumberId && t.Type == (byte)type)
                         .OrderByDescending(t => t.Id).FirstOrDefault();

                if (st != null)
                {
                    return(new TslStatus()
                    {
                        Id = st.Id,
                        Type = (eTslStatusType)st.Type,
                        Status = (eTslStatus)st.Status,
                        CreatedDate = st.CreatedDate,
                        DeletedDate = st.DeletedDate
                    });
                }
                else
                {
                    return(null);
                }
            }
        }
Esempio n. 29
0
        public static List <ResultData> GetResults(eTaskType taskType, int phoneNumberId = 0)
        {
            var results = new List <ResultData>();

            using (var ctx = new NovaAlertContext())
            {
                //var list = ctx.ViewResults.Where(r => r.TaskType == (byte)taskType && r.PhoneNumberId != null).OrderBy(r => r.Id).ToList();

                var list = new List <ViewResult>();
                if (phoneNumberId == 0)
                {
                    list = ctx.ViewResults.Where(r => r.TaskType == (byte)taskType && r.PhoneNumberId != null).OrderBy(r => r.Id).ToList();
                }
                else
                {
                    list = ctx.ViewResults.Where(r => r.TaskType == (byte)taskType && r.PhoneNumberId == phoneNumberId).OrderBy(r => r.Id).ToList();
                }

                foreach (var item in list)
                {
                    var re = new ResultData()
                    {
                        DisplayId     = item.Id,
                        PhoneNumberId = item.PhoneNumberId.Value,
                        UnitName      = item.UnitName,
                        Task          = (eTask)(item.Task ?? 0),
                        Level         = (eTaskLevel)(item.Level ?? 0),
                        Result        = (eTaskResult)(item.Result ?? 0),
                        TaskType      = (eTaskType)item.TaskType
                    };

                    if (re.Result == eTaskResult.NL)
                    {
                        if (item.Duration.HasValue)
                        {
                            re.TimeReceive     = item.CreatedDate;
                            re.IntervalReceive = TimeSpan.FromSeconds(item.Duration.Value);
                        }
                    }
                    else if (re.Result == eTaskResult.CTT)
                    {
                        if (item.Duration.HasValue)
                        {
                            re.TimeChange     = item.CreatedDate;
                            re.IntervalChange = TimeSpan.FromSeconds(item.Duration.Value);
                        }

                        var temp = ctx.GroupUnitTasks.Where(r => r.Result == (byte)eTaskResult.NL && r.PhoneNumberId == item.PhoneNumberId &&
                                                            r.TaskType == (byte)eTaskType.CTT).OrderByDescending(r => r.Id).FirstOrDefault();
                        if (temp != null)
                        {
                            if (temp.Duration.HasValue)
                            {
                                re.TimeReceive     = temp.CreatedDate;
                                re.IntervalReceive = TimeSpan.FromSeconds(temp.Duration.Value);
                            }
                        }
                    }

                    results.Add(re);
                }
            }

            return(results);
        }
Esempio n. 30
0
        private static IQueryable <CallLogDb> BuildCallLogSearchQuery(SearchCallLogCriteria cr, NovaAlertContext ctx)
        {
            var query = ctx.CallLogDbs.Include("Details").Where(c => c.DeletedDate == null);

            if (cr.CallType > 0)
            {
                query = query.Where(c => c.CallType == cr.CallType);
            }

            if (cr.ChannelId.HasValue)
            {
                query = query.Where(c => c.Details.Any(det => det.ChannelId == cr.ChannelId.Value));
            }

            if (!string.IsNullOrEmpty(cr.UnitName))
            {
                query = query.Where(c => c.Details.Any(det => det.UnitName != null && det.UnitName.Contains(cr.UnitName)));
            }

            if (cr.StartDate.HasValue)
            {
                query = query.Where(c => SqlFunctions.DateDiff("day", c.StartTime, cr.StartDate.Value) <= 0);
            }

            if (cr.EndDate.HasValue)
            {
                query = query.Where(c => SqlFunctions.DateDiff("day", c.StartTime, cr.EndDate.Value) >= 0);
            }
            return(query);
        }