public ArchiveDto GetArchiveById(int siteId, int archiveId) { var ic = _contentRep.GetContent(siteId); var archive = ic.GetArchiveById(archiveId); if (archive == null) { return(default(ArchiveDto)); } return(ArchiveDto.ConvertFrom(archive, true, true, true)); }
public ArchiveDto GetSameCategoryNextArchive(int siteId, int archiveId) { var ic = _contentRep.GetContent(siteId); var archive = ic.GetNextSiblingArchive(archiveId); if (archive == null) { return(default(ArchiveDto)); } return(ArchiveDto.ConvertFrom(archive, true, false, false)); }
public Result SaveArchive(int siteId, int catId, ArchiveDto archiveDto) { var value = archiveDto.ToArchiveEntity(); value.CatId = catId; value.SiteId = siteId; var ic = _contentRep.GetContent(siteId); IArchive ia; if (archiveDto.Id <= 0) { ia = ic.CreateArchive(new CmsArchiveEntity()); } else { ia = ic.GetArchiveById(archiveDto.Id); } var err = ia.Set(value); if (err == null) { // 更新模板 if (!string.IsNullOrEmpty(archiveDto.TemplatePath)) { ia.SetTemplatePath(archiveDto.TemplatePath); } // 设置扩展属性 err = ia.SetExtendValue(archiveDto.ExtendValues); // 保存文档 if (err == null) { err = ia.Save(); } } var r = new Result(); if (err == null) { r.Data = new Dictionary <string, string>(); r.Data.Add("ArchiveId", ia.GetAggregaterootId().ToString()); } else { r.ErrCode = 1; r.ErrMsg = err.Message; } return(r); }
private IEnumerable <ArchiveDto> GetArchiveEnumertor(IEnumerable <IArchive> archives) { IDictionary <int, CategoryDto> categories = new Dictionary <int, CategoryDto>(); ArchiveDto archive; CategoryDto cateDto; int categoryId; foreach (var ia in archives) { var av = ia.Get(); archive = new ArchiveDto { StrId = av.StrId, Id = ia.GetAggregaterootId(), PublisherId = av.AuthorId, Alias = av.Alias, Agree = av.Agree, Disagree = av.Disagree, Content = av.Content, CreateTime = TimeUtils.UnixTime(av.CreateTime), Tags = av.Tags, UpdateTime = TimeUtils.UnixTime(av.UpdateTime), Source = av.Source, Thumbnail = av.Thumbnail, Title = av.Title, SmallTitle = av.SmallTitle, Location = av.Location, ViewCount = av.ViewCount, Outline = av.Outline, //TemplateBind=null, ExtendValues = ia.GetExtendValues() }; //archive = new ArchiveDto().CloneData(ia); //archive.ID = ia.ID; if (!categories.TryGetValue(categoryId = ia.Category.GetDomainId(), out cateDto)) { cateDto = CategoryDto.ConvertFrom(ia.Category); categories.Add(categoryId, cateDto); } archive.Category = cateDto; yield return(archive); } }
/// <summary> /// 获取文档的模板ID /// </summary> /// <param name="archive"></param> /// <returns></returns> private string GetArchiveTemplateId(ArchiveDto archive) { ////获取模板ID //string tplID = null; //Module m = CmsLogic.Module.GetModule(archive.Category.ModuleID); //if (m != null) //{ // TemplateBind tb = CmsLogic.TemplateBind.GetArchiveTemplateBind(archive.ID, archive.Category.ID); // if (tb != null) // { // string id = this.GetTemplateID(tb.TplPath); // if (id != null) // { // tplID = "/" + id; // } // } //} ////设置默认的模板 //if (String.IsNullOrEmpty(tplID)) //{ // tplID = this.FormatTemplatePath("archive"); //} //return tplID; if (archive.TemplatePath != null) { //return "/" + this.GetTemplateId(archive.TemplatePath); if (archive.TemplatePath.StartsWith("templates")) { return("/" + GetTemplateId(archive.TemplatePath)); } else { return(FormatTemplatePath(archive.TemplatePath.Replace(".tml", "").Replace(".html", ""))); } } //设置默认的模板 return(FormatTemplatePath("archive")); }
public string GetArchive(ArchiveDto archive) { #region 属性 /* * //验证密码 * PropertyBLL pbll = new PropertyBLL(); * var a = pbll.GetProperty(category.ModuleID, "pwd"); * if (a != null) * { * var json = archive.GetPropertiesJson(); * string key = json.GetValue("pwd"); * if (!String.IsNullOrEmpty(key)) * { * string requireKey = HttpContext.Current.Request.QueryString["pwd"]; * if (requireKey != key) * { * HttpContext.Current.Response.Write("<div style='margin:0 auto;padding:30px 0'>请输入密码:<input type='text'/><input type='button' value='提交' onclick=\"location.replace(location.href+'?pwd='+this.previousSibling.value)\"/></div>"); * HttpContext.Current.Response.End(); * } * * } * }*/ #endregion //获取模板ID var tplId = GetArchiveTemplateId(archive); var category = archive.Category; //用于当前的模板共享数据 Cms.Context.Items["archive.id"] = archive.Id; Cms.Context.Items["category.path"] = category.Path; Cms.Context.Items["module.id"] = category.ModuleId; //解析模板 var html = PageUtility.Require(tplId, page => { page.AddVariable("site", _site); var pageArchive = new PageArchive(archive); page.AddVariable("archive", pageArchive); page.AddVariable("category", category); page.AddVariable("module", new Module { ID = category.ModuleId }); page.AddVariable("page", new PageVariable { Title = $"{archive.Title}_{category.Name}_{_site.Title}", SubTitle = _site.Title, Keywords = archive.Tags, Description = pageArchive.Outline.Replace("\"", string.Empty) }); }); return(html); }