Example #1
0
        public static List <RobotBehaviorKeyphraseModel> FindAll(string _synappsDeviceId)
        {
            var dc      = new RobotBehaviorsDataContext(SqlConnectionString);
            var records =
                from n in dc.RobotBehaviorKeyphrases
                where n.SynAppsDeviceId == _synappsDeviceId
                where n.IsDeleted == false
                select n;

            return(Build(records));
        }
Example #2
0
        public static int NumberOfMeetToday(string _deviceId, string _personId)
        {
            var dc    = new RobotBehaviorsDataContext(SqlConnectionString);
            var count =
                (from n in dc.RobotBehaviorToPersons
                 where n.DeviceId == _deviceId
                 where n.PersonId == _personId
                 where n.IsDeleted == false
                 where n.CreatedAt >= DateTime.Now.Date
                 select n).Count();

            return(count);
        }
Example #3
0
        public static RobotBehaviorKeyphraseModel Find(string _synappsDeviceId, List <string> _keyphrases)
        {
            var dc      = new RobotBehaviorsDataContext(SqlConnectionString);
            var records =
                from n in dc.RobotBehaviorKeyphrases
                where n.SynAppsDeviceId == _synappsDeviceId
                where _keyphrases.Contains(n.Keyphrase)
                where n.IsDeleted == false
                select n;

            var results = Build(records);

            return(results.Count > 0 ? results.First() : null);
        }
Example #4
0
        public static void Refresh(string _synappsDeviceId, List <RobotBehaviorModel> list)
        {
            var dc         = new RobotBehaviorsDataContext(SqlConnectionString);
            var synAppsIds = (from l in list select l.SynAppsId).ToList <int>();
            var forDelete  =
                from n in dc.RobotBehaviors
                where n.SynAppsDeviceId == _synappsDeviceId
                where n.IsSynAppsLinked == true
                where !synAppsIds.Contains(n.SynAppsId)
                select n;

            Delete(forDelete);

            var newBehaviors = new List <RobotBehavior>();

            foreach (var l in list)
            {
                var behaviors =
                    from n in dc.RobotBehaviors
                    where n.SynAppsDeviceId == _synappsDeviceId
                    where n.IsSynAppsLinked == true
                    where n.SynAppsId == l.SynAppsId
                    select n;

                if (behaviors.Count() > 0)
                {
                    behaviors.First <RobotBehavior>().IsDeleted  = false;
                    behaviors.First <RobotBehavior>().Status     = l.Status;
                    behaviors.First <RobotBehavior>().ActionType = l.ActionType;
                    behaviors.First <RobotBehavior>().ActionBody = l.ActionBody;
                    behaviors.First <RobotBehavior>().UpdatedAt  = DateTime.Now;
                }
                else
                {
                    newBehaviors.Add(new RobotBehavior
                    {
                        SynAppsId       = l.SynAppsId,
                        SynAppsDeviceId = l.SynAppsDeviceId,
                        Status          = l.Status,
                        ActionType      = l.ActionType,
                        ActionBody      = l.ActionBody,
                        IsSynAppsLinked = l.IsSynAppsLinked,
                        IsDeleted       = l.IsDeleted,
                        CreatedAt       = DateTime.Now
                    });
                }
            }
            dc.RobotBehaviors.InsertAllOnSubmit(newBehaviors);
            dc.SubmitChanges();
        }
Example #5
0
        public static RobotBehaviorModel Find(string _synappsDeviceId, string _actionType)
        {
            var dc      = new RobotBehaviorsDataContext(SqlConnectionString);
            var records =
                from n in dc.RobotBehaviors
                where n.SynAppsDeviceId == _synappsDeviceId
                where n.ActionType == _actionType
                where n.IsDeleted == false
                select n;

            var results = Build(records);

            return(results.Count > 0 ? results.First() : null);
        }
