public async Task <WebResponseContent> CreatePage(App_News news) { WebResponseContent webResponseContent = WebResponseContent.Instance; if (news == null) { return(webResponseContent.Error("未获取到数据")); } if (!await repository.ExistsAsync(x => x.Id == news.Id)) { return(webResponseContent.Error("请求的数据已发生变化,请刷新页面重新提交")); } string template = FileHelper.ReadFile(@"Template\\AppHtml\\cart.html"); if (string.IsNullOrEmpty(template)) { return(webResponseContent.Error("未获取到页面的模板,请确认模板是否存在")); } string filePath; string fileName; string urlPath; if (!string.IsNullOrEmpty(news.DetailUrl) && news.DetailUrl.IndexOf("/") != -1 && news.DetailUrl.Split(".").Length == 2) { var file = news.DetailUrl.Split("/"); fileName = file[^ 1];
public WebResponseContent SetCover(App_News news) { int count = repository.Update(news, x => new { news.ImageUrl }, true); if (count == 0) { return(WebResponseContent.Instance.Error("未更新到数据")); } return(WebResponseContent.Instance.OK("封面设置成功")); }
public async Task <WebResponseContent> CreatePage(App_News news) { WebResponseContent webResponseContent = WebResponseContent.Instance; if (news == null) { return(webResponseContent.Error("未获取到数据")); } if (!await repository.ExistsAsync(x => x.Id == news.Id)) { return(webResponseContent.Error("请求的数据已发生变化,请刷新页面重新提交")); } string template = FileHelper.ReadFile(@"Template\\AppHtml\\news.html"); if (string.IsNullOrEmpty(template)) { return(webResponseContent.Error("未获取到页面的模板,请确认模板是否存在")); } string filePath; string fileName; string urlPath; if (!string.IsNullOrEmpty(news.DetailUrl) && news.DetailUrl.IndexOf("/") != -1 && news.DetailUrl.Split(".").Length == 2) { var file = news.DetailUrl.Split("/"); fileName = file[file.Length - 1]; filePath = news.DetailUrl.Replace(fileName, ""); urlPath = filePath; } else { string day = DateTime.Now.ToString("yyyyMMdd"); fileName = DateTime.Now.ToString("HHmmsss") + new Random().Next(1000, 9999) + ".html"; urlPath = $"static/news/{day}/"; filePath = urlPath.MapPath(true); } string content = template.Replace("{title}", news.Title).Replace("{date}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Replace("{content}", news.Content); FileHelper.WriteFile((filePath.IndexOf("wwwroot") == -1 ? "wwwroot/" : "") + filePath, fileName, content); //更新数据库的url news.DetailUrl = $"{urlPath}{fileName}"; repository.Update(news, x => new { news.DetailUrl, news.Content }, true); return(webResponseContent.OK("面发布成功,可预览看效果", new { url = news.DetailUrl })); }
public IActionResult SetCover([FromBody] App_News news, string t1, string t2) { return(Json(Service.SetCover(news))); }
public async Task <IActionResult> CreatePage([FromBody] App_News news) { return(Json(await Service.CreatePage(news))); }