Skip to content

Commit

Permalink
Merge pull request #214 from SeriaWei/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
SeriaWei authored Aug 16, 2018
2 parents ae7bfaf + 4a79602 commit 7337296
Show file tree
Hide file tree
Showing 192 changed files with 3,230 additions and 220 deletions.
1 change: 1 addition & 0 deletions DataBase/Build.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@echo off
cd /d %~dp0
REM:请根据您的个人实际情况修改以下信息:
REM:如果您运行该批处理时出现乱码或者执行不成功,请参考
REM:http://www.zkea.net/zkeacms/document/issues
Expand Down
Binary file modified DataBase/InitialData/dbo.ApplicationSetting.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.Article.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.ArticleType.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CMS_Layout.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CMS_LayoutHtml.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CMS_Media.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CMS_Message.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CMS_Page.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CMS_Redirection.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CMS_Rule.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CMS_Theme.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CMS_WidgetBase.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CMS_Zone.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.Carousel.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.CarouselItem.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.DataArchived.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.Forms.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.Language.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.Navigation.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.Permission.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.Product.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.ProductCategory.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.ProductCategoryTag.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.ProductImage.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.ProductTag.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.Roles.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.SectionContent.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.SectionGroup.Table.sql
Binary file not shown.
Binary file modified DataBase/InitialData/dbo.Users.Table.sql
Binary file not shown.
2,077 changes: 2,077 additions & 0 deletions DataBase/MySql/Dump3.1.sql

Large diffs are not rendered by default.

Binary file added DataBase/SQLite/Database-3.1.sqlite
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ApplicationSetting.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Article.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ArticleDetailWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ArticleListWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ArticleSummaryWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ArticleTopWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ArticleType.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ArticleTypeWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Basket.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CMS_Layout.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CMS_LayoutHtml.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CMS_Media.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CMS_Message.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CMS_Page.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CMS_Redirection.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CMS_Rule.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CMS_Theme.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CMS_WidgetBase.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CMS_Zone.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Carousel.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CarouselItem.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.CarouselWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Comments.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.DataArchived.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.DataDictionary.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ExtendField.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.FormData.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.FormDataItem.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Forms.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.HtmlWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ImageWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Language.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Navigation.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.NavigationWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Order.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.OrderItem.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.PageView.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Permission.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Product.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ProductCategory.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ProductCategoryTag.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ProductCategoryWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ProductDetailWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ProductImage.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ProductListWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ProductTag.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Roles.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.ScriptWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.SectionContent.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.SectionContentCallToAction.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.SectionContentImage.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.SectionContentParagraph.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.SectionContentTitle.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.SectionContentVideo.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.SectionGroup.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.SectionTemplate.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.SectionWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.StyleSheetWidget.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.UserRoleRelation.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.Users.Table.sql
Binary file not shown.
Binary file modified DataBase/Tables/dbo.VideoWidget.Table.sql
Binary file not shown.
9 changes: 9 additions & 0 deletions DataBase/Update/3.1/Scripts.Sqlite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALTER TABLE Article ADD Url NVARCHAR(100);
ALTER TABLE ArticleType ADD Url NVARCHAR(100);
ALTER TABLE ProductCategory ADD Url NVARCHAR(100);
ALTER TABLE Forms ADD NotificationReceiver NVARCHAR(500);

INSERT INTO [Language] ([LanKey], [CultureName], [LanValue], [Module], [LanType]) VALUES ('Robots@Content', 'zh-CN', '内容', 'Robots', 'EntityProperty');
INSERT INTO [Language] ([LanKey], [CultureName], [LanValue], [Module], [LanType]) VALUES ('MessageNotificationConfig@MessageNotifyEmails', 'zh-CN', '新留言通知邮箱', 'MessageNotificationConfig', 'EntityProperty');
INSERT INTO [Language] ([LanKey], [CultureName], [LanValue], [Module], [LanType]) VALUES ('MessageNotificationConfig@CommentNotifyEmails', 'zh-CN', '新评论通知邮箱', 'MessageNotificationConfig', 'EntityProperty');

