コード例 #1
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);
        }
コード例 #2
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);
        }
 partial void UpdateConversationHistory(ConversationHistory instance);
 partial void DeleteConversationHistory(ConversationHistory instance);
 partial void InsertConversationHistory(ConversationHistory instance);