public static void Setup(int testItems) { SetTestRepo(); for(int i=0;i<testItems;i++){ Information item=new Information(); _testRepo._items.Add(item); } }
public static void Setup(Information item) { SetTestRepo(); _testRepo._items.Add(item); }
/// <summary> /// 将Information记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.Information) /// </summary> /// <param name="model">SubSonic插件生成的实体</param> /// <returns>DataAccess.Model.Information</returns> public DataAccess.Model.Information Transform(Information model) { if (model == null) return null; return new DataAccess.Model.Information { Id = model.Id, InformationClass_Root_Id = model.InformationClass_Root_Id, InformationClass_Root_Name = model.InformationClass_Root_Name, InformationClass_Id = model.InformationClass_Id, InformationClass_Name = model.InformationClass_Name, Title = model.Title, RedirectUrl = model.RedirectUrl, Content = model.Content, Upload = model.Upload, FrontCoverImg = model.FrontCoverImg, Notes = model.Notes, NewsTime = model.NewsTime, Keywords = model.Keywords, SeoTitle = model.SeoTitle, SeoKey = model.SeoKey, SeoDesc = model.SeoDesc, Author = model.Author, FromName = model.FromName, Sort = model.Sort, IsDisplay = model.IsDisplay, IsHot = model.IsHot, IsTop = model.IsTop, IsPage = model.IsPage, IsDel = model.IsDel, CommentCount = model.CommentCount, ViewCount = model.ViewCount, AddYear = model.AddYear, AddMonth = model.AddMonth, AddDay = model.AddDay, AddDate = model.AddDate, Manager_Id = model.Manager_Id, Manager_CName = model.Manager_CName, UpdateDate = model.UpdateDate, }; }
/// <summary> /// 更新IIS缓存中指定Id记录 /// </summary> /// <param name="model">记录实体</param> public void SetModelForCache(Information model) { SetModelForCache(Transform(model)); }
/// <summary> /// 添加与编辑Information记录 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="model">Information表实体</param> /// <param name="content">更新说明</param> /// <param name="isCache">是否更新缓存</param> /// <param name="isAddUseLog">是否添加用户操作日志</param> public void Save(Page page, Information model, string content = null, bool isCache = true, bool isAddUseLog = true) { try { //保存 model.Save(); //判断是否启用缓存 if (CommonBll.IsUseCache() && isCache) { SetModelForCache(model); } if (isAddUseLog) { if (string.IsNullOrEmpty(content)) { content = "{0}" + (model.Id == 0 ? "添加" : "编辑") + "Information记录成功,ID为【" + model.Id + "】"; } //添加用户访问记录 UseLogBll.GetInstence().Save(page, content); } } catch (Exception e) { var result = "执行InformationBll.Save()函数出错!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(txtTitle.Text.Trim())) { return txtTitle.Label + "不能为空!"; } if (ddlInformationClass_Id.SelectedValue == "0") { return ddlInformationClass_Id.Label + "为必选项,请选择!"; } //判断是否重复 var sTitle = StringHelper.FilterSql(txtTitle.Text, true); var icId = ConvertHelper.Cint0(ddlInformationClass_Id.SelectedValue); if ( DataAccess.DataModel.Information.Exists( x => x.Title == sTitle && x.InformationClass_Id == icId && x.Id != id)) { return txtTitle.Label + "已存在!请重新输入!"; } #endregion #region 赋值 //获取实体 var model = new Information(x => x.Id == id); //------------------------------------------ //设置名称 model.Title = StringHelper.Left(txtTitle.Text, 100); //取得分类 model.InformationClass_Id = ConvertHelper.Cint0(ddlInformationClass_Id.SelectedValue); model.InformationClass_Root_Id = ConvertHelper.Cint0(InformationClassBll.GetInstence() .GetFieldValue(model.InformationClass_Id, InformationClassTable.ParentId)); if (model.InformationClass_Root_Id > 0) { model.InformationClass_Root_Name = InformationClassBll.GetInstence() .GetName(this, model.InformationClass_Root_Id); } model.InformationClass_Name = StringHelper.Left(ddlInformationClass_Id.SelectedText, 20); //重定向 model.RedirectUrl = StringHelper.Left(txtRedirectUrl.Text, 250); //------------------------------------------ //编辑器 model.Content = StringHelper.Left(txtText.Text, 0, true, false); model.Upload = StringHelper.Left(txtUpload.Text, 0, true, false); //这里必须用回前端存放的Key,不然删除时无法同步删除编辑器上传的图片 RndKey = StringHelper.Left(txtRndKey.Text, 0); //检查用户上传的文件和最后保存的文件是否有出入, //如果上传的文件大于保存的文件,把不保存,但本次操作已经上传的文件删除。 model.Upload = UploadFileBll.GetInstence().FCK_BatchDelPic(model.Content, model.Upload); //------------------------------------------ //其它值 model.NewsTime = dpNewsTime.SelectedDate ?? DateTime.Now; model.AddYear = model.NewsTime.Year; model.AddMonth = model.NewsTime.Month; model.AddDay = model.NewsTime.Day; model.Notes = StringHelper.Left(txtNotes.Text, 200); model.Keywords = StringHelper.Left(txtKeywords.Text, 50); model.Author = StringHelper.Left(txtAuthor.Text, 50); model.FromName = StringHelper.Left(txtFromName.Text, 50); model.SeoTitle = StringHelper.Left(txtSeoTitle.Text, 100); model.SeoKey = StringHelper.Left(txtSeoKey.Text, 100); model.SeoDesc = StringHelper.Left(txtSeoDesc.Text, 200); model.Sort = 0; //设定当前项是否显示 model.IsDisplay = ConvertHelper.StringToByte(rblIsDisplay.SelectedValue); model.IsHot = ConvertHelper.StringToByte(rblIsHot.SelectedValue); model.IsTop = ConvertHelper.StringToByte(rblIsTop.SelectedValue); //------------------------------------------ //判断是否是新增 if (model.Id == 0) { //添加时间与用户 model.AddDate = DateTime.Now; //修改时间与用户 model.UpdateDate = DateTime.Now; } else { //修改时间与用户 model.UpdateDate = DateTime.Now; } model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); #endregion //------------------------------------------ #region 上传图片 if (this.filePhoto.HasFile && this.filePhoto.FileName.Length > 3) { int vid = 3; //3 文章封面 //--------------------------------------------------- var upload = new UploadFile(); result = new UploadFileBll().Upload_AspNet(this.filePhoto.PostedFile, vid, RndKey, OnlineUsersBll.GetInstence().GetManagerId(), OnlineUsersBll.GetInstence().GetManagerCName(), upload); this.filePhoto.Dispose(); //--------------------------------------------------- if (result.Length == 0) //上传成功 { model.FrontCoverImg = upload.Path; } else { CommonBll.WriteLog("上传出错:" + result); //收集异常信息 return "上传出错!" + result; } } //如果是修改,检查用户是否重新上传过封面图片,如果是删除旧的图片 if (model.Id > 0) { UploadFileBll.GetInstence() .Upload_DiffFile(InformationTable.Id, InformationTable.FrontCoverImg, InformationTable.TableName, model.Id, model.FrontCoverImg); //同步UploadFile上传表 UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, InformationTable.TableName, model.Id); } #endregion //---------------------------------------------------------- //存储到数据库 InformationBll.GetInstence().Save(this, model); #region 同步更新上传图片表绑定Id if (id == 0) { //同步UploadFile上传表记录,绑定刚刚上传成功的文件Id为当前记录Id UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, InformationTable.TableName, model.Id); } #endregion } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return result; }