/// <summary> /// 返回业务模型对象全部的结果查询表达式 /// </summary> /// <returns></returns> public virtual IQueryable <TModel> GetQuery() { IQueryable <TEntity> query = _innerDataProvider.GetQuery(); if (typeof(MultiLanguage).IsAssignableFrom(typeof(TEntity))) { query = query.Include("LangTexts"); } //如果实现逻辑删除接口,并且没有改写EFAuditDataSerice,则在此加条件 if (typeof(ICanLogicalDeleteEntity).IsAssignableFrom(typeof(TEntity)) && _innerDataProvider.GetType() == typeof(EFAuditDataService <TEntity>)) { query = query.Where("IsDeleted=false"); } if (typeof(IDataRule).IsAssignableFrom(typeof(TEntity))) { var context = _innerDataProvider.GetContext(); var userId = AppManager.Instance.GetCurrentUserId().ToInt(); query = query.Where(t => context.Set <Sys_DataRule>().Any(dr => dr.BillId == t.Id && dr.ObjectId == userId)); } var langMapper = new LangDataMapper <TModel, TEntity>(); var duQuery = new DeptUserAuthQuery <TModel>(); return(duQuery.GetQuery(query.ProjectTo <TModel>())); }
/// <summary> /// 保存多语言的文本信息 /// </summary> /// <param name="dataService">当前的数据服务</param> /// <param name="e">数据实体对象</param> /// <param name="t">业务实体对象</param> public void SaveLanguages(EFAuditDataService <TEntity> dataService, TEntity e, TModel t) { var me = e as IMultiLanguage; if (me == null) { return; } ModelRule modelRule = ModelRule.Get <TModel>(); string entityType = typeof(TEntity).Name; var langs = ResHelper.GetUsedCultureNames().Select(l => l.ToLower()).ToArray(); if (me.LangTexts == null) { me.LangTexts = dataService.GetContext().Set <Sys_DataLanguage>().Where(d => d.BillId == e.Id && d.BillType == entityType).ToList(); } var sysLangs = me.LangTexts; foreach (var rule in modelRule.SingleRules.Where(r => r.DataType == ExtDataType.MultiLanguage)) { //先处理主文本框name不带语言后缀的表单值,表示是当前语言 string langVal = HttpContext.Current.Request.Form[rule.Name]; string currentLang = ResHelper.CurrentCultureName.ToLower(); var langEntity = sysLangs.FirstOrDefault(l => l.Language == currentLang); if (langEntity == null) { langEntity = new Sys_DataLanguage { BillId = e.Id, BillType = entityType, Language = currentLang, Name = rule.Name, Text = langVal }; dataService.MarkState(langEntity, EntityState.Added); } else if (langVal != langEntity.Text) { langEntity.Text = langVal; dataService.MarkState(langEntity, EntityState.Modified); } RefHelper.SetValue(e, rule.Name, langVal); //再处理下拉列表中的文本框name带语言后缀的表单值 foreach (var lang in langs.Where(l => l != currentLang)) { langVal = HttpContext.Current.Request.Form[rule.Name + "-" + lang]; langEntity = sysLangs.FirstOrDefault(l => l.Language == lang); if (langEntity == null) { langEntity = new Sys_DataLanguage { BillId = e.Id, BillType = entityType, Language = lang, Name = rule.Name, Text = langVal }; dataService.MarkState(langEntity, EntityState.Added); } else if (langVal != langEntity.Text) { langEntity.Text = langVal; dataService.MarkState(langEntity, EntityState.Modified); } } } }