public async Task <ArticleForReturnDto> Execute(ArticleForCreationDto articleForCreation) { var newArticle = _mapper.Map <Article>(articleForCreation); if (!string.IsNullOrEmpty(articleForCreation.PhotoUrl)) { newArticle.Photos.Add(ArticlePhoto.Create(articleForCreation.PhotoUrl, true)); } _unitOfWork.ArticleRepository.Add(newArticle); if (await _unitOfWork.Commit()) { var articleForReturnDto = _mapper.Map <ArticleForReturnDto>(newArticle); return(articleForReturnDto); } return(null); }
public static List <Article> GetDefaultList() { // sort by name1 : 10th article/11th article/12th article/1st article/2nd article/3rd article/4th article/5th article/6th article/7th article/8th article/9th article // sort by supref : sup1 ref 1/sup1 ref 2/sup2 ref 1/sup2 ref 2/sup3 ref 1/sup3 ref 2/sup4 ref 1/sup4 ref 2/sup5 ref 1/sup5 ref 2/sup6 ref 1/sup6 ref 2 return(new List <Article>() { new ArticleBuilder().WithCode("Article01").WithName1("1st article").WithSupplierId("sup1").WithSupplierReference("sup2 ref 1").WithUnit("ST").WithPurchasePrice(10.00M) .WithPhotos(new List <ArticlePhoto>() { ArticlePhoto.Create("www.retail4u.be/article1.jpg", true) }) .Build(), new ArticleBuilder().WithCode("Article02").WithName1("2nd article").WithSupplierId("sup2").WithSupplierReference("sup2 ref 2").WithUnit("ST").WithPurchasePrice(20.00M) .WithPhotos(new List <ArticlePhoto>() { ArticlePhoto.Create("www.retail4u.be/article2.jpg", true) }) .Build(), new ArticleBuilder().WithCode("Article03").WithName1("3rd article").WithSupplierId("sup3").WithSupplierReference("sup4 ref 1").WithUnit("ST").WithPurchasePrice(30.00M) .WithPhotos(new List <ArticlePhoto>() { ArticlePhoto.Create("www.retail4u.be/article3.jpg", true) }) .Build(), new ArticleBuilder().WithCode("Article04").WithName1("4th article").WithSupplierId("sup4").WithSupplierReference("sup4 ref 2").WithUnit("ST").WithPurchasePrice(40.00M).Build(), new ArticleBuilder().WithCode("Article05").WithName1("5th article").WithSupplierId("sup5").WithSupplierReference("sup6 ref 1").WithUnit("BS").WithPurchasePrice(50.00M).Build(), new ArticleBuilder().WithCode("Article06").WithName1("6th article").WithSupplierId("sup6").WithSupplierReference("sup6 ref 2").WithUnit("ST").WithPurchasePrice(60.00M).Build(), new ArticleBuilder().WithCode("Article07").WithName1("7th article").WithSupplierId("sup7").WithSupplierReference("sup1 ref 1").WithUnit("BS").WithPurchasePrice(70.00M).Build(), new ArticleBuilder().WithCode("Article08").WithName1("8th article").WithSupplierId("sup8").WithSupplierReference("sup1 ref 2").WithUnit("ST").WithPurchasePrice(80.00M).Build(), new ArticleBuilder().WithCode("Article09").WithName1("9th article").WithSupplierId("sup9").WithSupplierReference("sup3 ref 1").WithUnit("ST").WithPurchasePrice(90.00M).Build(), new ArticleBuilder().WithCode("Article10").WithName1("10th article").WithSupplierId("sup10").WithSupplierReference("sup3 ref 2").WithUnit("BX").WithPurchasePrice(100.00M).Build(), new ArticleBuilder().WithCode("Article11").WithName1("11th article").WithSupplierId("sup11").WithSupplierReference("sup5 ref 1").WithUnit("BM").WithPurchasePrice(110.00M).Build(), new ArticleBuilder().WithCode("Article12").WithName1("12th article").WithSupplierId("sup12").WithSupplierReference("sup5 ref 2").WithUnit("BX").WithPurchasePrice(120.00M).Build() }); }
public void Insert(ArticlePhoto articlePhoto) { BusinessContext.Current.RepositoryContext.ArticlePhotoRepository.Insert(articlePhoto); }
public void Delete(ArticlePhoto articlePhoto) { BusinessContext.Current.RepositoryContext.ArticlePhotoRepository.Delete(articlePhoto); }
/// <summary> /// 发布图片文章内容页。 /// </summary> /// <param name="photoArticle">图片文章</param> /// <param name="photoArticleRelease">图片文章发布类</param> public void ReleasingPhotoArticleItem(ArticlePhoto photoArticle, Release photoArticleRelease) { // 详细页:{ReleaseDirectory}/{CategoryId}/{Year}-{Month}-{Day}/{ArticleId}.htm if (photoArticleRelease.Template.TemplateType != TemplateType.PhotoArticleItem) return; // 装载模版 photoArticleRelease.Template.TemplatePath = Regex.Replace(photoArticleRelease.Template.TemplatePath, @"\{TemplateDirectory\}", this.TemplateDirectory, RegexOptions.IgnoreCase); string templatePath = System.Web.HttpContext.Current.Server.MapPath(photoArticleRelease.Template.TemplatePath); Wis.Toolkit.Templates.TemplateManager templateManager = Wis.Toolkit.Templates.TemplateManager.LoadFile(templatePath, Encoding.UTF8); templateManager.SetVariable("ApplicationPath", this.ApplicationPath); templateManager.SetVariable("TemplateDirectory", this.TemplateDirectory); templateManager.SetVariable("ReleaseDirectory", this.ReleaseDirectory); // 处理 Release photoArticleRelease.ReleasePath = Regex.Replace(photoArticleRelease.ReleasePath, @"\{ReleaseDirectory\}", this.ReleaseDirectory, RegexOptions.IgnoreCase); photoArticleRelease.ReleasePath = Regex.Replace(photoArticleRelease.ReleasePath, @"\{CategoryId\}", photoArticle.Category.CategoryId.ToString(), RegexOptions.IgnoreCase); photoArticleRelease.ReleasePath = Regex.Replace(photoArticleRelease.ReleasePath, @"\{Year\}", photoArticle.DateCreated.Year.ToString(), RegexOptions.IgnoreCase); photoArticleRelease.ReleasePath = Regex.Replace(photoArticleRelease.ReleasePath, @"\{Month\}", photoArticle.DateCreated.Month.ToString(), RegexOptions.IgnoreCase); photoArticleRelease.ReleasePath = Regex.Replace(photoArticleRelease.ReleasePath, @"\{Day\}", photoArticle.DateCreated.Day.ToString(), RegexOptions.IgnoreCase); // 生成静态页 #warning 按照 ContentHtml 长度,生成多页,需要测试 string pagerSeparator = "<!--Article.ContentHtml.Pager-->"; if (photoArticle.ContentHtml.IndexOf(pagerSeparator) > -1) // 含有分页 { string[] contentHtmls = photoArticle.ContentHtml.Split(pagerSeparator.ToCharArray()); for (int index = 0; index < contentHtmls.Length; index++) { photoArticle.ContentHtml = contentHtmls[index] + ReleaseTinyPager((index + 1), contentHtmls.Length); templateManager.SetVariable("PhotoArticle", photoArticle); // 最近更新的文章 string replacedArticleId = string.Format("{0}/{1}", photoArticle.ArticleId, (index + 1)); //photoArticleRelease.ReleasePath = Regex.Replace(photoArticleRelease.ReleasePath, @"\{ArticleId\}", replacedArticleId, RegexOptions.IgnoreCase); string rawReleasePath = photoArticleRelease.ReleasePath; // 记录{ArticleId} photoArticleRelease.ReleasePath = Regex.Replace(rawReleasePath, @"\{ArticleId\}", replacedArticleId, RegexOptions.IgnoreCase); ReleasingStaticPage(photoArticleRelease, templateManager); photoArticleRelease.ReleasePath = rawReleasePath; ReleasingStaticPage(photoArticleRelease, templateManager); } } else { templateManager.SetVariable("PhotoArticle", photoArticle); // 最近更新的文章 photoArticleRelease.ReleasePath = Regex.Replace(photoArticleRelease.ReleasePath, @"\{ArticleId\}", photoArticle.ArticleId.ToString(), RegexOptions.IgnoreCase); ReleasingStaticPage(photoArticleRelease, templateManager); } }
/// <summary> /// 发布图片文章内容页。 /// </summary> /// <param name="photoArticle">图片文章</param> public void ReleasingPhotoArticleItem(ArticlePhoto photoArticle) { List<Release> releases = GetReleasesByCategoryGuid(photoArticle.Category.CategoryGuid, TemplateType.PhotoArticleItem); foreach (Release release in releases) { ReleasingPhotoArticleItem(photoArticle, release); } }
public void ReleasingRemovedPhotoArticle(ArticlePhoto photoArticle) { // 1 发布 PhotoArticle 页面,根据分类编号找 Item 的模版 // 2 发布 Category 页面,根据分类编号找List或Index的模版 List<Release> releases = GetReleasesByCategoryGuid(photoArticle.Category.CategoryGuid); foreach (Release release in releases) { switch (release.Template.TemplateType) { case TemplateType.PhotoArticleIndex: // 视频文章索引页 ReleasingPhotoArticleIndex(photoArticle.Category, release); break; case TemplateType.PhotoArticleList: // 视频文章列表页,带分页 ReleasingPhotoArticleList(photoArticle.Category, release); break; case TemplateType.PhotoArticleItem:// 移除文章详细页 // 处理 Release release.ReleasePath = Regex.Replace(release.ReleasePath, @"\{ReleaseDirectory\}", this.ReleaseDirectory, RegexOptions.IgnoreCase); release.ReleasePath = Regex.Replace(release.ReleasePath, @"\{CategoryId\}", photoArticle.Category.CategoryId.ToString(), RegexOptions.IgnoreCase); release.ReleasePath = Regex.Replace(release.ReleasePath, @"\{Year\}", photoArticle.DateCreated.Year.ToString(), RegexOptions.IgnoreCase); release.ReleasePath = Regex.Replace(release.ReleasePath, @"\{Month\}", photoArticle.DateCreated.Month.ToString(), RegexOptions.IgnoreCase); release.ReleasePath = Regex.Replace(release.ReleasePath, @"\{Day\}", photoArticle.DateCreated.Day.ToString(), RegexOptions.IgnoreCase); // 生成静态页 #warning 按照 ContentHtml 长度,删除多页,需要测试 string pagerSeparator = "<!--Article.ContentHtml.Pager-->"; if (photoArticle.ContentHtml.IndexOf(pagerSeparator) > -1) // 含有分页 { string[] contentHtmls = photoArticle.ContentHtml.Split(pagerSeparator.ToCharArray()); for (int index = 0; index < contentHtmls.Length; index++) { string replacedArticleId = string.Format("{0}/{1}", photoArticle.ArticleId, (index + 1)); release.ReleasePath = Regex.Replace(release.ReleasePath, @"\{ArticleId\}", replacedArticleId, RegexOptions.IgnoreCase); // 删除文章静态页 release.ReleasePath = System.Web.HttpContext.Current.Server.MapPath(release.ReleasePath); if (System.IO.File.Exists(release.ReleasePath)) System.IO.File.Delete(release.ReleasePath); } } else { release.ReleasePath = Regex.Replace(release.ReleasePath, @"\{ArticleId\}", photoArticle.ArticleId.ToString(), RegexOptions.IgnoreCase); // 删除文章静态页 release.ReleasePath = System.Web.HttpContext.Current.Server.MapPath(release.ReleasePath); if (System.IO.File.Exists(release.ReleasePath)) System.IO.File.Delete(release.ReleasePath); } break; default: throw new System.ArgumentException("TemplateType"); } } // 3 发布被引用的页面 ReleasingRelatedReleases(photoArticle.Category.CategoryGuid); }
/// <summary> /// /// </summary> /// <param name="photoArticle"></param> public void ReleasingPhotoArticle(ArticlePhoto photoArticle) { // 1 发布 VideoArticle 页面,根据分类编号找Item的模版 // 2 发布 Category 页面,根据分类编号找List或Index的模版 List<Release> releases = GetReleasesByCategoryGuid(photoArticle.Category.CategoryGuid); foreach (Release release in releases) { switch (release.Template.TemplateType) { case TemplateType.PhotoArticleIndex: // 视频文章索引页 ReleasingPhotoArticleIndex(photoArticle.Category, release); break; case TemplateType.PhotoArticleList: // 视频文章列表页,带分页 ReleasingPhotoArticleList(photoArticle.Category, release); break; case TemplateType.PhotoArticleItem:// 视频文章详细页 ReleasingPhotoArticleItem(photoArticle, release); break; default: throw new System.ArgumentException("TemplateType"); } } // 3 发布被引用的页面 ReleasingRelatedReleases(photoArticle.Category.CategoryGuid); }