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" })); } }
/// <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); }
public void SetValueFromPath_AddToNullDictionary_ThrowsException() { //Arrange var entity = new DictionaryEntity <int>(); //act PathHelper.SetValueFromPath(typeof(DictionaryEntity <int>), "/foo/0", entity, "Element One", JsonPatchOperationType.add); }
/// <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); }
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); }
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)); }
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); }
/// <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); }
/// <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); }
/// <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)); }
/// <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))); }
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); }
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); }
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); }
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); }
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); }
/// <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))); }
/// <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()); }
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" })); } }
public bool UpdateEntity(DictionaryEntity entity) { return(_dictionaryRepository.Update(entity)); }
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); }
/// <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)); }
/// <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)); }
public static Task <int> Count(ApplicationDbContext context, DictionaryEntity entity) { return(context.JGN_Dictionary.Where(returnWhereClause(entity)).CountAsync()); }
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); }
public bool AddEntity(DictionaryEntity entity) { return(_dictionaryRepository.Add(entity)); }
public bool Delete(DictionaryEntity entity) { return(_dictionaryRepository.Delete(entity)); }