public ActionResult AddDictionaryData()
        {
            int    id    = Convert.ToInt32(Request.Form["id"]);
            string text  = Request.Form["text"].ToString().Trim();
            int    parId = Convert.ToInt32(Request.Form["parId"]);

            DictionaryEntity entity = new DictionaryEntity
            {
                Name         = text,
                Abbreviation = string.Empty,
                ParId        = parId,
                DelFlag      = 1
            };

            if (_dictionaryService.AddEntity(entity))
            {
                return(Json(new ResultModel {
                    StatusCode = System.Net.HttpStatusCode.OK, Message = "Success"
                }));
            }
            else
            {
                return(Json(new ResultModel {
                    StatusCode = System.Net.HttpStatusCode.InternalServerError, Message = "An Error Occued when saving DictionaryEntity"
                }));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 把实体类转换成键/值对集合
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="dict"></param>
 private static void GetParameters(DictionaryEntity entity, Dictionary <string, object> dict)
 {
     dict.Add("FieldID", entity.FieldID);
     dict.Add("Title", entity.Title);
     dict.Add("TableName", entity.TableName);
     dict.Add("FieldName", entity.FieldName);
     dict.Add("FieldValue", entity.FieldValue);
 }
Exemplo n.º 3
0
        public void SetValueFromPath_AddToNullDictionary_ThrowsException()
        {
            //Arrange
            var entity = new DictionaryEntity <int>();

            //act
            PathHelper.SetValueFromPath(typeof(DictionaryEntity <int>), "/foo/0", entity, "Element One", JsonPatchOperationType.add);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 通过数据读取器生成实体类
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static DictionaryEntity GetEntityFromrdr(NullableDataReader rdr)
        {
            DictionaryEntity info = new DictionaryEntity();

            info.FieldID    = rdr.GetInt32("FieldID");
            info.Title      = rdr.GetString("Title");
            info.TableName  = rdr.GetString("TableName");
            info.FieldName  = rdr.GetString("FieldName");
            info.FieldValue = rdr.GetString("FieldValue");
            return(info);
        }
Exemplo n.º 5
0
        private Dictionary <string, double> _synonymize(Dictionary <string, double> scoredStatements)
        {
            var updatedScoredStatements = new Dictionary <string, double>();

            var keywords = KeywordExtractor.Invoke(string.Join(" ", scoredStatements.Select(x => x.Key)));

            foreach (var sentence in scoredStatements)
            {
                var tokens = NLPExtractor.Words(sentence.Key);
                var pos    = NLPExtractor.Pos(tokens);

                string recontructedStatement = "";
                double score = sentence.Value;

                for (int idx = 0; idx < tokens.Count; idx++)
                {
                    string word = tokens[idx];

                    if (keywords.Keys.Contains(word))
                    {
                        var wordEntries = Api.Invoke(tokens[idx]);
                        wordEntries.Wait();

                        if (wordEntries != null)
                        {
                            List <DictionaryEntity> results = wordEntries.Result;
                            if (results != null && results.Count > 0)
                            {
                                string currentFunctionalLabel = MapPosToFunctionalLabel(pos[idx].ToPos());

                                if (currentFunctionalLabel != null)
                                {
                                    DictionaryEntity correctDataset = results
                                                                      .Find(x => x.Fl == currentFunctionalLabel);

                                    if (correctDataset != null)
                                    {
                                        word   = SelectRandomSynonym(correctDataset.Meta.Syns);
                                        score += 0.1;
                                    }
                                }
                            }
                        }
                    }

                    recontructedStatement += string.Format("{0} ", word);
                }

                updatedScoredStatements.Add(recontructedStatement, score);
            }

            return(scoredStatements);
        }
Exemplo n.º 6
0
        public async Task UpsertAsync(string id, IDictionary <string, string> dict)
        {
            var entity = new DictionaryEntity
            {
                PartitionKey = id
            };

            foreach (var item in dict)
            {
                entity.Add(item.Key, item.Value);
            }
            await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
        }
Exemplo n.º 7
0
        public void SetValueFromPath_AddDictionaryValue_ThrowsForExistingKey()
        {
            //Arrange
            var entity = new DictionaryEntity <int>
            {
                Foo = new Dictionary <int, string> {
                    { 1, "Element One" }, { 2, "Element Two" },
                }
            };

            //act
            PathHelper.SetValueFromPath(typeof(DictionaryEntity <int>), "/foo/2", entity, "Element Three", JsonPatchOperationType.add);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取实体(异步方式)
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual async Task <DictionaryEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null)
        {
            DictionaryEntity obj    = null;
            string           strSQL = "select top 1 * from Dictionary where 1=1 " + strWhere;

            using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict)))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual DictionaryEntity GetEntity(string strWhere, Dictionary <string, object> dict = null)
        {
            DictionaryEntity obj    = null;
            string           strSQL = "select top 1 * from Dictionary where 1=1 " + strWhere;

            using (NullableDataReader reader = _DB.GetDataReader(strSQL, dict))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual bool Update(DictionaryEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update Dictionary SET " +
                            "Title = @Title," +
                            "TableName = @TableName," +
                            "FieldName = @FieldName," +
                            "FieldValue = @FieldValue" +
                            " WHERE " +

                            "FieldID = @FieldID";

            return(_DB.ExeSQLResult(strSQL, dict));
        }
Exemplo n.º 11
0
        /// <summary>
        /// 更新一条记录(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <bool> UpdateAsync(DictionaryEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update Dictionary SET " +
                            "Title = @Title," +
                            "TableName = @TableName," +
                            "FieldName = @FieldName," +
                            "FieldValue = @FieldValue" +
                            " WHERE " +

                            "FieldID = @FieldID";

            return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)));
        }