11 changes: 11 additions & 0 deletions DataBase/Update/3.1/Scripts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER TABLE dbo.Article ADD Url NVARCHAR(100) NULL
ALTER TABLE dbo.ArticleType ADD Url NVARCHAR(100) NULL
ALTER TABLE dbo.ProductCategory ADD Url NVARCHAR(100) NULL

ALTER TABLE dbo.Forms ADD NotificationReceiver NVARCHAR(500) NULL

INSERT [dbo].[Language] ([LanKey], [CultureName], [LanValue], [Module], [LanType]) VALUES (N'Robots@Content', N'zh-CN', N'内容', N'Robots', N'EntityProperty')

INSERT [dbo].[Language] ([LanKey], [CultureName], [LanValue], [Module], [LanType]) VALUES (N'MessageNotificationConfig@MessageNotifyEmails', N'zh-CN', N'新留言通知邮箱', N'MessageNotificationConfig', N'EntityProperty')
INSERT [dbo].[Language] ([LanKey], [CultureName], [LanValue], [Module], [LanType]) VALUES (N'MessageNotificationConfig@CommentNotifyEmails', N'zh-CN', N'新评论通知邮箱', N'MessageNotificationConfig', N'EntityProperty')

2 changes: 1 addition & 1 deletion Dockerfile.SQLite
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN publish-zkeacms

# Copy Database
RUN mkdir /build/src/ZKEACMS.WebHost/bin/Release/PublishOutput/App_Data
RUN cp -f /build/DataBase/SQLite/Database-3.0.1.sqlite /build/src/ZKEACMS.WebHost/bin/Release/PublishOutput/App_Data/Database.sqlite
RUN cp -f /build/DataBase/SQLite/Database-3.1.sqlite /build/src/ZKEACMS.WebHost/bin/Release/PublishOutput/App_Data/Database.sqlite
RUN cp -f /build/DataBase/SQLite/appsettings.json /build/src/ZKEACMS.WebHost/bin/Release/PublishOutput/appsettings.json

# Build runtime image
Expand Down
2 changes: 1 addition & 1 deletion Release.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Add-Type -assembly "system.io.compression.filesystem"
$source = "Release"
$destination = "ZKEACMS.Core.v3.0.1.zip"
$destination = "ZKEACMS.Core.zip"
Write-Host "Starting release" $destination
Write-Host "This may take a few minutes, please wait..."
if(Test-Path $source){
Expand Down
4 changes: 2 additions & 2 deletions src/EasyFrameWork/Constant/RegularExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public class RegularExpression
/// <summary>
/// 匹配正整数
/// </summary>
public const string PositiveIntegers = @"^[1-9]+$";
public const string PositiveIntegers = @"^[1-9]\d*$";
/// <summary>
/// 匹配负整数
/// </summary>
public const string NegativeIntegers = @"^-[1-9]+$";
public const string NegativeIntegers = @"^-[1-9]\d*$";
/// <summary>
///匹配整数
/// </summary>
Expand Down
9 changes: 1 addition & 8 deletions src/EasyFrameWork/Logging/FileLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ void WriteInfo(string msg)
writer.WriteLine($"{item.Key}:{item.Value}");
}
}
if (_httpContextAccessor.HttpContext.Request.Form != null)
{
writer.WriteLine("Form:");
foreach (var item in _httpContextAccessor.HttpContext.Request.Form)
{
writer.WriteLine($"{item.Key}:{item.Value}");
}
}

