/// <summary> /// 更新自动回复记录 /// 注:先删除全部再插入数据,这样做会使主键值增的比较快,但考虑到业务上口令不会经常变更,故采用此较为简单的方法 /// </summary> /// <param name="view"></param> /// <returns></returns> public int Update(AutoReplyView view) { var entity = view.ConvertToEntity(); // 口令管理表 var result = Repository.Update(entity); if (result > 0 && entity.Id > 0) { // 口令表 // 删除所有 _autoReplyKeywordService.Repository.Delete(x => x.AutoReplyId == entity.Id); foreach (var keyword in view.Keywords) { var keywordEntity = keyword.ConvertToEntity(); // 添加 _autoReplyKeywordService.Repository.Insert(keywordEntity); } // 口令回复表 // 删除所有 _autoReplyContentService.Repository.Delete(x => x.AutoReplyId == entity.Id); foreach (var content in view.Contents) { var contentEntity = content.ConvertToEntity(); _autoReplyContentService.Repository.Insert(contentEntity); } } return(result); }
/// <summary> /// 添加自动回复记录 /// </summary> /// <param name="view"></param> /// <returns></returns> public int Add(AutoReplyView view) { var entity = view.ConvertToEntity(); var result = Repository.Insert(entity); if (result > 0 && entity.Id > 0) { foreach (var keyword in view.Keywords) { var keywordEntity = keyword.ConvertToEntity(); keywordEntity.AutoReplyId = entity.Id; _autoReplyKeywordService.Repository.Insert(keywordEntity); } foreach (var content in view.Contents) { var contentEntity = content.ConvertToEntity(); contentEntity.AutoReplyId = entity.Id; _autoReplyContentService.Repository.Insert(contentEntity); } } return(result); }