Exemplo n.º 12
0
        public void SetValueFromPath_RemoveDictionaryValue_NoOpForNonexistingKey()
        {
            //Arrange
            var entity = new DictionaryEntity <int>
            {
                Foo = new Dictionary <int, string> {
                    { 1, "Element One" }, { 2, "Element Two" },
                }
            };

            //act
            PathHelper.SetValueFromPath(typeof(DictionaryEntity <int>), "/foo/5", entity, null, JsonPatchOperationType.remove);

            //Assert
            Assert.AreEqual(2, entity.Foo.Count);
        }
Exemplo n.º 13
0
        public void SetValueFromPath_RemoveDictionaryValue_RemovesValue()
        {
            //Arrange
            var entity = new DictionaryEntity <int>
            {
                Foo = new Dictionary <int, string> {
                    { 1, "Element One" }, { 2, "Element Two" },
                }
            };

            //act
            PathHelper.SetValueFromPath(typeof(DictionaryEntity <int>), "/foo/2", entity, null, JsonPatchOperationType.remove);

            //Assert
            Assert.IsFalse(entity.Foo.ContainsKey(2));
            Assert.AreEqual(1, entity.Foo.Count);
        }
Exemplo n.º 14
0
        public void SetValueFromPath_AddDictionaryValue_AddsValue()
        {
            //Arrange
            var entity = new DictionaryEntity <int>
            {
                Foo = new Dictionary <int, string> {
                    { 1, "Element One" }, { 2, "Element Two" },
                }
            };

            //act
            PathHelper.SetValueFromPath(typeof(DictionaryEntity <int>), "/foo/3", entity, "Element Three", JsonPatchOperationType.add);

            //Assert
            Assert.AreEqual("Element Three", entity.Foo[3]);
            Assert.AreEqual(3, entity.Foo.Count);
        }
Exemplo n.º 15
0
        public void SetValueFromPath_ReplaceDictionaryByIntKey_UpdatesValue()
        {
            //Arrange
            var entity = new DictionaryEntity <int>
            {
                Foo = new Dictionary <int, string> {
                    { 1, "Element One" }, { 2, "Element Two" },
                }
            };

            //act
            PathHelper.SetValueFromPath(typeof(DictionaryEntity <int>), "/foo/2", entity, "Element Two Updated", JsonPatchOperationType.replace);

            //Assert
            Assert.AreEqual("Element Two Updated", entity.Foo[2]);
            Assert.AreEqual("Element One", entity.Foo[1]);
            Assert.AreEqual(2, entity.Foo.Count);
        }