writer.WriteLine(_httpContextAccessor.HttpContext.Request.GetAbsoluteUrl());
}
writer.WriteLine(Split);
Expand Down
9 changes: 5 additions & 4 deletions src/EasyFrameWork/Mvc/Plugin/DeveloperViewFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Easy.Mvc.Plugin
{
public class DeveloperViewFileProvider : IFileProvider
{
public const string ProjectRootPath = "/Porject.RootPath/";
public DeveloperViewFileProvider(IHostingEnvironment hostingEnvironment)
{
HostingEnvironment = hostingEnvironment;
Expand All @@ -22,10 +23,10 @@ public IDirectoryContents GetDirectoryContents(string subpath)

public IFileInfo GetFileInfo(string subpath)
{
if (subpath.StartsWith("/Porject.RootPath/", StringComparison.Ordinal))
if (subpath.StartsWith(ProjectRootPath, StringComparison.Ordinal))
{
var parent = new DirectoryInfo(HostingEnvironment.ContentRootPath).Parent;
var file = Path.Combine(parent.FullName, subpath.Replace("/Porject.RootPath/", "").ToFilePath());
var file = Path.Combine(parent.FullName, subpath.Replace(ProjectRootPath, string.Empty).ToFilePath());
if (File.Exists(file))
{
return new PhysicalFileInfo(new FileInfo(file));
Expand All @@ -36,10 +37,10 @@ public IFileInfo GetFileInfo(string subpath)

public IChangeToken Watch(string filter)
{
if (filter.StartsWith("/Porject.RootPath/", StringComparison.Ordinal))
if (filter.StartsWith(ProjectRootPath, StringComparison.Ordinal))
{
var parent = new DirectoryInfo(HostingEnvironment.ContentRootPath).Parent;
var file = Path.Combine(parent.FullName, filter.Replace("/Porject.RootPath/", "").ToFilePath());
var file = Path.Combine(parent.FullName, filter.Replace(ProjectRootPath, string.Empty).ToFilePath());
if (File.Exists(file))
{
return new PollingFileChangeToken(new FileInfo(file));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ private static void ConfigureRazor(RazorViewEngineOptions options, IHostingEnvir
var directory = new DirectoryInfo(m.RelativePath);
if (hostingEnvironment.IsDevelopment())
{
options.ViewLocationFormats.Add($"/Porject.RootPath/{directory.Name}" + "/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
options.ViewLocationFormats.Add($"/Porject.RootPath/{directory.Name}" + "/Views/Shared/{0}" + RazorViewEngine.ViewExtension);
options.ViewLocationFormats.Add($"/Porject.RootPath/{directory.Name}" + "/Views/{0}" + RazorViewEngine.ViewExtension);
options.ViewLocationFormats.Add($"{DeveloperViewFileProvider.ProjectRootPath}{directory.Name}" + "/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
options.ViewLocationFormats.Add($"{DeveloperViewFileProvider.ProjectRootPath}{directory.Name}" + "/Views/Shared/{0}" + RazorViewEngine.ViewExtension);
options.ViewLocationFormats.Add($"{DeveloperViewFileProvider.ProjectRootPath}{directory.Name}" + "/Views/{0}" + RazorViewEngine.ViewExtension);
}
else
{
Expand Down
40 changes: 25 additions & 15 deletions src/EasyFrameWork/Mvc/RazorPages/ViewRenderService.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,72 @@
using Microsoft.AspNetCore.Http;
using Easy.Mvc.Plugin;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Easy.Mvc.RazorPages
{
public class ViewRenderService : IViewRenderService
{
private readonly IRazorViewEngine _viewEngine;
private readonly ITempDataProvider _tempDataProvider;
private readonly IServiceProvider _serviceProvider;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IHttpContextAccessor _httpContextAccessor;

public ViewRenderService(IRazorViewEngine viewEngine, ITempDataProvider tempDataProvider,
IServiceProvider serviceProvider)
public ViewRenderService(IRazorViewEngine viewEngine, ITempDataProvider tempDataProvider, IHostingEnvironment hostingEnvironment, IHttpContextAccessor httpContextAccessor)
{
_viewEngine = viewEngine;
_tempDataProvider = tempDataProvider;
_serviceProvider = serviceProvider;
_hostingEnvironment = hostingEnvironment;
_httpContextAccessor = httpContextAccessor;
}
public string Render(string viewPath)
{
return Render(viewPath, string.Empty);
}
public string Render<TModel>(string viewPath, TModel model)
{
var httpContext = new DefaultHttpContext { RequestServices = _serviceProvider };
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
ActionContext actionContext = new ActionContext(_httpContextAccessor.HttpContext, new RouteData(), new ActionDescriptor());

string pluginPath = $"~/wwwroot/{Loader.PluginFolder}/";
string actualViewPath = viewPath;
if (_hostingEnvironment.IsDevelopment() && actualViewPath.StartsWith(pluginPath))
{
actualViewPath = actualViewPath.Replace(pluginPath, DeveloperViewFileProvider.ProjectRootPath);
}

ViewEngineResult viewResult = _viewEngine.GetView(null, actualViewPath, true);

var viewResult = _viewEngine.GetView(null, viewPath, false);
if (!viewResult.Success)
{
throw new InvalidOperationException($"找不到视图模板 {viewPath}");
throw new InvalidOperationException($"Can not find view from path: {viewPath}. If your view is in plugins, please make sure the path is starts with ~/wwwroot/{Loader.PluginFolder}/");
}

var viewDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
ViewDataDictionary viewDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
{
Model = model
};

using (var writer = new StringWriter())
using (StringWriter writer = new StringWriter())
{
var viewContext = new ViewContext(
ViewContext viewContext = new ViewContext(
actionContext,
viewResult.View,
viewDictionary,
new TempDataDictionary(actionContext.HttpContext, _tempDataProvider),
writer,
new HtmlHelperOptions()
);
var render = viewResult.View.RenderAsync(viewContext);

System.Threading.Tasks.Task render = viewResult.View.RenderAsync(viewContext);
render.Wait();
return writer.ToString();
}
Expand Down
4 changes: 4 additions & 0 deletions src/EasyFrameWork/Notification/RazorEmailNotice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ namespace Easy.Notification
public class RazorEmailNotice : EmailNotice
{
public object Model { get; set; }
/// <summary>
/// Content root view path: ~/EmailTemplates/ResetPassword.cshtml.
/// Or view in plugins: ~/wwwroot/Plugins/ZKEACMS.Article/EmailTemplates/ResetPassword.cshtml
/// </summary>
public string TemplatePath { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/EasyFrameWork/RepositoryPattern/IService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using System.Linq;
using System.Threading.Tasks;

namespace Easy.RepositoryPattern
{
Expand All @@ -16,10 +17,15 @@ public interface IService<T> : IDisposable
ServiceResult<T> AddRange(params T[] items);
IQueryable<T> Get();
T GetSingle(Expression<Func<T, bool>> filter);
Task<T> GetSingleAsync(Expression<Func<T, bool>> filter);
IList<T> Get(Expression<Func<T, bool>> filter);
Task<IList<T>> GetAsync(Expression<Func<T, bool>> filter);
IList<T> Get(Expression<Func<T, bool>> filter, Pagination pagination);
Task<IList<T>> GetAsync(Expression<Func<T, bool>> filter, Pagination pagination);
T Get(params object[] primaryKey);
Task<T> GetAsync(params object[] primaryKey);
int Count(Expression<Func<T, bool>> filter);
Task<int> CountAsync(Expression<Func<T, bool>> filter);
ServiceResult<T> Update(T item);
ServiceResult<T> UpdateRange(params T[] items);
void Remove(params object[] primaryKey);
Expand Down
49 changes: 48 additions & 1 deletion src/EasyFrameWork/RepositoryPattern/ServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Reflection;
using Easy.Extend;
using System.ComponentModel.DataAnnotations.Schema;
using System.Threading.Tasks;

namespace Easy.RepositoryPattern
{
Expand Down Expand Up @@ -113,7 +114,7 @@ public virtual ServiceResult<T> Add(T item)
SaveChanges();
}
return result;
}
}
public virtual ServiceResult<T> AddRange(params T[] items)
{
ServiceResult<T> result = new ServiceResult<T>();
Expand Down Expand Up @@ -146,6 +147,7 @@ public virtual ServiceResult<T> AddRange(params T[] items)
}
return result;
}

public virtual IQueryable<T> Get()
{
return CurrentDbSet;
Expand All @@ -154,10 +156,18 @@ public virtual T GetSingle(Expression<Func<T, bool>> filter)
{
return Get().Single(filter);
}
public virtual async Task<T> GetSingleAsync(Expression<Func<T, bool>> filter)
{
return await Get().SingleAsync(filter);
}
public virtual IList<T> Get(Expression<Func<T, bool>> filter)
{
return Get().Where(filter).ToList();
}
public virtual async Task<IList<T>> GetAsync(Expression<Func<T, bool>> filter)
{
return await Get().Where(filter).ToListAsync();
}
public virtual IList<T> Get(Expression<Func<T, bool>> filter, Pagination pagination)
{
pagination.RecordCount = Count(filter);
Expand All @@ -183,10 +193,39 @@ public virtual IList<T> Get(Expression<Func<T, bool>> filter, Pagination paginat
}
return result.Skip(pagination.PageIndex * pagination.PageSize).Take(pagination.PageSize).ToList();
}
public virtual async Task<IList<T>> GetAsync(Expression<Func<T, bool>> filter, Pagination pagination)
{
pagination.RecordCount = await CountAsync(filter);
IQueryable<T> result;
if (filter != null)
{
result = Get().Where(filter);
}
else
{
result = Get();
}
if (pagination.OrderBy != null || pagination.OrderByDescending != null)
{
if (pagination.OrderBy != null)
{
result = result.OrderBy(pagination.OrderBy);
}
else
{
result = result.OrderByDescending(pagination.OrderByDescending);
}
}
return await result.Skip(pagination.PageIndex * pagination.PageSize).Take(pagination.PageSize).ToListAsync();
}
public virtual T Get(params object[] primaryKey)
{
return CurrentDbSet.Find(primaryKey);
}
public virtual async Task<T> GetAsync(params object[] primaryKey)
{
return await CurrentDbSet.FindAsync(primaryKey);
}
public virtual int Count(Expression<Func<T, bool>> filter)
{
if (filter != null)
Expand All @@ -195,6 +234,14 @@ public virtual int Count(Expression<Func<T, bool>> filter)
}
return Get().Count();
}
public virtual async Task<int> CountAsync(Expression<Func<T, bool>> filter)
{
if (filter != null)
{
return await Get().Where(filter).CountAsync();
}
return await Get().CountAsync();
}
public virtual ServiceResult<T> Update(T item)
{
var result = Validate(item);
Expand Down
3 changes: 3 additions & 0 deletions src/ZKEACMS.Article/ArticlePlug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.Extensions.Options;
using ZKEACMS.WidgetTemplate;
using Easy.RepositoryPattern;
using ZKEACMS.Route;

namespace ZKEACMS.Article
{
Expand Down Expand Up @@ -117,6 +118,8 @@ public override void ConfigureServices(IServiceCollection serviceCollection)
{
serviceCollection.AddTransient<IArticleService, ArticleService>();
serviceCollection.AddTransient<IArticleTypeService, ArticleTypeService>();
serviceCollection.AddTransient<IRouteDataProvider, ArticleRouteDataProvider>();
serviceCollection.AddTransient<IRouteDataProvider, ArticleTypeRouteDataProvider>();
serviceCollection.AddScoped<IOnModelCreating, EntityFrameWorkModelCreating>();

serviceCollection.Configure<ArticleListWidget>(option =>
Expand Down
Loading

0 comments on commit 7337296

Please sign in to comment.