/// <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="autoReplyId"></param> /// <returns></returns> public AutoReplyView GetDetail(int autoReplyId) { // 主表 var autoReply = Repository.Entities.FirstOrDefault(x => x.Id == autoReplyId); if (autoReply == null) { return(null); } var view = AutoReplyView.ConvertFromEntity(autoReply); // 口令 view.Keywords = _autoReplyKeywordService.GetList <AutoReplyKeywordView>(x => x.AutoReplyId == autoReplyId); // 回复 view.Contents = _autoReplyContentService.GetList <AutoReplyContentView>(x => x.AutoReplyId == autoReplyId); return(view); }
/// <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); }
public ActionResult AddQrCodeAll(int AppID) { var listSrc = _BaseService.Repository.SqlQuery("select null Deleted,null UpdatedDate,null UpdatedUserID, null CreatedUserID, id,0 AppId,0 SceneId,'' Url, name Description,null CreatedDate from QrCodeFrom", false).ToList(); var list = listSrc.Select(a => (QrCodeView) new QrCodeView().ConvertAPIModel(a)).ToList(); var autoService = EngineContext.Current.Resolve <IAutoReplyService>(); var tagService = EngineContext.Current.Resolve <ISystemUserTagService>(); //Expression<Func<AutoReply, bool>> predicate = d => true; var listTag = tagService.GetList <SystemUserTagView>(1000, d => true); foreach (var a in list) { a.AppId = AppId; AddQrCode(a); var tag = listTag.Find(b => b.Name == a.Description); var obj = new AutoReplyView() { AppId = AppID, Description = "", Name = a.Description + "[扫码关注]", KeywordType = 362, IsDeleted = false, Keywords = new List <AutoReplyKeywordView>() { new AutoReplyKeywordView() { Keyword = a.SceneId.ToString(), SecondaryType = 0 } }, Contents = new List <AutoReplyContentView>() { new AutoReplyContentView() { PrimaryType = 2, SecondaryType = 0, UserTags = new List <int>() { tag.Id }, IsEncrypt = false, IsNewContent = false, Content = "您好,终于等到你啦~" } } }; autoService.Add(obj); var obj1 = new AutoReplyView() { AppId = AppID, Description = "", Name = a.Description + "[扫码]", KeywordType = 50, IsDeleted = false, Keywords = new List <AutoReplyKeywordView>() { new AutoReplyKeywordView() { Keyword = a.SceneId.ToString(), SecondaryType = 0 } }, Contents = new List <AutoReplyContentView>() { new AutoReplyContentView() { PrimaryType = 2, SecondaryType = 0, UserTags = new List <int>() { tag.Id }, IsEncrypt = false, IsNewContent = false, Content = "您好,终于等到你啦~" } } }; autoService.Add(obj1); _BaseService.Repository.SqlExcute("delete QrCodeFrom where id=" + a.Id); } return(Json(new { result = 200 })); }