public string CreateIdiom(JuheIdiomData dt) { Editor editor = _editors.Find(x => x.OpenId == dt.OpenId).FirstOrDefault(); if (editor != null) { try { if (Regex.IsMatch(dt.Name, "^[\u4e00-\u9fa5]+(,[\u4e00-\u9fa5]+)?$") && dt.DefText != null && dt.DefText != "") { Definition def = new Definition { Source = dt.Source, Text = dt.DefText.Replace("?", "?"), Examples = null, Addition = null, IsBold = false, Links = null }; List <Definition> defs = new List <Definition> { def }; long timeUT = DateTimeOffset.Now.ToUnixTimeSeconds(); char index = dt.Pinyin.ToUpper().ToCharArray()[0]; if (index == 'Ā' || index == 'Á' || index == 'Ǎ' || index == 'À') { index = 'A'; } else if (index == 'Ē' || index == 'É' || index == 'Ě' || index == 'È') { index = 'E'; } else if (index == 'Ō' || index == 'Ó' || index == 'Ǒ' || index == 'Ò') { index = 'O'; } _idioms.InsertOne(new Idiom { Name = dt.Name, Index = index, Pinyin = dt.Pinyin.Replace(" ", ""), Origin = null, Definitions = defs, Creator = editor.NickName, CreateTimeUT = timeUT, LastEditor = editor.NickName, UpdateTimeUT = timeUT }); var filter = Builders <Editor> .Filter.Eq("_id", editor.Id); var update = Builders <Editor> .Update.Inc("EditCount", 1); _editors.UpdateOne(filter, update); return("已自动收录!"); } } catch (Exception) { } } return("自动收录失败!"); }
public ActionResult <string> CrtIdiFrmJh([FromBody] JuheIdiomData dt) { string rtn = data.CreateIdiom(dt); return(rtn); }