public async Task <IActionResult> UpdateResumeTags(UpdateResumeTagsModel model) { var resume = await _resumeManager.FindByIdAsync(model.Id); if (resume == null) { return(Ok("未找到简历信息。")); } if (resume.Tags == null) { resume.Tags = new List <ResumeTag>(); } resume.Tags.Clear(); // 系统未设置标签时新增标签 if (!string.IsNullOrEmpty(model.CustomTags)) { var tags = model.CustomTags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var dictionary = await _dictionaryManager.FindByNameAsync(ResumeDefaults.TagType); if (dictionary == null) { dictionary = new Dictionary() { Name = ResumeDefaults.TagType, DisplayName = "标签" } } ; if (dictionary.DictionaryItems == null) { dictionary.DictionaryItems = new List <DictionaryItem>(); } foreach (var tag in tags) { var dictionaryItem = dictionary.DictionaryItems.FirstOrDefault(f => f.Name == tag); var maxDictionaryItem = dictionary.DictionaryItems.OrderByDescending(o => o.Value).FirstOrDefault(); int maxDictionaryValue = 0; if (maxDictionaryItem != null) { maxDictionaryValue = maxDictionaryItem.Value + 1; } if (dictionaryItem == null) { dictionary.DictionaryItems.Add(new DictionaryItem() { Name = tag, Value = maxDictionaryValue }); } var tagItem = resume.Tags.FirstOrDefault(f => f.Value == tag); if (tagItem == null) { resume.Tags.Add(new ResumeTag() { Value = tag }); } } await _dictionaryManager.UpdateAsync(dictionary); } // 保存简历标签 foreach (string key in Request.Form.Keys) { if (key.StartsWith("Tag.", StringComparison.Ordinal) && Request.Form[key] == "on") { string tagValue = key.Substring("Tag.".Length); var tagItem = resume.Tags.FirstOrDefault(f => f.Value == tagValue); if (tagItem == null) { resume.Tags.Add(new ResumeTag() { Value = tagValue }); } } } await _resumeManager.UpdateAsync(resume, true); return(Ok()); }