Exemplo n.º 16
0
        public void SetValueFromPath_ReplaceDictionaryByStringKey_UpdatesValue()
        {
            //Arrange
            var entity = new DictionaryEntity <string>
            {
                Foo = new Dictionary <string, string> {
                    { "key1", "Element One" }, { "key2", "Element Two" },
                }
            };

            //act
            PathHelper.SetValueFromPath(typeof(DictionaryEntity <string>), "/foo/key1", entity, "Element One Updated", JsonPatchOperationType.replace);

            //Assert
            Assert.AreEqual("Element One Updated", entity.Foo["key1"]);
            Assert.AreEqual("Element Two", entity.Foo["key2"]);
            Assert.AreEqual(2, entity.Foo.Count);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <int> InsertAsync(DictionaryEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into Dictionary (" +
                            "Title," +
                            "TableName," +
                            "FieldName," +
                            "FieldValue) " +
                            "values(" +
                            "@Title," +
                            "@TableName," +
                            "@FieldName," +
                            "@FieldValue)";

            return(await Task.Run(() => _DB.ReturnID(strSQL, dict)));
        }
Exemplo n.º 18
0
        /// <summary>
        /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual int Insert(DictionaryEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into Dictionary (" +
                            "Title," +
                            "TableName," +
                            "FieldName," +
                            "FieldValue) " +
                            "values(" +
                            "@Title," +
                            "@TableName," +
                            "@FieldName," +
                            "@FieldValue)";

            return(_DB.ReturnID(strSQL, dict));
        }
        /// <summary>
        /// 表单
        /// </summary>
        /// <returns></returns>
        public ActionResult Form()
        {
            string action = Request.QueryString["action"].ToString();

            if (action == "update")
            {
                int id = Convert.ToInt32(Request.QueryString["id"]);
                DictionaryEntity entity = _dictionaryService.GetEntity(id);
                ViewBag.Dic   = entity;
                ViewBag.ParId = entity.ParId;
            }

            if (action == "add")
            {
                int parId = Convert.ToInt32(Request.QueryString["parId"]);
                ViewBag.ParId = parId;
            }

            ViewBag.Action = action;
            return(View());
        }
Exemplo n.º 20
0
        public async Task UpsertAsync(string id, KeyValuePair <string, string> keyValuePair)
        {
            var query = new TableQuery <DictionaryEntity>().Where(
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, id));
            var queryResults = await _table.ExecuteQuerySegmentedAsync(query, null);

            var entity = queryResults.Results.FirstOrDefault();

            if (entity == null)
            {
                entity = new DictionaryEntity
                {
                    PartitionKey = id
                };
            }
            if (entity.ContainsKey(keyValuePair.Key))
            {
                entity.Remove(keyValuePair.Key);
            }
            entity.Add(keyValuePair.Key, keyValuePair.Value);
            await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
        }
        public ActionResult UpdateDictionaryData()
        {
            int    id   = Convert.ToInt32(Request.Form["id"]);
            string text = Request.Form["text"].ToString().Trim();
            // int parId = Convert.ToInt32(Request.Form["parId"]);

            DictionaryEntity entity = _dictionaryService.GetEntity(id);

            entity.Name = text;

            if (_dictionaryService.UpdateEntity(entity))
            {
                return(Json(new ResultModel {
                    StatusCode = System.Net.HttpStatusCode.OK, Message = "Success"
                }));
            }
            else
            {
                return(Json(new ResultModel {
                    StatusCode = System.Net.HttpStatusCode.InternalServerError, Message = "An Error Occued when saving DictionaryEntity"
                }));
            }
        }
        public ActionResult Delete()
        {
            int id = Convert.ToInt32(Request.Form["id"]);
            DictionaryEntity entity = _dictionaryService.GetEntity(id);

            if (entity == null)
            {
                return(Json(new ResultModel {
                    StatusCode = System.Net.HttpStatusCode.NotFound, Message = $"The entity id {id} is not found"
                }));
            }
            if (_dictionaryService.Delete(entity))
            {
                return(Json(new ResultModel {
                    StatusCode = System.Net.HttpStatusCode.OK, Message = "Success"
                }));
            }
            else
            {
                return(Json(new ResultModel {
                    StatusCode = System.Net.HttpStatusCode.InternalServerError, Message = "An Error Occued when deleting DictionaryEntity"
                }));
            }
        }
Exemplo n.º 23
0
 public bool UpdateEntity(DictionaryEntity entity)
 {
     return(_dictionaryRepository.Update(entity));
 }
Exemplo n.º 24
0
        private static System.Linq.Expressions.Expression <Func <JGN_Dictionary, bool> > returnWhereClause(DictionaryEntity entity)
        {
            var where_clause = PredicateBuilder.New <JGN_Dictionary>(true);

            if (entity.id > 0)
            {
                where_clause = where_clause.And(p => p.id == entity.id);
            }

            if (entity.type != DictionaryType.All)
            {
                where_clause = where_clause.And(p => p.type == (byte)entity.type);
            }

            if (entity.term != "")
            {
                where_clause = where_clause.And(p => p.value.Contains(entity.term));
            }

            return(where_clause);
        }
Exemplo n.º 25
0
 /// <summary>
 /// 增加或更新一条记录(异步方式)
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual async Task <bool> AddOrUpdateAsync(DictionaryEntity entity, bool IsSave)
 {
     return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity));
 }
Exemplo n.º 26
0
 /// <summary>
 /// 增加或更新一条记录
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual bool AddOrUpdate(DictionaryEntity entity, bool IsSave)
 {
     return(IsSave ? Add(entity) : Update(entity));
 }
Exemplo n.º 27
0
 public static Task <int> Count(ApplicationDbContext context, DictionaryEntity entity)
 {
     return(context.JGN_Dictionary.Where(returnWhereClause(entity)).CountAsync());
 }
Exemplo n.º 28
0
        private static IQueryable <JGN_Dictionary> processOptionalConditions(IQueryable <JGN_Dictionary> collectionQuery, DictionaryEntity query)
        {
            if (query.order != "")
            {
                collectionQuery = (IQueryable <JGN_Dictionary>)collectionQuery.Sort(query.order);
            }
            if (query.id == 0)
            {
                // skip logic
                if (query.pagenumber > 1)
                {
                    collectionQuery = collectionQuery.Skip(query.pagesize * (query.pagenumber - 1));
                }
                // take logic
                if (!query.loadall)
                {
                    collectionQuery = collectionQuery.Take(query.pagesize);
                }
            }

            return(collectionQuery);
        }
Exemplo n.º 29
0
 public bool AddEntity(DictionaryEntity entity)
 {
     return(_dictionaryRepository.Add(entity));
 }
Exemplo n.º 30
0
 public bool Delete(DictionaryEntity entity)
 {
     return(_dictionaryRepository.Delete(entity));
 }