Example #6
0
        public static void Refresh(string _synappsDeviceId, List <RobotBehaviorKeyphraseModel> list)
        {
            var dc         = new RobotBehaviorsDataContext(SqlConnectionString);
            var synAppsIds = (from l in list select l.SynAppsId).ToList <int>();
            var forDelete  =
                from n in dc.RobotBehaviorKeyphrases
                where n.SynAppsDeviceId == _synappsDeviceId
                where n.IsSynAppsLinked == true
                where !synAppsIds.Contains(n.SynAppsId)
                select n;

            Delete(forDelete);

            var newKeyphrases = new List <RobotBehaviorKeyphrase>();

            foreach (var l in list)
            {
                var keyphrases =
                    from n in dc.RobotBehaviorKeyphrases
                    where n.SynAppsDeviceId == _synappsDeviceId
                    where n.IsSynAppsLinked == true
                    where n.SynAppsId == l.SynAppsId
                    select n;

                if (keyphrases.Count() > 0)
                {
                    keyphrases.First <RobotBehaviorKeyphrase>().Keyphrase      = l.Keyphrase;
                    keyphrases.First <RobotBehaviorKeyphrase>().KeyphraseReply = l.KeyphraseReply;
                    keyphrases.First <RobotBehaviorKeyphrase>().Status         = l.Status;
                    keyphrases.First <RobotBehaviorKeyphrase>().UpdatedAt      = DateTime.Now;
                }
                else
                {
                    newKeyphrases.Add(new RobotBehaviorKeyphrase
                    {
                        SynAppsId       = l.SynAppsId,
                        SynAppsDeviceId = l.SynAppsDeviceId,
                        Keyphrase       = l.Keyphrase,
                        KeyphraseReply  = l.KeyphraseReply,
                        Status          = l.Status,
                        IsSynAppsLinked = l.IsSynAppsLinked,
                        IsDeleted       = l.IsDeleted,
                        CreatedAt       = DateTime.Now
                    });
                }
            }
            dc.RobotBehaviorKeyphrases.InsertAllOnSubmit(newKeyphrases);
            dc.SubmitChanges();
        }
        public static List <RobotBehaviorTalkLogModel> FindAll(string _deviceId, string _personId)
        {
            List <RobotBehaviorTalkLogModel> list = new List <RobotBehaviorTalkLogModel>();

            var dc      = new RobotBehaviorsDataContext(SqlConnectionString);
            var records =
                from n in dc.RobotBehaviorTalkLogs
                where n.DeviceId == _deviceId
                where n.PersonId == _personId
                where n.IsDeleted == false
                orderby n.CreatedAt descending
                select n;

            return(Build(records));
        }
Example #8
0
        public void Save()
        {
            var dc = new RobotBehaviorsDataContext(SqlConnectionString);

            if (this.Id == 0)
            {
                var robotBehaviorKeyphrase = new RobotBehaviorKeyphrase();
                robotBehaviorKeyphrase.SynAppsId       = this.SynAppsId;
                robotBehaviorKeyphrase.SynAppsDeviceId = this.SynAppsDeviceId;
                robotBehaviorKeyphrase.Keyphrase       = this.Keyphrase;
                robotBehaviorKeyphrase.KeyphraseReply  = this.KeyphraseReply;
                robotBehaviorKeyphrase.Status          = this.Status;
                robotBehaviorKeyphrase.IsSynAppsLinked = this.IsSynAppsLinked;
                robotBehaviorKeyphrase.IsDeleted       = this.IsDeleted;
                robotBehaviorKeyphrase.CreatedAt       = DateTime.Now;

                dc.RobotBehaviorKeyphrases.InsertOnSubmit(robotBehaviorKeyphrase);
                dc.SubmitChanges();

                this.Id        = robotBehaviorKeyphrase.Id;
                this.CreatedAt = robotBehaviorKeyphrase.CreatedAt;
            }
            else
            {
                var records =
                    from n in dc.RobotBehaviorKeyphrases
                    where n.Id == this.Id
                    select n;

                foreach (var r in records)
                {
                    r.SynAppsId       = this.SynAppsId;
                    r.SynAppsDeviceId = this.SynAppsDeviceId;
                    r.Keyphrase       = this.Keyphrase;
                    r.KeyphraseReply  = this.KeyphraseReply;
                    r.Status          = this.Status;
                    r.IsSynAppsLinked = this.IsSynAppsLinked;
                    r.IsDeleted       = this.IsDeleted;
                    r.UpdatedAt       = DateTime.Now;
                }
                dc.SubmitChanges();
            }
        }
        public void Save()
        {
            var dc = new RobotBehaviorsDataContext(SqlConnectionString);

            if (this.Id == 0)
            {
                var robotBehaviorTalkLog = new RobotBehaviorTalkLog();
                robotBehaviorTalkLog.DeviceId            = this.DeviceId;
                robotBehaviorTalkLog.PersonId            = this.PersonId;
                robotBehaviorTalkLog.RobotTalk           = this.RobotTalk;
                robotBehaviorTalkLog.PersonTalk          = this.PersonTalk;
                robotBehaviorTalkLog.PersonTalkKeyphrase = this.PersonTalkKeyphrase;
                robotBehaviorTalkLog.Status    = this.Status;
                robotBehaviorTalkLog.IsDeleted = this.IsDeleted;
                robotBehaviorTalkLog.CreatedAt = DateTime.Now;

                dc.RobotBehaviorTalkLogs.InsertOnSubmit(robotBehaviorTalkLog);
                dc.SubmitChanges();

                this.Id        = robotBehaviorTalkLog.Id;
                this.CreatedAt = robotBehaviorTalkLog.CreatedAt;
            }
            else
            {
                var records =
                    from n in dc.RobotBehaviorTalkLogs
                    where n.Id == this.Id
                    select n;

                foreach (var r in records)
                {
                    r.PersonId            = this.PersonId;
                    r.RobotTalk           = this.RobotTalk;
                    r.PersonTalk          = this.PersonTalk;
                    r.PersonTalkKeyphrase = this.PersonTalkKeyphrase;
                    r.Status    = this.Status;
                    r.IsDeleted = this.IsDeleted;
                    r.UpdatedAt = DateTime.Now;
                }
                dc.SubmitChanges();
            }
        }
