コード例 #1
0
        public static List <ConversationHistoryModel> FindAllByDeviceId(string _deviceId)
        {
            var dc        = new ConversationHistoriesDataContext(SqlConnectionString);
            var histories =
                from n in dc.ConversationHistories
                where n.DeviceId == _deviceId
                select n;

            return(Build(histories));
        }
コード例 #2
0
        public static List <ConversationHistoryModel> FindAllOfUnknownMessageByDeviceId(string _deviceId)
        {
            var dc        = new ConversationHistoriesDataContext(SqlConnectionString);
            var histories =
                from n in dc.ConversationHistories
                where n.DeviceId == _deviceId
                where (n.Status == ConversationStatus.None.ObtainStatus() || n.Status == ConversationStatus.Miss.ObtainStatus())
                select n;

            return(Build(histories));
        }
コード例 #3
0
        public static List <ConversationHistoryModel> FindAllByDeviceIdAndSynAppsUnlink(string _deviceId)
        {
            var dc        = new ConversationHistoriesDataContext(SqlConnectionString);
            var histories =
                from n in dc.ConversationHistories
                where n.DeviceId == _deviceId
                where n.IsSynAppsLinked == false
                select n;

            return(Build(histories));
        }
コード例 #4
0
        public static List <ConversationHistoryModel> FindAllByDeviceId(string _deviceId, ConversationStatus _status, string _fromMessage)
        {
            var dc        = new ConversationHistoriesDataContext(SqlConnectionString);
            var histories =
                from n in dc.ConversationHistories
                where n.DeviceId == _deviceId
                where n.Status == _status.ObtainStatus()
                where n.FromMessage == _fromMessage
                select n;

            return(Build(histories));
        }
コード例 #5
0
        public static ConversationHistoryModel FindById(long _id)
        {
            var dc        = new ConversationHistoriesDataContext(SqlConnectionString);
            var histories =
                from n in dc.ConversationHistories
                where n.Id == _id
                select n;

            var list = Build(histories);

            if (list.Count > 0)
            {
                return(list.First <ConversationHistoryModel>());
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
        public static ApiResult AddMessageText(string _deviceId, string _fromUserId, string _fromMessage, string _toMessage, string _intent, double _score, long _synAppsAccountId, string _synAppsAccountName, long _assetId, ConversationStatus _status)
        {
            var apiResult = new ApiResult()
            {
                StatusCode = StatusCode.Success
            };
            var now = DateTime.UtcNow;
            var dc  = new ConversationHistoriesDataContext(SqlConnectionString);
            var conversationHistory = new ConversationHistory
            {
                DeviceId           = _deviceId,
                FromUserId         = _fromUserId,
                FromMessage        = _fromMessage,
                ToMessage          = _toMessage,
                Intent             = _intent,
                Score              = _score,
                SynAppsAccountId   = _synAppsAccountId,
                SynAppsAccountName = _synAppsAccountName,
                SynAppAssetId      = _assetId,
                Status             = _status.ObtainStatus(),
                UpdatedAt          = now,
                CreatedAt          = now
            };

            try
            {
                dc.ConversationHistories.InsertOnSubmit(conversationHistory);
                dc.SubmitChanges();
            }
            catch (Exception e)
            {
                apiResult.StatusCode = StatusCode.Error;
                apiResult.Message    = e.Message;
            }

            return(apiResult);
        }
コード例 #7
0
        public ApiResult Save()
        {
            var apiResult = new ApiResult()
            {
                StatusCode = StatusCode.Success
            };
            var now = DateTime.UtcNow;
            var dc  = new ConversationHistoriesDataContext(SqlConnectionString);

            if (this.Id == 0)
            {
                var r = new ConversationHistory();
                r.DeviceId        = this.DeviceId;
                r.FromUserId      = this.FromUserId;
                r.FromMessage     = this.FromMessage;
                r.ToMessage       = this.ToMessage;
                r.Intent          = this.Intent;
                r.Score           = this.Score;
                r.Status          = this.Status.ObtainStatus();
                r.IsSynAppsLinked = this.IsSynAppsLinked;
                r.CreatedAt       = now;
                r.UpdatedAt       = now;

                try
                {
                    dc.ConversationHistories.InsertOnSubmit(r);
                    dc.SubmitChanges();

                    this.Id        = r.Id;
                    this.CreatedAt = r.CreatedAt;
                }
                catch (Exception e)
                {
                    apiResult.StatusCode = StatusCode.Error;
                    apiResult.Message    = e.Message;
                }
            }
            else
            {
                var records =
                    from n in dc.ConversationHistories
                    where n.Id == this.Id
                    select n;

                foreach (var r in records)
                {
                    r.DeviceId        = this.DeviceId;
                    r.FromUserId      = this.FromUserId;
                    r.FromMessage     = this.FromMessage;
                    r.ToMessage       = this.ToMessage;
                    r.Intent          = this.Intent;
                    r.Score           = this.Score;
                    r.Status          = this.Status.ObtainStatus();
                    r.IsSynAppsLinked = this.IsSynAppsLinked;
                    r.UpdatedAt       = now;
                }

                try
                {
                    dc.SubmitChanges();
                }
                catch (Exception e)
                {
                    apiResult.StatusCode = StatusCode.Error;
                    apiResult.Message    = e.Message;
                }
            }

            return(apiResult);
        }