Exemplo n.º 1
0
 public void SaveDayTypes(List <DayTypeConfig> list)
 {
     foreach (var item in list)
     {
         var obj = _ctx.DayTypeConfigDbs.Where(a => a.DayOfWeek == item.DayOfWeek).FirstOrDefault();
         //Mapper.Map<DayTypeConfig, DayTypeConfigDb>(item, obj);
         obj.DayType = item.DayType;
     }
     _ctx.SaveChanges();
 }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
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));
                }
            }
        }
Exemplo n.º 4
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();
     }
 }
Exemplo n.º 5
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();
     }
 }
Exemplo n.º 6
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();
     }
 }
Exemplo n.º 7
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();
                }
            }
        }
Exemplo n.º 8
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();
            }
        }
Exemplo n.º 9
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));
                }
            }
        }
Exemplo n.º 10
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();
            }
        }
Exemplo n.º 11
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();
            }
        }
Exemplo n.º 12
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));
                }
            }
        }