Esempio n. 1
0
        public static List <PredictionEntityModel> FindAllBySynAppsDeviceId(string _synappsDeviceId)
        {
            var dc      = new PredictionExamplesDataContext(SqlConnectionString);
            var records =
                from n in dc.PredictionEntities
                where n.SynAppsDeviceId == _synappsDeviceId
                select n;

            return(Build(records));
        }
Esempio n. 2
0
        public static ApiResult Refresh(string _synappsDeviceId, List <PredictionEntityModel> _list)
        {
            var apiResult = new ApiResult {
                StatusCode = StatusCode.Success
            };
            var dc = new PredictionExamplesDataContext(SqlConnectionString);

            dc.Connection.Open();
            using (dc.Transaction = dc.Connection.BeginTransaction())
            {
                try
                {
                    var forDelete =
                        from n in dc.PredictionEntities
                        where n.SynAppsDeviceId == _synappsDeviceId
                        select n;
                    dc.PredictionEntities.DeleteAllOnSubmit(forDelete);

                    var now      = DateTime.UtcNow;
                    var entities = new List <PredictionEntity>();
                    foreach (var entity in _list)
                    {
                        entities.Add(new PredictionEntity
                        {
                            SynAppsDeviceId = entity.SynAppsDeviceId,
                            LuisExampleId   = entity.LuisExampleId,
                            EntityName      = entity.EntityName,
                            EntityValue     = entity.EntityValue,
                            CreatedAt       = now,
                            UpdatedAt       = now
                        });
                    }
                    dc.PredictionEntities.InsertAllOnSubmit(entities);
                    dc.SubmitChanges();
                    dc.Transaction.Commit();
                }
                catch (Exception e)
                {
                    dc.Transaction.Rollback();
                    apiResult.StatusCode = StatusCode.Error;
                    apiResult.Message    = e.Message;
                }
            }
            dc.Connection.Close();

            return(apiResult);
        }
Esempio n. 3
0
        public static PredictionEntityModel FindBySynAppsDeviceIdAndLuisExampleId(string _synappsDeviceId, long _luisExampleId)
        {
            var dc      = new PredictionExamplesDataContext(SqlConnectionString);
            var records =
                from n in dc.PredictionEntities
                where n.SynAppsDeviceId == _synappsDeviceId
                where n.LuisExampleId == _luisExampleId
                select n;

            var list = Build(records);

            if (list.Count > 0)
            {
                return(list.First());
            }
            else
            {
                return(null);
            }
        }
        public static List <PredictionIntentModel> FindAllBySynAppsDeviceIdAndIntentOrderByLuisExampleId(string _synappsDeviceId, string _intent)
        {
            List <PredictionIntentModel> list = new List <PredictionIntentModel>();

            var dc      = new PredictionExamplesDataContext(SqlConnectionString);
            var records =
                from n in dc.PredictionIntents
                join b in dc.PredictionEntities on n.LuisExampleId equals b.LuisExampleId
                where n.SynAppsDeviceId == _synappsDeviceId
                where n.Intent == _intent
                where b.SynAppsDeviceId == _synappsDeviceId
                orderby n.LuisExampleId
                select new
            {
                Id = n.Id,
                SynAppsDeviceId = n.SynAppsDeviceId,
                LuisExampleId   = n.LuisExampleId,
                Intent          = n.Intent,
                EntityName      = b.EntityName,
                EntityValue     = b.EntityValue,
                CreatedAt       = n.CreatedAt,
                UpdatedAt       = n.UpdatedAt
            };

            foreach (var r in records)
            {
                var model = PredictionIntentModel.New();
                model.Id = r.Id;
                model.SynAppsDeviceId = r.SynAppsDeviceId;
                model.LuisExampleId   = r.LuisExampleId;
                model.Intent          = r.Intent;
                model.EntityName      = r.EntityName;
                model.EntityValue     = r.EntityValue;
                model.CreatedAt       = r.CreatedAt;
                model.UpdatedAt       = r.UpdatedAt;

                list.Add(model);
            }

            return(list);
        }
Esempio n. 5
0
        public ApiResult Save()
        {
            var apiResult = new ApiResult()
            {
                StatusCode = StatusCode.Success
            };
            var now = DateTime.UtcNow;
            var dc  = new PredictionExamplesDataContext(SqlConnectionString);

            if (this.Id == 0)
            {
                var r = new PredictionEntity();
                r.SynAppsDeviceId = this.SynAppsDeviceId;
                r.LuisExampleId   = this.LuisExampleId;
                r.EntityName      = this.EntityName;
                r.EntityValue     = this.EntityValue;
                r.CreatedAt       = now;
                r.UpdatedAt       = now;

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

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

                foreach (var r in records)
                {
                    r.SynAppsDeviceId = this.SynAppsDeviceId;
                    r.LuisExampleId   = this.LuisExampleId;
                    r.EntityName      = this.EntityName;
                    r.EntityValue     = this.EntityValue;
                    r.UpdatedAt       = now;
                }

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

            return(apiResult);
        }