Example #10
0
        public static List <RobotBehaviorToPersonModel> FindAllByDeviceIdAndPersonId(string _deviceId, string _personId)
        {
            List <RobotBehaviorToPersonModel> list = new List <RobotBehaviorToPersonModel>();

            var dc      = new RobotBehaviorsDataContext(SqlConnectionString);
            var records =
                from n in dc.RobotBehaviorToPersons
                join b in dc.RobotBehaviors on n.RobotBehaviorId equals b.SynAppsId
                where n.DeviceId == _deviceId
                where n.PersonId == _personId
                where n.IsDeleted == false
                orderby n.CreatedAt descending
                select new {
                n.Id,
                n.DeviceId,
                n.PersonId,
                n.RobotBehaviorId,
                n.Weather,
                n.Status,
                n.CreatedAt,
                b.ActionType,
                b.ActionBody
            };

            foreach (var r in records)
            {
                var model = RobotBehaviorToPersonModel.New();
                model.Id              = r.Id;
                model.DeviceId        = r.DeviceId;
                model.PersonId        = r.PersonId;
                model.RobotBehaviorId = r.RobotBehaviorId;
                model.Status          = r.Status;
                model.Weather         = r.Weather;
                model.CreatedAt       = r.CreatedAt;
                model.ActionType      = r.ActionType;
                model.ActionBody      = r.ActionBody;

                list.Add(model);
            }

            return(list);
        }
Example #11
0
        public void Save()
        {
            var dc = new RobotBehaviorsDataContext(SqlConnectionString);

            if (this.Id == 0)
            {
                var robotBehaviorToPerson = new RobotBehaviorToPerson();
                robotBehaviorToPerson.DeviceId        = this.DeviceId;
                robotBehaviorToPerson.PersonId        = this.PersonId;
                robotBehaviorToPerson.RobotBehaviorId = this.RobotBehaviorId;
                robotBehaviorToPerson.Status          = this.Status;
                robotBehaviorToPerson.Weather         = this.Weather;
                robotBehaviorToPerson.IsDeleted       = this.IsDeleted;
                robotBehaviorToPerson.CreatedAt       = DateTime.Now;

                dc.RobotBehaviorToPersons.InsertOnSubmit(robotBehaviorToPerson);
                dc.SubmitChanges();

                this.Id        = robotBehaviorToPerson.Id;
                this.CreatedAt = robotBehaviorToPerson.CreatedAt;
            }
            else
            {
                var records =
                    from n in dc.RobotBehaviorToPersons
                    where n.Id == this.Id
                    select n;

                foreach (var r in records)
                {
                    r.PersonId        = this.PersonId;
                    r.RobotBehaviorId = this.RobotBehaviorId;
                    r.Status          = this.Status;
                    r.Weather         = this.Weather;
                    r.IsDeleted       = this.IsDeleted;
                    r.UpdatedAt       = DateTime.Now;
                }
                dc.SubmitChanges();
            }
        }