diff --git a/src/EasyFrameWork/RepositoryPattern/Error.cs b/src/EasyFrameWork/Error.cs similarity index 91% rename from src/EasyFrameWork/RepositoryPattern/Error.cs rename to src/EasyFrameWork/Error.cs index 0051d51e..69b59bcf 100644 --- a/src/EasyFrameWork/RepositoryPattern/Error.cs +++ b/src/EasyFrameWork/Error.cs @@ -2,13 +2,14 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy.RepositoryPattern; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Easy.RepositoryPattern +namespace Easy { public class Error : Violation { diff --git a/src/EasyFrameWork/RepositoryPattern/ServiceResult.cs b/src/EasyFrameWork/ErrorOr.cs similarity index 80% rename from src/EasyFrameWork/RepositoryPattern/ServiceResult.cs rename to src/EasyFrameWork/ErrorOr.cs index 80b95594..75cf20d4 100644 --- a/src/EasyFrameWork/RepositoryPattern/ServiceResult.cs +++ b/src/EasyFrameWork/ErrorOr.cs @@ -2,17 +2,18 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy.RepositoryPattern; using System; using System.Collections.Generic; using System.Linq; using System.Text; -namespace Easy.RepositoryPattern +namespace Easy { - public class ServiceResult + public class ErrorOr { private readonly List _ruleViolations; - public ServiceResult() + public ErrorOr() { _ruleViolations = new List(); } @@ -138,53 +139,53 @@ public string InfoMessage } } - public static implicit operator ServiceResult(Error error) + public static implicit operator ErrorOr(Error error) { - var result = new ServiceResult(); + var result = new ErrorOr(); result._ruleViolations.Add(error); return result; } - public static implicit operator ServiceResult(Warning warning) + public static implicit operator ErrorOr(Warning warning) { - var result = new ServiceResult(); + var result = new ErrorOr(); result._ruleViolations.Add(warning); return result; } - public static implicit operator ServiceResult(Info info) + public static implicit operator ErrorOr(Info info) { - var result = new ServiceResult(); + var result = new ErrorOr(); result._ruleViolations.Add(info); return result; } } - public class ServiceResult : ServiceResult + public class ErrorOr : ErrorOr { - public ServiceResult() { } - public ServiceResult(T result) + public ErrorOr() { } + public ErrorOr(T result) { Result = result; } public T Result { get; set; } - public static implicit operator ServiceResult(T result) + public static implicit operator ErrorOr(T result) { - return new ServiceResult(result); + return new ErrorOr(result); } - public static implicit operator ServiceResult(Error error) + public static implicit operator ErrorOr(Error error) { - var result = new ServiceResult(); + var result = new ErrorOr(); result.AddError(error); return result; } - public static implicit operator ServiceResult(Warning warning) + public static implicit operator ErrorOr(Warning warning) { - var result = new ServiceResult(); + var result = new ErrorOr(); result.AddWarning(warning); return result; } - public static implicit operator ServiceResult(Info info) + public static implicit operator ErrorOr(Info info) { - var result = new ServiceResult(); + var result = new ErrorOr(); result.AddInfo(info); return result; } diff --git a/src/EasyFrameWork/RepositoryPattern/Info.cs b/src/EasyFrameWork/Info.cs similarity index 91% rename from src/EasyFrameWork/RepositoryPattern/Info.cs rename to src/EasyFrameWork/Info.cs index 54d2fa38..ffcffb03 100644 --- a/src/EasyFrameWork/RepositoryPattern/Info.cs +++ b/src/EasyFrameWork/Info.cs @@ -2,13 +2,14 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy.RepositoryPattern; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Easy.RepositoryPattern +namespace Easy { public class Info : Violation { diff --git a/src/EasyFrameWork/Modules/MutiLanguage/ILanguageService.cs b/src/EasyFrameWork/Modules/MutiLanguage/ILanguageService.cs index b5b41766..dedfe92d 100644 --- a/src/EasyFrameWork/Modules/MutiLanguage/ILanguageService.cs +++ b/src/EasyFrameWork/Modules/MutiLanguage/ILanguageService.cs @@ -11,12 +11,12 @@ namespace Easy.Modules.MutiLanguage { public interface ILanguageService { - ServiceResult Add(LanguageEntity entity); - ServiceResult AddOrUpdate(LanguageEntity entity); + ErrorOr Add(LanguageEntity entity); + ErrorOr AddOrUpdate(LanguageEntity entity); IEnumerable Get(Expression> expression, Pagination pagination); IEnumerable GetCultures(string lanKey); LanguageEntity Get(string lanKey, string cultureName); - ServiceResult Update(LanguageEntity entity); + ErrorOr Update(LanguageEntity entity); string[] GetCultureCodes(); } } diff --git a/src/EasyFrameWork/Modules/MutiLanguage/LanguageService.cs b/src/EasyFrameWork/Modules/MutiLanguage/LanguageService.cs index 2e2e4432..35de9489 100644 --- a/src/EasyFrameWork/Modules/MutiLanguage/LanguageService.cs +++ b/src/EasyFrameWork/Modules/MutiLanguage/LanguageService.cs @@ -104,9 +104,9 @@ private ConcurrentDictionary Save(LanguageEntity item) + private ErrorOr Save(LanguageEntity item) { - var result = new ServiceResult(); + var result = new ErrorOr(); var localeFile = Path.Combine(GetLocaleDirectory(), $"{item.CultureName}.yml"); try { @@ -122,7 +122,7 @@ private ServiceResult Save(LanguageEntity item) return result; } - public ServiceResult Add(LanguageEntity item) + public ErrorOr Add(LanguageEntity item) { return Save(item); } @@ -146,13 +146,13 @@ public IEnumerable GetCultures(string lanKey) } } } - public ServiceResult Update(LanguageEntity item) + public ErrorOr Update(LanguageEntity item) { return Save(item); } - public ServiceResult AddOrUpdate(LanguageEntity entity) + public ErrorOr AddOrUpdate(LanguageEntity entity) { LanguageEntity translate = Get(entity.LanKey, entity.CultureName); if (translate == null) diff --git a/src/EasyFrameWork/Modules/Role/IRoleService.cs b/src/EasyFrameWork/Modules/Role/IRoleService.cs index 39dc38af..7fbbb78c 100644 --- a/src/EasyFrameWork/Modules/Role/IRoleService.cs +++ b/src/EasyFrameWork/Modules/Role/IRoleService.cs @@ -7,7 +7,7 @@ namespace Easy.Modules.Role public interface IRoleService : IService { IList GetPermission(int roleId); - ServiceResult Add(RoleEntity roleEntity, List permissionDescriptors); - ServiceResult Update(RoleEntity roleEntity, List permissionDescriptors); + ErrorOr Add(RoleEntity roleEntity, List permissionDescriptors); + ErrorOr Update(RoleEntity roleEntity, List permissionDescriptors); } } \ No newline at end of file diff --git a/src/EasyFrameWork/Modules/Role/RoleService.cs b/src/EasyFrameWork/Modules/Role/RoleService.cs index 39e20362..9a665efa 100644 --- a/src/EasyFrameWork/Modules/Role/RoleService.cs +++ b/src/EasyFrameWork/Modules/Role/RoleService.cs @@ -32,7 +32,7 @@ public override DbSet CurrentDbSet } } - public ServiceResult Add(RoleEntity roleEntity, List permissionDescriptors) + public ErrorOr Add(RoleEntity roleEntity, List permissionDescriptors) { return BeginTransaction(() => { @@ -60,7 +60,7 @@ public IList GetPermission(int roleId) return _permissionService.Get(m => m.RoleId == roleId); } - public ServiceResult Update(RoleEntity roleEntity, List permissionDescriptors) + public ErrorOr Update(RoleEntity roleEntity, List permissionDescriptors) { return BeginTransaction(() => { diff --git a/src/EasyFrameWork/Modules/User/Service/UserService.cs b/src/EasyFrameWork/Modules/User/Service/UserService.cs index cdc20784..690cdc26 100644 --- a/src/EasyFrameWork/Modules/User/Service/UserService.cs +++ b/src/EasyFrameWork/Modules/User/Service/UserService.cs @@ -55,7 +55,7 @@ private string ProtectPassWord(string passWord) } return passWord; } - public override ServiceResult Add(UserEntity item) + public override ErrorOr Add(UserEntity item) { if (item.UserID.IsNullOrEmpty() && item.Email.IsNotNullAndWhiteSpace()) { @@ -100,7 +100,7 @@ public override ServiceResult Add(UserEntity item) return result; } - public override ServiceResult Update(UserEntity item) + public override ErrorOr Update(UserEntity item) { if (item.PassWordNew.IsNotNullAndWhiteSpace()) { diff --git a/src/EasyFrameWork/RepositoryPattern/IService.cs b/src/EasyFrameWork/RepositoryPattern/IService.cs index acea7883..a8d3ec18 100644 --- a/src/EasyFrameWork/RepositoryPattern/IService.cs +++ b/src/EasyFrameWork/RepositoryPattern/IService.cs @@ -17,8 +17,8 @@ public interface IService : IDisposable { IApplicationContext ApplicationContext { get; set; } void BeginTransaction(Action action); - ServiceResult Add(T item); - ServiceResult AddRange(params T[] items); + ErrorOr Add(T item); + ErrorOr AddRange(params T[] items); IQueryable Get(); T GetSingle(Expression> filter); Task GetSingleAsync(Expression> filter); @@ -30,8 +30,8 @@ public interface IService : IDisposable Task GetAsync(params object[] primaryKey); int Count(Expression> filter); Task CountAsync(Expression> filter); - ServiceResult Update(T item); - ServiceResult UpdateRange(params T[] items); + ErrorOr Update(T item); + ErrorOr UpdateRange(params T[] items); void Remove(params object[] primaryKey); void Remove(T item); void Remove(Expression> filter); diff --git a/src/EasyFrameWork/RepositoryPattern/ServiceBase.cs b/src/EasyFrameWork/RepositoryPattern/ServiceBase.cs index ad6d6a70..8b1c88ed 100644 --- a/src/EasyFrameWork/RepositoryPattern/ServiceBase.cs +++ b/src/EasyFrameWork/RepositoryPattern/ServiceBase.cs @@ -72,7 +72,7 @@ public TEntity BeginTransaction(Func action) try { var result = action.Invoke(); - if (result is ServiceResult sResult && sResult.HasError) + if (result is ErrorOr sResult && sResult.HasError) { transaction.Rollback(); } @@ -94,9 +94,9 @@ public TEntity BeginTransaction(Func action) return action.Invoke(); } } - protected virtual ServiceResult Validate(T item) + protected virtual ErrorOr Validate(T item) { - ServiceResult serviceResult = new ServiceResult(); + ErrorOr serviceResult = new ErrorOr(); var entryType = typeof(T); var viewConfig = ServiceLocator.GetViewConfigure(typeof(T)); if (viewConfig != null) @@ -123,7 +123,7 @@ protected virtual ServiceResult Validate(T item) serviceResult.Result = item; return serviceResult; } - public virtual ServiceResult Add(T item) + public virtual ErrorOr Add(T item) { var result = Validate(item); if (result.HasError) @@ -148,9 +148,9 @@ public virtual ServiceResult Add(T item) SaveChanges(); return result; } - public virtual ServiceResult AddRange(params T[] items) + public virtual ErrorOr AddRange(params T[] items) { - ServiceResult result = new ServiceResult(); + ErrorOr result = new ErrorOr(); foreach (var item in items) { var itemResult = Validate(item); @@ -284,7 +284,7 @@ public virtual async Task CountAsync(Expression> filter) } return await Get().CountAsync(); } - public virtual ServiceResult Update(T item) + public virtual ErrorOr Update(T item) { var result = Validate(item); if (result.HasError) @@ -305,7 +305,7 @@ public virtual ServiceResult Update(T item) SaveChanges(); return result; } - public virtual ServiceResult UpdateRange(params T[] items) + public virtual ErrorOr UpdateRange(params T[] items) { foreach (var item in items) { @@ -327,7 +327,7 @@ public virtual ServiceResult UpdateRange(params T[] items) } CurrentDbSet.UpdateRange(items); SaveChanges(); - return new ServiceResult(); + return new ErrorOr(); } public void Remove(params object[] primaryKey) { diff --git a/src/EasyFrameWork/RepositoryPattern/Warning.cs b/src/EasyFrameWork/Warning.cs similarity index 91% rename from src/EasyFrameWork/RepositoryPattern/Warning.cs rename to src/EasyFrameWork/Warning.cs index 4114da8c..9e74756d 100644 --- a/src/EasyFrameWork/RepositoryPattern/Warning.cs +++ b/src/EasyFrameWork/Warning.cs @@ -2,13 +2,14 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy.RepositoryPattern; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Easy.RepositoryPattern +namespace Easy { public class Warning : Violation { diff --git a/src/ZKEACMS.Article/Service/ArticleApiService.cs b/src/ZKEACMS.Article/Service/ArticleApiService.cs index e80406ea..47d051b4 100644 --- a/src/ZKEACMS.Article/Service/ArticleApiService.cs +++ b/src/ZKEACMS.Article/Service/ArticleApiService.cs @@ -2,8 +2,8 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy; using Easy.Mvc.Authorize; -using Easy.RepositoryPattern; using System; using System.Collections.Generic; using System.Linq; @@ -55,7 +55,7 @@ public ArticleEntity GetByName(string name) } return article; } - public ServiceResult Create(ArticleEntity article) + public ErrorOr Create(ArticleEntity article) { var validResult = ValidArticleType(article); if (validResult.HasError) return validResult; @@ -64,7 +64,7 @@ public ServiceResult Create(ArticleEntity article) return _articleService.Add(article); } - public ServiceResult Update(ArticleEntity article) + public ErrorOr Update(ArticleEntity article) { var validResult = ValidArticleType(article); if (validResult.HasError) return validResult; @@ -73,9 +73,9 @@ public ServiceResult Update(ArticleEntity article) return _articleService.Update(article); } - private ServiceResult ValidArticleType(ArticleEntity article) + private ErrorOr ValidArticleType(ArticleEntity article) { - ServiceResult serviceResult = new ServiceResult(); + ErrorOr serviceResult = new ErrorOr(); ArticleType articleType = _articleTypeService.Get(article.ArticleTypeID ?? 0); if (articleType == null) { diff --git a/src/ZKEACMS.Article/Service/ArticleDetailWidgetService.cs b/src/ZKEACMS.Article/Service/ArticleDetailWidgetService.cs index fb4e89c5..7a00a27f 100644 --- a/src/ZKEACMS.Article/Service/ArticleDetailWidgetService.cs +++ b/src/ZKEACMS.Article/Service/ArticleDetailWidgetService.cs @@ -14,7 +14,6 @@ using Easy.Extend; using System.Collections.Concurrent; using Easy.Cache; -using Easy.RepositoryPattern; using Easy.Constant; using ZKEACMS.StructuredData; using Easy.Serializer; @@ -50,13 +49,13 @@ private void DismissRelatedPageUrls() _cacheManager.Remove(ArticleDetailWidgetRelatedPageUrls); } - public override ServiceResult Add(ArticleDetailWidget item) + public override ErrorOr Add(ArticleDetailWidget item) { var result = base.Add(item); DismissRelatedPageUrls(); return result; } - public override ServiceResult Update(ArticleDetailWidget item) + public override ErrorOr Update(ArticleDetailWidget item) { var result = base.Update(item); DismissRelatedPageUrls(); diff --git a/src/ZKEACMS.Article/Service/ArticleListWidgetService.cs b/src/ZKEACMS.Article/Service/ArticleListWidgetService.cs index f6470bfc..3097e1f0 100644 --- a/src/ZKEACMS.Article/Service/ArticleListWidgetService.cs +++ b/src/ZKEACMS.Article/Service/ArticleListWidgetService.cs @@ -48,7 +48,7 @@ private string GetDetailPageUrl() return "~/article-detail"; } - public override ServiceResult Add(ArticleListWidget item) + public override ErrorOr Add(ArticleListWidget item) { if (item.DetailPageUrl.IsNullOrEmpty()) { diff --git a/src/ZKEACMS.Article/Service/ArticleService.cs b/src/ZKEACMS.Article/Service/ArticleService.cs index 400fc1f8..4a961946 100644 --- a/src/ZKEACMS.Article/Service/ArticleService.cs +++ b/src/ZKEACMS.Article/Service/ArticleService.cs @@ -28,9 +28,9 @@ public ArticleService(IApplicationContext applicationContext, _localize = localize; _eventManager = eventManager; } - public override ServiceResult Add(ArticleEntity item) + public override ErrorOr Add(ArticleEntity item) { - ServiceResult result; + ErrorOr result; if (item.Url.IsNotNullAndWhiteSpace() && GetByUrl(item.Url) != null) { return new Error("Url", _localize.Get("URL already exists")); @@ -43,9 +43,9 @@ public override ServiceResult Add(ArticleEntity item) } return result; } - public override ServiceResult Update(ArticleEntity item) + public override ErrorOr Update(ArticleEntity item) { - ServiceResult result; + ErrorOr result; if (item.Url.IsNotNullAndWhiteSpace() && Count(m => m.Url == item.Url && m.ID != item.ID) > 0) { return new Error("Url", _localize.Get("URL already exists")); diff --git a/src/ZKEACMS.Article/Service/ArticleTypeApiService.cs b/src/ZKEACMS.Article/Service/ArticleTypeApiService.cs index 18925520..74591fb8 100644 --- a/src/ZKEACMS.Article/Service/ArticleTypeApiService.cs +++ b/src/ZKEACMS.Article/Service/ArticleTypeApiService.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using System; using System.Collections.Generic; using System.Linq; @@ -21,16 +21,16 @@ public ArticleTypeApiService(IArticleTypeService articleTypeService) _articleTypeService = articleTypeService; } - public ServiceResult Create(ArticleType articleType) + public ErrorOr Create(ArticleType articleType) { var validResult= ValidParentId(articleType); if (validResult.HasError) return validResult; return _articleTypeService.Add(articleType); } - private ServiceResult ValidParentId(ArticleType articleType) + private ErrorOr ValidParentId(ArticleType articleType) { - ServiceResult result = new ServiceResult(); + ErrorOr result = new ErrorOr(); if (articleType.ParentID.HasValue) { var parentArticleType = _articleTypeService.Get(articleType.ParentID.Value); @@ -56,7 +56,7 @@ public ArticleType GetByName(string name) return _articleTypeService.GetByUrl(name); } - public ServiceResult Update(ArticleType articleType) + public ErrorOr Update(ArticleType articleType) { var validResult = ValidParentId(articleType); if (validResult.HasError) return validResult; diff --git a/src/ZKEACMS.Article/Service/ArticleTypeService.cs b/src/ZKEACMS.Article/Service/ArticleTypeService.cs index 47ac698c..971bccec 100644 --- a/src/ZKEACMS.Article/Service/ArticleTypeService.cs +++ b/src/ZKEACMS.Article/Service/ArticleTypeService.cs @@ -24,7 +24,7 @@ public ArticleTypeService(IApplicationContext applicationContext, IArticleServic _localize = localize; } - public override ServiceResult Add(ArticleType item) + public override ErrorOr Add(ArticleType item) { item.ParentID = item.ParentID ?? 0; if (item.Url.IsNotNullAndWhiteSpace()&& GetByUrl(item.Url) != null) @@ -33,7 +33,7 @@ public override ServiceResult Add(ArticleType item) } return base.Add(item); } - public override ServiceResult Update(ArticleType item) + public override ErrorOr Update(ArticleType item) { if (item.Url.IsNotNullAndWhiteSpace() && Count(m => m.Url == item.Url && m.ID != item.ID) > 0) { diff --git a/src/ZKEACMS.Article/Service/IArticleApiService.cs b/src/ZKEACMS.Article/Service/IArticleApiService.cs index a57fac33..bae7b041 100644 --- a/src/ZKEACMS.Article/Service/IArticleApiService.cs +++ b/src/ZKEACMS.Article/Service/IArticleApiService.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using System; using System.Collections.Generic; using System.Linq; @@ -16,8 +16,8 @@ public interface IArticleApiService { ArticleEntity Get(int id); ArticleEntity GetByName(string name); - ServiceResult Create(ArticleEntity article); - ServiceResult Update(ArticleEntity article); + ErrorOr Create(ArticleEntity article); + ErrorOr Update(ArticleEntity article); ArticleEntity Publish(int id); void Delete(int id); } diff --git a/src/ZKEACMS.Article/Service/IArticleTypeApiService.cs b/src/ZKEACMS.Article/Service/IArticleTypeApiService.cs index d87c0ca3..f4852f13 100644 --- a/src/ZKEACMS.Article/Service/IArticleTypeApiService.cs +++ b/src/ZKEACMS.Article/Service/IArticleTypeApiService.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using System; using System.Collections.Generic; using System.Linq; @@ -16,8 +16,8 @@ public interface IArticleTypeApiService { ArticleType Get(int id); ArticleType GetByName(string name); - ServiceResult Create(ArticleType articleType); - ServiceResult Update(ArticleType articleType); + ErrorOr Create(ArticleType articleType); + ErrorOr Update(ArticleType articleType); void Delete(int id); } } diff --git a/src/ZKEACMS.EventAction/ActionExecutor/ActionContent.cs b/src/ZKEACMS.EventAction/ActionExecutor/ActionContent.cs index e69e2940..6286219d 100644 --- a/src/ZKEACMS.EventAction/ActionExecutor/ActionContent.cs +++ b/src/ZKEACMS.EventAction/ActionExecutor/ActionContent.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using Fluid; using System; using System.Collections.Concurrent; @@ -48,9 +48,9 @@ public Dictionary GetRendedWith(object model) } return renderedArgs; } - public ServiceResult ParseTemplate(string key, string template) + public ErrorOr ParseTemplate(string key, string template) { - var result = new ServiceResult(); + var result = new ErrorOr(); try { var templateResult = _templates.GetOrAdd(key, key => @@ -66,9 +66,9 @@ public ServiceResult ParseTemplate(string key, string template) } return result; } - public ServiceResult ValidateWith() + public ErrorOr ValidateWith() { - var result = new ServiceResult(); + var result = new ErrorOr(); if (With == null) return result; foreach (var item in With) diff --git a/src/ZKEACMS.EventAction/ActionExecutor/Executors/EmailExecutor.cs b/src/ZKEACMS.EventAction/ActionExecutor/Executors/EmailExecutor.cs index 9a2a67ae..0c805ea6 100644 --- a/src/ZKEACMS.EventAction/ActionExecutor/Executors/EmailExecutor.cs +++ b/src/ZKEACMS.EventAction/ActionExecutor/Executors/EmailExecutor.cs @@ -2,9 +2,9 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy; using Easy.Extend; using Easy.Notification; -using Easy.RepositoryPattern; using System; using System.Collections.Generic; using System.IO; @@ -27,7 +27,7 @@ public EmailExecutor(IActionBodyService actionBodyService, INotificationManager _notificationManager = notificationManager; } - public ServiceResult Execute(Arguments args, object model, EventArg e) + public ErrorOr Execute(Arguments args, object model, EventArg e) { EmailMessage emailMessage = CreateEmailMessage(args); string emailBody = args.Named("body"); @@ -44,10 +44,10 @@ public ServiceResult Execute(Arguments args, object model, EventArg e) emailMessage.Content = emailBody; emailMessage.IsHtml = true; - if (emailMessage.To == null || emailMessage.To.Length == 0) return new ServiceResult(); + if (emailMessage.To == null || emailMessage.To.Length == 0) return new ErrorOr(); _notificationManager.Send(emailMessage); - return new ServiceResult(); + return new ErrorOr(); } private EmailMessage CreateEmailMessage(Arguments args) { diff --git a/src/ZKEACMS.EventAction/ActionExecutor/Executors/HttpExecutor.cs b/src/ZKEACMS.EventAction/ActionExecutor/Executors/HttpExecutor.cs index 6c554f3a..dd237b71 100644 --- a/src/ZKEACMS.EventAction/ActionExecutor/Executors/HttpExecutor.cs +++ b/src/ZKEACMS.EventAction/ActionExecutor/Executors/HttpExecutor.cs @@ -2,8 +2,8 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy; using Easy.Extend; -using Easy.RepositoryPattern; using System.Collections.Generic; using ZKEACMS.Event; using ZKEACMS.EventAction.HttpParser; @@ -25,7 +25,7 @@ public HttpExecutor(IActionBodyService actionBodyService, IPendingTaskService pe _pendingTaskService = pendingTaskService; } - public ServiceResult Execute(Arguments args, object model, EventArg e) + public ErrorOr Execute(Arguments args, object model, EventArg e) { string requestBody = args.Named("request"); @@ -36,11 +36,11 @@ public ServiceResult Execute(Arguments args, object model, EventArg e) requestBody = _actionBodyService.RenderBody(id, model); } - if (requestBody.IsNullOrWhiteSpace()) return new ServiceResult(); + if (requestBody.IsNullOrWhiteSpace()) return new ErrorOr(); var request = HttpRequestContent.Parse(requestBody); PushRequestInQueue(request); - return new ServiceResult(); + return new ErrorOr(); } private void PushRequestInQueue(HttpRequestContent httpRequest) { diff --git a/src/ZKEACMS.EventAction/ActionExecutor/IActionExecutor.cs b/src/ZKEACMS.EventAction/ActionExecutor/IActionExecutor.cs index 2c82cca3..f7367905 100644 --- a/src/ZKEACMS.EventAction/ActionExecutor/IActionExecutor.cs +++ b/src/ZKEACMS.EventAction/ActionExecutor/IActionExecutor.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using System; using System.Collections.Generic; using System.Linq; @@ -14,6 +14,6 @@ namespace ZKEACMS.EventAction.ActionExecutor { public interface IActionExecutor { - ServiceResult Execute(Arguments args, object model, EventArg e); + ErrorOr Execute(Arguments args, object model, EventArg e); } } diff --git a/src/ZKEACMS.EventAction/HttpParser/HttpRequesetTaskHandler.cs b/src/ZKEACMS.EventAction/HttpParser/HttpRequesetTaskHandler.cs index a1da9bfa..370cf08c 100644 --- a/src/ZKEACMS.EventAction/HttpParser/HttpRequesetTaskHandler.cs +++ b/src/ZKEACMS.EventAction/HttpParser/HttpRequesetTaskHandler.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -24,19 +24,19 @@ public HttpRequesetTaskHandler(IHttpClientFactory httpClientFactory) _httpClientFactory = httpClientFactory; } - public override Task> ExecuteAsync(object context) + public override Task> ExecuteAsync(object context) { return SendAsync(context as HttpRequestContent); } - public async Task> SendAsync(HttpRequestContent httpRequest) + public async Task> SendAsync(HttpRequestContent httpRequest) { using (var response = await _httpClientFactory.CreateClient().SendAsync(httpRequest.ConvertToHttpRequestMessage())) { string responseContent = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) throw new Exception($"Send http request with error.\r\nPayload:\r\n{httpRequest}\r\nResponse:\r\n{responseContent}"); - return new ServiceResult(responseContent); + return new ErrorOr(responseContent); } } } diff --git a/src/ZKEACMS.EventAction/Service/ActionBodyService.cs b/src/ZKEACMS.EventAction/Service/ActionBodyService.cs index 5da23749..6775c3b9 100644 --- a/src/ZKEACMS.EventAction/Service/ActionBodyService.cs +++ b/src/ZKEACMS.EventAction/Service/ActionBodyService.cs @@ -29,12 +29,12 @@ public ActionBodyService(IApplicationContext applicationContext, CMSDbContext db { } - public override ServiceResult Add(ActionBody item) + public override ErrorOr Add(ActionBody item) { IFluidTemplate templateResult = null; if (item.Body.IsNotNullAndWhiteSpace() && !FluidTemplateHelper.TryParse(item.Body, out templateResult, out var error)) { - var result = new ServiceResult(); + var result = new ErrorOr(); result.AddError("Body", error); return result; } @@ -46,12 +46,12 @@ public override ServiceResult Add(ActionBody item) return addResult; } - public override ServiceResult Update(ActionBody item) + public override ErrorOr Update(ActionBody item) { IFluidTemplate templateResult = null; if (item.Body.IsNotNullAndWhiteSpace() && !FluidTemplateHelper.TryParse(item.Body, out templateResult, out var error)) { - var result = new ServiceResult(); + var result = new ErrorOr(); result.AddError("Body", error); return result; } @@ -69,9 +69,9 @@ public string RenderBody(int ID, object model) return template.Render(model); } - private ServiceResult ParseTemplate(int ID) + private ErrorOr ParseTemplate(int ID) { - var result = new ServiceResult(); + var result = new ErrorOr(); try { var template = _templates.GetOrAdd(ID, key => diff --git a/src/ZKEACMS.EventAction/Service/EventActionService.cs b/src/ZKEACMS.EventAction/Service/EventActionService.cs index 71a50725..5c0ebe31 100644 --- a/src/ZKEACMS.EventAction/Service/EventActionService.cs +++ b/src/ZKEACMS.EventAction/Service/EventActionService.cs @@ -44,7 +44,7 @@ public EventActionService(IApplicationContext applicationContext, CMSDbContext d _signals = signals; } - public override ServiceResult Update(Models.EventAction item) + public override ErrorOr Update(Models.EventAction item) { var result = ValidateActions(item); if (result.HasError) return result; @@ -52,7 +52,7 @@ public EventActionService(IApplicationContext applicationContext, CMSDbContext d _signals.Trigger(EventActionChanged); return base.Update(item); } - public override ServiceResult Add(Models.EventAction item) + public override ErrorOr Add(Models.EventAction item) { var result = ValidateActions(item); if (result.HasError) return result; @@ -95,9 +95,9 @@ public Dictionary> GetAllActivedActinosFromCach } - private ServiceResult ValidateActions(Models.EventAction item) + private ErrorOr ValidateActions(Models.EventAction item) { - ServiceResult result = new ServiceResult(); + ErrorOr result = new ErrorOr(); try { var eventAction = YamlConverter.Deserialize(Encode(item.Actions)); diff --git a/src/ZKEACMS.FormGenerator/Service/FormDataService.cs b/src/ZKEACMS.FormGenerator/Service/FormDataService.cs index a83fd9c0..3aed3063 100644 --- a/src/ZKEACMS.FormGenerator/Service/FormDataService.cs +++ b/src/ZKEACMS.FormGenerator/Service/FormDataService.cs @@ -40,7 +40,7 @@ public FormDataService(IApplicationContext applicationContext, _eventManager = eventManager; } - public override ServiceResult Add(FormData item) + public override ErrorOr Add(FormData item) { var result = base.Add(item); if (result.HasError) @@ -101,9 +101,9 @@ private void MergeDataToForm(FormData formData) } } - public ServiceResult SaveForm(IFormCollection formCollection, string formId) + public ErrorOr SaveForm(IFormCollection formCollection, string formId) { - var result = new ServiceResult(); + var result = new ErrorOr(); var form = _formService.Get(formId); if (form == null) { diff --git a/src/ZKEACMS.FormGenerator/Service/FormService.cs b/src/ZKEACMS.FormGenerator/Service/FormService.cs index e55d805d..03ccba40 100644 --- a/src/ZKEACMS.FormGenerator/Service/FormService.cs +++ b/src/ZKEACMS.FormGenerator/Service/FormService.cs @@ -20,13 +20,13 @@ public FormService(IApplicationContext applicationContext, CMSDbContext dbContex { } - public override ServiceResult
Add(Form item) + public override ErrorOr Add(Form item) { item.ID = Guid.NewGuid().ToString("N"); item.FieldsData = JsonConverter.Serialize(item.FormFields); return base.Add(item); } - public override ServiceResult Update(Form item) + public override ErrorOr Update(Form item) { item.FieldsData = JsonConverter.Serialize(item.FormFields); return base.Update(item); diff --git a/src/ZKEACMS.FormGenerator/Service/IFormDataService.cs b/src/ZKEACMS.FormGenerator/Service/IFormDataService.cs index e3cafbd7..3a59f285 100644 --- a/src/ZKEACMS.FormGenerator/Service/IFormDataService.cs +++ b/src/ZKEACMS.FormGenerator/Service/IFormDataService.cs @@ -2,6 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy; using Easy.RepositoryPattern; using Microsoft.AspNetCore.Http; using System; @@ -15,7 +16,7 @@ namespace ZKEACMS.FormGenerator.Service { public interface IFormDataService : IService { - ServiceResult SaveForm(IFormCollection form, string formId); + ErrorOr SaveForm(IFormCollection form, string formId); MemoryStream Export(int id); MemoryStream ExportByForm(string formId); } diff --git a/src/ZKEACMS.Mail/EmailPendingTaskHandler.cs b/src/ZKEACMS.Mail/EmailPendingTaskHandler.cs index de1957bd..dbe5597b 100644 --- a/src/ZKEACMS.Mail/EmailPendingTaskHandler.cs +++ b/src/ZKEACMS.Mail/EmailPendingTaskHandler.cs @@ -1,5 +1,5 @@ -using Easy.Notification; -using Easy.RepositoryPattern; +using Easy; +using Easy.Notification; using System; using System.Collections.Generic; using System.Linq; @@ -19,10 +19,10 @@ public EmailPendingTaskHandler(IEmailNotification emailNotification) _emailNotification = emailNotification; } - public override async Task> ExecuteAsync(object context) + public override async Task> ExecuteAsync(object context) { await _emailNotification.SendEmailAsync(context as EmailContext); - return new ServiceResult(); + return new ErrorOr(); } } } diff --git a/src/ZKEACMS.Message/Service/CommentsService.cs b/src/ZKEACMS.Message/Service/CommentsService.cs index ebcbbce4..a37e4664 100644 --- a/src/ZKEACMS.Message/Service/CommentsService.cs +++ b/src/ZKEACMS.Message/Service/CommentsService.cs @@ -21,9 +21,9 @@ public CommentsService(IApplicationContext applicationContext, CMSDbContext dbCo { _eventManager = eventManager; } - public override ServiceResult Add(Comments item) + public override ErrorOr Add(Comments item) { - ServiceResult result = base.Add(item); + ErrorOr result = base.Add(item); if (!result.HasError) { _eventManager.Trigger(Events.OnCommentsSubmitted, item); diff --git a/src/ZKEACMS.Message/Service/MessageService.cs b/src/ZKEACMS.Message/Service/MessageService.cs index 1adaae00..9403433a 100644 --- a/src/ZKEACMS.Message/Service/MessageService.cs +++ b/src/ZKEACMS.Message/Service/MessageService.cs @@ -22,9 +22,9 @@ public MessageService(IApplicationContext applicationContext, CMSDbContext dbCon { _eventManager = eventManager; } - public override ServiceResult Add(MessageEntity item) + public override ErrorOr Add(MessageEntity item) { - ServiceResult result = base.Add(item); + ErrorOr result = base.Add(item); if (!result.HasError && item.ActionType == ActionType.Continue) { _eventManager.Trigger(Events.OnMessageSubmitted, item); diff --git a/src/ZKEACMS.Product/Service/IProductApiService.cs b/src/ZKEACMS.Product/Service/IProductApiService.cs index 8aa8de81..fcf8cc2c 100644 --- a/src/ZKEACMS.Product/Service/IProductApiService.cs +++ b/src/ZKEACMS.Product/Service/IProductApiService.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using System; using System.Collections.Generic; using System.Linq; @@ -16,8 +16,8 @@ public interface IProductApiService { ProductEntity Get(int id); ProductEntity GetByName(string name); - ServiceResult Create(ProductEntity product); - ServiceResult Update(ProductEntity product); + ErrorOr Create(ProductEntity product); + ErrorOr Update(ProductEntity product); ProductEntity Publish(int id); void Delete(int id); } diff --git a/src/ZKEACMS.Product/Service/IProductCategoryApiService.cs b/src/ZKEACMS.Product/Service/IProductCategoryApiService.cs index 9d8043e0..b4ff703b 100644 --- a/src/ZKEACMS.Product/Service/IProductCategoryApiService.cs +++ b/src/ZKEACMS.Product/Service/IProductCategoryApiService.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using System; using System.Collections.Generic; using System.Linq; @@ -16,8 +16,8 @@ public interface IProductCategoryApiService { ProductCategory Get(int id); ProductCategory GetByName(string name); - ServiceResult Create(ProductCategory productCategory); - ServiceResult Update(ProductCategory productCategory); + ErrorOr Create(ProductCategory productCategory); + ErrorOr Update(ProductCategory productCategory); void Delete(int id); } } diff --git a/src/ZKEACMS.Product/Service/ProductApiService.cs b/src/ZKEACMS.Product/Service/ProductApiService.cs index 84f82949..dca00a4d 100644 --- a/src/ZKEACMS.Product/Service/ProductApiService.cs +++ b/src/ZKEACMS.Product/Service/ProductApiService.cs @@ -2,10 +2,10 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy; using Easy.Constant; using Easy.Extend; using Easy.Mvc.Authorize; -using Easy.RepositoryPattern; using System; using System.Collections.Generic; using System.Linq; @@ -57,7 +57,7 @@ public ProductEntity GetByName(string name) } return product; } - public ServiceResult Create(ProductEntity product) + public ErrorOr Create(ProductEntity product) { var validResult = ValidProductType(product); if (validResult.HasError) return validResult; @@ -73,7 +73,7 @@ public ServiceResult Create(ProductEntity product) return _productService.Add(product); } - public ServiceResult Update(ProductEntity product) + public ErrorOr Update(ProductEntity product) { var validResult = ValidProductType(product); if (validResult.HasError) return validResult; @@ -92,9 +92,9 @@ public ServiceResult Update(ProductEntity product) return _productService.Update(product); } - private ServiceResult ValidProductType(ProductEntity product) + private ErrorOr ValidProductType(ProductEntity product) { - ServiceResult serviceResult = new ServiceResult(); + ErrorOr serviceResult = new ErrorOr(); ProductCategory productType = _productCategoryService.Get(product.ProductCategoryID); if (productType == null) { diff --git a/src/ZKEACMS.Product/Service/ProductCategoryApiService.cs b/src/ZKEACMS.Product/Service/ProductCategoryApiService.cs index 51d20e4c..24a631cf 100644 --- a/src/ZKEACMS.Product/Service/ProductCategoryApiService.cs +++ b/src/ZKEACMS.Product/Service/ProductCategoryApiService.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using System; using System.Collections.Generic; using System.Linq; @@ -21,16 +21,16 @@ public ProductCategoryApiService(IProductCategoryService productCategoryService) _productCategoryService = productCategoryService; } - public ServiceResult Create(ProductCategory productCategory) + public ErrorOr Create(ProductCategory productCategory) { var validResult = ValidParentId(productCategory); if (validResult.HasError) return validResult; return _productCategoryService.Add(productCategory); } - private ServiceResult ValidParentId(ProductCategory productCategory) + private ErrorOr ValidParentId(ProductCategory productCategory) { - ServiceResult result = new ServiceResult(); + ErrorOr result = new ErrorOr(); if (productCategory.ParentID > 0) { var parentProductCategory = _productCategoryService.Get(productCategory.ParentID); @@ -56,7 +56,7 @@ public ProductCategory GetByName(string name) return _productCategoryService.GetByUrl(name); } - public ServiceResult Update(ProductCategory productCategory) + public ErrorOr Update(ProductCategory productCategory) { var validResult = ValidParentId(productCategory); if (validResult.HasError) return validResult; diff --git a/src/ZKEACMS.Product/Service/ProductCategoryService.cs b/src/ZKEACMS.Product/Service/ProductCategoryService.cs index 41ff1319..36cab0ea 100644 --- a/src/ZKEACMS.Product/Service/ProductCategoryService.cs +++ b/src/ZKEACMS.Product/Service/ProductCategoryService.cs @@ -29,7 +29,7 @@ public ProductCategoryService(IProductService productService, _productCategoryTagService = productCategoryTagService; _localize = localize; } - public override ServiceResult Add(ProductCategory item) + public override ErrorOr Add(ProductCategory item) { if (item.Url.IsNotNullAndWhiteSpace() && GetByUrl(item.Url) != null) { @@ -37,7 +37,7 @@ public override ServiceResult Add(ProductCategory item) } return base.Add(item); } - public override ServiceResult Update(ProductCategory item) + public override ErrorOr Update(ProductCategory item) { if (item.Url.IsNotNullAndWhiteSpace() && Count(m => m.Url == item.Url && m.ID != item.ID) > 0) { diff --git a/src/ZKEACMS.Product/Service/ProductListWidgetService.cs b/src/ZKEACMS.Product/Service/ProductListWidgetService.cs index 94159410..44229661 100644 --- a/src/ZKEACMS.Product/Service/ProductListWidgetService.cs +++ b/src/ZKEACMS.Product/Service/ProductListWidgetService.cs @@ -51,7 +51,7 @@ private string GetDetailPageUrl() } return "~/product-detail"; } - public override ServiceResult Add(ProductListWidget item) + public override ErrorOr Add(ProductListWidget item) { if (!item.PageSize.HasValue || item.PageSize.Value == 0) { diff --git a/src/ZKEACMS.Product/Service/ProductService.cs b/src/ZKEACMS.Product/Service/ProductService.cs index 62a18388..7091c644 100644 --- a/src/ZKEACMS.Product/Service/ProductService.cs +++ b/src/ZKEACMS.Product/Service/ProductService.cs @@ -42,9 +42,9 @@ public void Publish(int ID) { Publish(Get(ID)); } - public override ServiceResult Add(ProductEntity item) + public override ErrorOr Add(ProductEntity item) { - ServiceResult result = new ServiceResult(); + ErrorOr result = new ErrorOr(); if (item.Url.IsNotNullAndWhiteSpace() && GetByUrl(item.Url) != null) { return new Error("Url", _localize.Get("URL already exists")); @@ -99,9 +99,9 @@ private void SaveImages(ProductImage item) } } - public override ServiceResult Update(ProductEntity item) + public override ErrorOr Update(ProductEntity item) { - ServiceResult result = new ServiceResult(); + ErrorOr result = new ErrorOr(); if (item.Url.IsNotNullAndWhiteSpace() && Count(m => m.Url == item.Url && m.ID != item.ID) > 0) { return new Error("Url", _localize.Get("URL already exists")); diff --git a/src/ZKEACMS.Redirection/Service/UrlRedirectService.cs b/src/ZKEACMS.Redirection/Service/UrlRedirectService.cs index a0091932..34b8d85d 100644 --- a/src/ZKEACMS.Redirection/Service/UrlRedirectService.cs +++ b/src/ZKEACMS.Redirection/Service/UrlRedirectService.cs @@ -27,9 +27,9 @@ private void RemoveCache() { _cacheManager.Remove(CacheKey); } - private ServiceResult PatternTest(UrlRedirect item) + private ErrorOr PatternTest(UrlRedirect item) { - ServiceResult exceptionResult = new ServiceResult(); + ErrorOr exceptionResult = new ErrorOr(); if (item.IsPattern ?? false) { try @@ -44,9 +44,9 @@ private ServiceResult PatternTest(UrlRedirect item) } return exceptionResult; } - private ServiceResult LoopTest(UrlRedirect item) + private ErrorOr LoopTest(UrlRedirect item) { - ServiceResult result = new ServiceResult(); + ErrorOr result = new ErrorOr(); List direction = new List(); direction.Add(item.DestinationURL.ToLowerInvariant()); UrlRedirect destiantion = item; @@ -76,9 +76,9 @@ private ServiceResult LoopTest(UrlRedirect item) } return result; } - private ServiceResult Valid(UrlRedirect item) + private ErrorOr Valid(UrlRedirect item) { - ServiceResult result = PatternTest(item); + ErrorOr result = PatternTest(item); if (result.HasError) { return result; @@ -89,24 +89,24 @@ public override IQueryable Get() { return CurrentDbSet.AsNoTracking(); } - public override ServiceResult Add(UrlRedirect item) + public override ErrorOr Add(UrlRedirect item) { - ServiceResult validResult = Valid(item); + ErrorOr validResult = Valid(item); if (validResult.HasError) { return validResult; } - ServiceResult result = base.Add(item); + ErrorOr result = base.Add(item); if (!result.HasError) { RemoveCache(); } return result; } - public override ServiceResult AddRange(params UrlRedirect[] items) + public override ErrorOr AddRange(params UrlRedirect[] items) { - ServiceResult result = base.AddRange(items); + ErrorOr result = base.AddRange(items); if (!result.HasError) { RemoveCache(); @@ -114,23 +114,23 @@ public override ServiceResult AddRange(params UrlRedirect[] items) return result; } - public override ServiceResult Update(UrlRedirect item) + public override ErrorOr Update(UrlRedirect item) { - ServiceResult validResult = Valid(item); + ErrorOr validResult = Valid(item); if (validResult.HasError) { return validResult; } - ServiceResult result = base.Update(item); + ErrorOr result = base.Update(item); if (!result.HasError) { RemoveCache(); } return result; } - public override ServiceResult UpdateRange(params UrlRedirect[] items) + public override ErrorOr UpdateRange(params UrlRedirect[] items) { - ServiceResult result = base.UpdateRange(items); + ErrorOr result = base.UpdateRange(items); if (!result.HasError) { RemoveCache(); diff --git a/src/ZKEACMS.SectionWidget/Service/SectionGroupService.cs b/src/ZKEACMS.SectionWidget/Service/SectionGroupService.cs index 954e505b..9fcf685d 100644 --- a/src/ZKEACMS.SectionWidget/Service/SectionGroupService.cs +++ b/src/ZKEACMS.SectionWidget/Service/SectionGroupService.cs @@ -77,7 +77,7 @@ public SectionGroup GenerateContentFromConfig(SectionGroup group) group.SectionContents = contents; return group; } - public override ServiceResult Add(SectionGroup item) + public override ErrorOr Add(SectionGroup item) { item.ID = Guid.NewGuid().ToString("N"); var result = base.Add(item); diff --git a/src/ZKEACMS.SectionWidget/Service/SectionWidgetService.cs b/src/ZKEACMS.SectionWidget/Service/SectionWidgetService.cs index 5c884e80..da6a12b8 100644 --- a/src/ZKEACMS.SectionWidget/Service/SectionWidgetService.cs +++ b/src/ZKEACMS.SectionWidget/Service/SectionWidgetService.cs @@ -16,7 +16,6 @@ using System; using Newtonsoft.Json.Linq; using Easy.Mvc.Plugin; -using Easy.RepositoryPattern; using ZKEACMS.Common.Service; using Microsoft.AspNetCore.Razor.Hosting; using Microsoft.AspNetCore.Mvc.Razor.Compilation; @@ -84,7 +83,7 @@ public override void Remove(Models.SectionWidget item) base.Remove(item); } - public override ServiceResult Add(Models.SectionWidget item) + public override ErrorOr Add(Models.SectionWidget item) { var result = base.Add(item); if (result.HasError) diff --git a/src/ZKEACMS.Shop/Service/AliPaymentService.cs b/src/ZKEACMS.Shop/Service/AliPaymentService.cs index 860b8743..6dbf2ef2 100644 --- a/src/ZKEACMS.Shop/Service/AliPaymentService.cs +++ b/src/ZKEACMS.Shop/Service/AliPaymentService.cs @@ -5,7 +5,7 @@ using Alipay.AopSdk.AspnetCore; using Alipay.AopSdk.Core.Domain; using Alipay.AopSdk.Core.Request; -using Easy.RepositoryPattern; +using Easy; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; @@ -51,7 +51,7 @@ public AliPaymentService(IAlipayService alipayService) } public string Getway => Gateways.AliPay; - public ServiceResult CloseOrder(Order order) + public ErrorOr CloseOrder(Order order) { AlipayTradeCloseModel model = new AlipayTradeCloseModel(); model.OutTradeNo = order.ID; @@ -63,7 +63,7 @@ public ServiceResult CloseOrder(Order order) var response = _alipayService.Execute(request); var responseEntry = JObject.Parse(response.Body).GetValue("alipay_trade_close_response").ToObject(); var status = responseEntry.msg.Equals("Success", StringComparison.OrdinalIgnoreCase); - var result = new ServiceResult + var result = new ErrorOr { Result = status }; @@ -117,7 +117,7 @@ public RefundInfo GetRefund(Order order) }; } - public ServiceResult Refund(Order order) + public ErrorOr Refund(Order order) { AlipayTradeRefundModel model = new AlipayTradeRefundModel(); model.OutTradeNo = order.ID; @@ -132,7 +132,7 @@ public ServiceResult Refund(Order order) var response = _alipayService.Execute(request); var responseEntry = JObject.Parse(response.Body).GetValue("alipay_trade_refund_response").ToObject(); var status = responseEntry.msg.Equals("Success", StringComparison.OrdinalIgnoreCase); - var result = new ServiceResult + var result = new ErrorOr { Result = status }; diff --git a/src/ZKEACMS.Shop/Service/BasketService.cs b/src/ZKEACMS.Shop/Service/BasketService.cs index a6c26fb8..da908f37 100644 --- a/src/ZKEACMS.Shop/Service/BasketService.cs +++ b/src/ZKEACMS.Shop/Service/BasketService.cs @@ -46,7 +46,7 @@ public override Basket Get(params object[] primaryKey) } return null; } - public override ServiceResult Add(Basket item) + public override ErrorOr Add(Basket item) { if (ApplicationContext.CurrentCustomer != null) { @@ -70,15 +70,15 @@ public override ServiceResult Add(Basket item) base.Add(item); } } - return new ServiceResult(); + return new ErrorOr(); } - public override ServiceResult Update(Basket item) + public override ErrorOr Update(Basket item) { if (ApplicationContext.CurrentCustomer != null && ApplicationContext.CurrentCustomer.UserID == item.UserId) { base.Update(item); } - return new ServiceResult(); + return new ErrorOr(); } public override void Remove(Basket item) { diff --git a/src/ZKEACMS.Shop/Service/IOrderService.cs b/src/ZKEACMS.Shop/Service/IOrderService.cs index 79867801..f6752a8f 100644 --- a/src/ZKEACMS.Shop/Service/IOrderService.cs +++ b/src/ZKEACMS.Shop/Service/IOrderService.cs @@ -2,6 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy; using Easy.RepositoryPattern; using System; using System.Collections.Generic; @@ -17,8 +18,8 @@ public interface IOrderService : IService void CompletePay(Order order, string paymentGateway, string paymentID); PaymentInfo GetPaymentInfo(string orderId); - ServiceResult Refund(string orderId, decimal amount, string reason); + ErrorOr Refund(string orderId, decimal amount, string reason); RefundInfo GetRefund(string orderId); - ServiceResult CloseOrder(string orderId); + ErrorOr CloseOrder(string orderId); } } diff --git a/src/ZKEACMS.Shop/Service/IPaymentService.cs b/src/ZKEACMS.Shop/Service/IPaymentService.cs index 469dfe5b..1339a1fa 100644 --- a/src/ZKEACMS.Shop/Service/IPaymentService.cs +++ b/src/ZKEACMS.Shop/Service/IPaymentService.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using System; using System.Collections.Generic; using System.Linq; @@ -15,8 +15,8 @@ public interface IPaymentService { string Getway { get; } PaymentInfo GetPaymentInfo(Order order); - ServiceResult Refund(Order order); + ErrorOr Refund(Order order); RefundInfo GetRefund(Order order); - ServiceResult CloseOrder(Order order); + ErrorOr CloseOrder(Order order); } } diff --git a/src/ZKEACMS.Shop/Service/OrderService.cs b/src/ZKEACMS.Shop/Service/OrderService.cs index a54f01cc..ef843cae 100644 --- a/src/ZKEACMS.Shop/Service/OrderService.cs +++ b/src/ZKEACMS.Shop/Service/OrderService.cs @@ -41,11 +41,11 @@ public override Order Get(params object[] primaryKey) return order; } - public override ServiceResult Add(Order item) + public override ErrorOr Add(Order item) { item.ID = Guid.NewGuid().ToString("N"); item.OrderStatus = (int)OrderStatus.UnPaid; - ServiceResult result = base.Add(item); + ErrorOr result = base.Add(item); if (!result.HasError) { foreach (var orderItem in item.OrderItems) @@ -66,7 +66,7 @@ public void BeginPay(Order order) _eventManager.Trigger(Events.OnPaymentBegin, order); } - public ServiceResult CloseOrder(string orderId) + public ErrorOr CloseOrder(string orderId) { var order = Get(orderId); if (order != null && order.OrderStatus == (int)OrderStatus.UnPaid) @@ -79,7 +79,7 @@ public ServiceResult CloseOrder(string orderId) } return serviceResult; } - ServiceResult result = new ServiceResult + ErrorOr result = new ErrorOr { Result = false }; @@ -117,7 +117,7 @@ public RefundInfo GetRefund(string orderId) return null; } - public ServiceResult Refund(string orderId, decimal amount, string reason) + public ErrorOr Refund(string orderId, decimal amount, string reason) { var order = Get(orderId); if (order != null && order.PaymentID.IsNotNullAndWhiteSpace() && order.RefundID.IsNullOrEmpty() && amount <= order.Total) @@ -133,7 +133,7 @@ public ServiceResult Refund(string orderId, decimal amount, string reason) } return result; } - ServiceResult failed = new ServiceResult + ErrorOr failed = new ErrorOr { Result = false }; diff --git a/src/ZKEACMS/Common/Service/CarouselItemService.cs b/src/ZKEACMS/Common/Service/CarouselItemService.cs index 58dd6c4d..ee47992e 100644 --- a/src/ZKEACMS/Common/Service/CarouselItemService.cs +++ b/src/ZKEACMS/Common/Service/CarouselItemService.cs @@ -19,15 +19,15 @@ public CarouselItemService(IApplicationContext applicationContext, CMSDbContext } public override DbSet CurrentDbSet => DbContext.CarouselItem; - public override ServiceResult Add(CarouselItemEntity item) + public override ErrorOr Add(CarouselItemEntity item) { if (!item.ActionType.HasFlag(ActionType.UnAttach)) { return base.Add(item); } - return new ServiceResult(); + return new ErrorOr(); } - public override ServiceResult Update(CarouselItemEntity item) + public override ErrorOr Update(CarouselItemEntity item) { if (item.ActionType.HasFlag(ActionType.Update)) { @@ -44,13 +44,13 @@ public override ServiceResult Update(CarouselItemEntity item Remove(item); } } - return new ServiceResult(); + return new ErrorOr(); } - public override ServiceResult UpdateRange(params CarouselItemEntity[] items) + public override ErrorOr UpdateRange(params CarouselItemEntity[] items) { items.Each(m => Update(m)); - return new ServiceResult(); + return new ErrorOr(); } } } \ No newline at end of file diff --git a/src/ZKEACMS/Common/Service/CarouselService.cs b/src/ZKEACMS/Common/Service/CarouselService.cs index 0bf5a11d..a689c9c3 100644 --- a/src/ZKEACMS/Common/Service/CarouselService.cs +++ b/src/ZKEACMS/Common/Service/CarouselService.cs @@ -34,7 +34,7 @@ public override CarouselEntity Get(params object[] primaryKey) return carousel; } - public override ServiceResult Add(CarouselEntity item) + public override ErrorOr Add(CarouselEntity item) { var result = base.Add(item); if (result.HasError) @@ -80,7 +80,7 @@ private void SaveCarouselItems(CarouselItemEntity item) } } - public override ServiceResult Update(CarouselEntity item) + public override ErrorOr Update(CarouselEntity item) { var result = base.Update(item); if (result.HasError) @@ -99,7 +99,7 @@ public override ServiceResult Update(CarouselEntity item) } return result; } - public override ServiceResult UpdateRange(params CarouselEntity[] items) + public override ErrorOr UpdateRange(params CarouselEntity[] items) { var result = base.UpdateRange(items); if (result.HasError) diff --git a/src/ZKEACMS/Common/Service/CarouselWidgetService.cs b/src/ZKEACMS/Common/Service/CarouselWidgetService.cs index 34b5641c..1836ed79 100644 --- a/src/ZKEACMS/Common/Service/CarouselWidgetService.cs +++ b/src/ZKEACMS/Common/Service/CarouselWidgetService.cs @@ -5,7 +5,6 @@ using Easy; using Easy.Constant; using Easy.Extend; -using Easy.RepositoryPattern; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; @@ -35,7 +34,7 @@ public override WidgetBase GetWidget(WidgetBase widget) carouselWidget.CarouselItems.Each(m => m.ActionType = ActionType.Update); return carouselWidget; } - public override ServiceResult Add(CarouselWidget item) + public override ErrorOr Add(CarouselWidget item) { return BeginTransaction(() => { diff --git a/src/ZKEACMS/Common/Service/ITemplateService.cs b/src/ZKEACMS/Common/Service/ITemplateService.cs index 5697c96a..fbd447d1 100644 --- a/src/ZKEACMS/Common/Service/ITemplateService.cs +++ b/src/ZKEACMS/Common/Service/ITemplateService.cs @@ -2,6 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy; using Easy.RepositoryPattern; using System; using System.Collections.Generic; @@ -17,7 +18,7 @@ public interface ITemplateService TemplateFile Get(int id); TemplateFile GetDefaultTemplateFile(string temaplateName); List GetTemplateFiles(Pagination p, string theme = "", string fileName = ""); - ServiceResult CreateOrUpdate(TemplateFile model); + ErrorOr CreateOrUpdate(TemplateFile model); void Delete(int id); } } diff --git a/src/ZKEACMS/Common/Service/NavigationService.cs b/src/ZKEACMS/Common/Service/NavigationService.cs index 66ed8921..9d32edd7 100644 --- a/src/ZKEACMS/Common/Service/NavigationService.cs +++ b/src/ZKEACMS/Common/Service/NavigationService.cs @@ -23,7 +23,7 @@ public NavigationService(IApplicationContext applicationContext, CMSDbContext db _htmlSanitizer = htmlSanitizer; } public override DbSet CurrentDbSet => DbContext.Navigation; - public override ServiceResult Add(NavigationEntity item) + public override ErrorOr Add(NavigationEntity item) { if (item.ParentId.IsNullOrEmpty()) { @@ -34,7 +34,7 @@ public override ServiceResult Add(NavigationEntity item) return base.Add(item); } - public override ServiceResult AddRange(params NavigationEntity[] items) + public override ErrorOr AddRange(params NavigationEntity[] items) { foreach (var item in items) { @@ -43,13 +43,13 @@ public override ServiceResult AddRange(params NavigationEntity return base.AddRange(items); } - public override ServiceResult Update(NavigationEntity item) + public override ErrorOr Update(NavigationEntity item) { Santize(item); return base.Update(item); } - public override ServiceResult UpdateRange(params NavigationEntity[] items) + public override ErrorOr UpdateRange(params NavigationEntity[] items) { foreach (var item in items) { diff --git a/src/ZKEACMS/Common/Service/ScriptWidgetService.cs b/src/ZKEACMS/Common/Service/ScriptWidgetService.cs index 05a0b162..f9c5b483 100644 --- a/src/ZKEACMS/Common/Service/ScriptWidgetService.cs +++ b/src/ZKEACMS/Common/Service/ScriptWidgetService.cs @@ -5,7 +5,6 @@ using System; using Easy; using Easy.Extend; -using Easy.RepositoryPattern; using Microsoft.EntityFrameworkCore; using ZKEACMS.Common.Models; using ZKEACMS.Widget; @@ -19,7 +18,7 @@ public ScriptWidgetService(IWidgetBasePartService widgetService, IApplicationCon { } public override DbSet CurrentDbSet => DbContext.ScriptWidget; - public override ServiceResult Add(ScriptWidget item) + public override ErrorOr Add(ScriptWidget item) { if (item.StyleClass.IsNullOrEmpty()) { diff --git a/src/ZKEACMS/Common/Service/StyleSheetWidgetService.cs b/src/ZKEACMS/Common/Service/StyleSheetWidgetService.cs index eb44dfad..015eff44 100644 --- a/src/ZKEACMS/Common/Service/StyleSheetWidgetService.cs +++ b/src/ZKEACMS/Common/Service/StyleSheetWidgetService.cs @@ -4,7 +4,6 @@ using System; using Easy; -using Easy.RepositoryPattern; using Microsoft.EntityFrameworkCore; using ZKEACMS.Common.Models; using ZKEACMS.Widget; @@ -19,7 +18,7 @@ public StyleSheetWidgetService(IWidgetBasePartService widgetService, IApplicatio { } public override DbSet CurrentDbSet => DbContext.StyleSheetWidget; - public override ServiceResult Add(StyleSheetWidget item) + public override ErrorOr Add(StyleSheetWidget item) { if (item.StyleClass.IsNullOrEmpty()) { diff --git a/src/ZKEACMS/Common/Service/TabWidgetService.cs b/src/ZKEACMS/Common/Service/TabWidgetService.cs index dccc0bcf..50a4fe4a 100644 --- a/src/ZKEACMS/Common/Service/TabWidgetService.cs +++ b/src/ZKEACMS/Common/Service/TabWidgetService.cs @@ -11,7 +11,6 @@ using ZKEACMS.Page; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Easy.RepositoryPattern; using ZKEACMS.Extend; namespace ZKEACMS.Common.Service @@ -23,12 +22,12 @@ public TabWidgetService(IWidgetBasePartService widgetBasePartService, IApplicati { } - public override ServiceResult Add(TabWidget item) + public override ErrorOr Add(TabWidget item) { item.TabItems = item.TabItems.RemoveDeletedItems().ToList(); return base.Add(item); } - public override ServiceResult Update(TabWidget item) + public override ErrorOr Update(TabWidget item) { item.TabItems = item.TabItems.RemoveDeletedItems().ToList(); return base.Update(item); diff --git a/src/ZKEACMS/Common/Service/TemplateService.cs b/src/ZKEACMS/Common/Service/TemplateService.cs index 2d9d545e..8d04e0dc 100644 --- a/src/ZKEACMS/Common/Service/TemplateService.cs +++ b/src/ZKEACMS/Common/Service/TemplateService.cs @@ -15,6 +15,7 @@ using Easy.RepositoryPattern; using Easy.Cache; using System.IO.Compression; +using Easy; namespace ZKEACMS.Common.Service { @@ -128,7 +129,7 @@ protected virtual string GetTemplateContent(string templateName) return string.Empty; } - public virtual ServiceResult CreateOrUpdate(TemplateFile model) + public virtual ErrorOr CreateOrUpdate(TemplateFile model) { string name = model.Name; string relativePath = model.RelativePath; @@ -148,7 +149,7 @@ public virtual ServiceResult CreateOrUpdate(TemplateFile model) ExtFile.WriteFile(model.Path, model.Content); EnsureHasViewImports(model.Path); _cacheMgr.Remove(_templateFilesCacheKey); - return new ServiceResult(GetTemplateFiles().First(m => m.RelativePath == model.RelativePath)); + return new ErrorOr(GetTemplateFiles().First(m => m.RelativePath == model.RelativePath)); } else { diff --git a/src/ZKEACMS/DataArchived/DataArchivedService.cs b/src/ZKEACMS/DataArchived/DataArchivedService.cs index 6a8e0398..6f7c7e77 100644 --- a/src/ZKEACMS/DataArchived/DataArchivedService.cs +++ b/src/ZKEACMS/DataArchived/DataArchivedService.cs @@ -36,7 +36,7 @@ public override DataArchived Get(params object[] primaryKey) return Get().FirstOrDefault(m => m.ID == key); } - public override ServiceResult Add(DataArchived item) + public override ErrorOr Add(DataArchived item) { lock (ArchiveLock) { diff --git a/src/ZKEACMS/Extend/ModelStateDictionaryExtend.cs b/src/ZKEACMS/Extend/ModelStateDictionaryExtend.cs index a2c7fd13..e73233d5 100644 --- a/src/ZKEACMS/Extend/ModelStateDictionaryExtend.cs +++ b/src/ZKEACMS/Extend/ModelStateDictionaryExtend.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using Microsoft.AspNetCore.Mvc.ModelBinding; using System; using System.Collections.Generic; @@ -14,7 +14,7 @@ namespace ZKEACMS { public static class ModelStateDictionaryExtend { - public static void Merge(this ModelStateDictionary modelState, ServiceResult serviceResult) + public static void Merge(this ModelStateDictionary modelState, ErrorOr serviceResult) { foreach (var item in serviceResult.Errors) { diff --git a/src/ZKEACMS/Layout/LayoutHtmlService.cs b/src/ZKEACMS/Layout/LayoutHtmlService.cs index 76ffe43c..97c2909b 100644 --- a/src/ZKEACMS/Layout/LayoutHtmlService.cs +++ b/src/ZKEACMS/Layout/LayoutHtmlService.cs @@ -36,7 +36,7 @@ public override IQueryable Get() { return CurrentDbSet.AsNoTracking(); } - public override ServiceResult Add(LayoutHtml item) + public override ErrorOr Add(LayoutHtml item) { item.LayoutHtmlId = 0; return base.Add(item); diff --git a/src/ZKEACMS/Layout/LayoutService.cs b/src/ZKEACMS/Layout/LayoutService.cs index a86ed74f..4dfb9d87 100644 --- a/src/ZKEACMS/Layout/LayoutService.cs +++ b/src/ZKEACMS/Layout/LayoutService.cs @@ -50,7 +50,7 @@ public override IQueryable Get() { return CurrentDbSet.AsNoTracking(); } - public override ServiceResult Add(LayoutEntity item) + public override ErrorOr Add(LayoutEntity item) { item.ID = Guid.NewGuid().ToString("N"); var result = base.Add(item); @@ -153,12 +153,12 @@ public void UpdateDesign(LayoutEntity item) } - public override ServiceResult Update(LayoutEntity item) + public override ErrorOr Update(LayoutEntity item) { MarkChanged(item); return base.Update(item); } - public override ServiceResult UpdateRange(params LayoutEntity[] items) + public override ErrorOr UpdateRange(params LayoutEntity[] items) { items.Each(MarkChanged); return base.UpdateRange(items); diff --git a/src/ZKEACMS/Media/IMediaService.cs b/src/ZKEACMS/Media/IMediaService.cs index 2b48a579..8343603b 100644 --- a/src/ZKEACMS/Media/IMediaService.cs +++ b/src/ZKEACMS/Media/IMediaService.cs @@ -2,6 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy; using Easy.RepositoryPattern; using System.Collections.Generic; using System.IO; @@ -11,13 +12,13 @@ namespace ZKEACMS.Media { public interface IMediaService : IService { - Task> UploadMediaAsync(MediaEntity entity, Stream fileStream); - Task> AppendMediaAsync(string id, Stream fileStream, bool isCompleted); + Task> UploadMediaAsync(MediaEntity entity, Stream fileStream); + Task> AppendMediaAsync(string id, Stream fileStream, bool isCompleted); IList GetPage(string parentId, Pagination pagin); MediaEntity GetImageFolder(); - Task> AddMediaToImageFolderAsync(MediaEntity entity, Stream fileStream); - Task> UploadFromExternalImageAsync(string imageUrl); - Task> UploadFromBlobImageAsync(Stream stream, string fileName); + Task> AddMediaToImageFolderAsync(MediaEntity entity, Stream fileStream); + Task> UploadFromExternalImageAsync(string imageUrl); + Task> UploadFromBlobImageAsync(Stream stream, string fileName); Task GetStreamAsync(string url); } diff --git a/src/ZKEACMS/Media/MediaService.cs b/src/ZKEACMS/Media/MediaService.cs index f3b2aa10..0ef71089 100644 --- a/src/ZKEACMS/Media/MediaService.cs +++ b/src/ZKEACMS/Media/MediaService.cs @@ -47,7 +47,7 @@ public MediaService(IApplicationContext applicationContext, public override DbSet CurrentDbSet => DbContext.Media; - public override ServiceResult Add(MediaEntity item) + public override ErrorOr Add(MediaEntity item) { if (item.ID.IsNullOrEmpty()) { @@ -109,13 +109,13 @@ private static void SetMediaType(MediaEntity item) } } - public async Task> AddMediaToImageFolderAsync(MediaEntity entity, Stream fileStream) + public async Task> AddMediaToImageFolderAsync(MediaEntity entity, Stream fileStream) { entity.ParentID = GetImageFolder().ID; return await UploadMediaAsync(entity, fileStream); } - public async Task> AppendMediaAsync(string id, Stream fileStream, bool isCompleted) + public async Task> AppendMediaAsync(string id, Stream fileStream, bool isCompleted) { var media = Get(id); if (media == null) return null; @@ -137,13 +137,13 @@ public async Task> AppendMediaAsync(string id, Stream } Update(media); } - return new ServiceResult(media); + return new ErrorOr(media); } - public async Task> UploadFromExternalImageAsync(string imageUrl) + public async Task> UploadFromExternalImageAsync(string imageUrl) { string ext = Path.GetExtension(imageUrl); - if (!Easy.Mvc.Common.IsImage(ext)) return new ServiceResult(); + if (!Easy.Mvc.Common.IsImage(ext)) return new ErrorOr(); string id = CreateIdByUrl(imageUrl); var media = Get(id); @@ -157,7 +157,7 @@ public async Task> UploadFromExternalImageAsync(strin Status = (int)RecordStatus.Active }, requestStream))?.Result; } - return new ServiceResult(media); + return new ErrorOr(media); } public MediaEntity GetImageFolder() @@ -177,13 +177,13 @@ public MediaEntity GetImageFolder() return folder; } - public async Task> UploadFromBlobImageAsync(Stream stream, string fileName) + public async Task> UploadFromBlobImageAsync(Stream stream, string fileName) { - if (Easy.Mvc.Common.IsExecuteableFile(Path.GetExtension(fileName))) return new ServiceResult(); + if (Easy.Mvc.Common.IsExecuteableFile(Path.GetExtension(fileName))) return new ErrorOr(); string id = GetIdFromStream(stream); MediaEntity entity = Get(id); - if (entity != null) return new ServiceResult(entity); + if (entity != null) return new ErrorOr(entity); entity = new MediaEntity { @@ -250,10 +250,10 @@ public override void RemoveRange(params MediaEntity[] items) base.RemoveRange(items); } - public async Task> UploadMediaAsync(MediaEntity entity, Stream fileStream) + public async Task> UploadMediaAsync(MediaEntity entity, Stream fileStream) { string extension = Path.GetExtension(entity.Title).ToLower(); - if (Easy.Mvc.Common.IsExecuteableFile(extension)) return new ServiceResult(); + if (Easy.Mvc.Common.IsExecuteableFile(extension)) return new ErrorOr(); string fileId = new IDGenerator().CreateStringId(); Stream stream; diff --git a/src/ZKEACMS/Page/IPageService.cs b/src/ZKEACMS/Page/IPageService.cs index 912f43ec..2282b408 100644 --- a/src/ZKEACMS/Page/IPageService.cs +++ b/src/ZKEACMS/Page/IPageService.cs @@ -2,6 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ +using Easy; using Easy.RepositoryPattern; namespace ZKEACMS.Page @@ -11,7 +12,7 @@ public interface IPageService : IService void Move(string id, int position, int oldPosition); PageEntity GetByPath(string path, bool isPreView); void MarkChanged(string pageId); - ServiceResult Publish(PageEntity item); + ErrorOr Publish(PageEntity item); void Revert(string ID, bool RetainLatest); void DeleteVersion(string ID); bool IsExists(string path); diff --git a/src/ZKEACMS/Page/PageService.cs b/src/ZKEACMS/Page/PageService.cs index 431076c6..9a892523 100644 --- a/src/ZKEACMS/Page/PageService.cs +++ b/src/ZKEACMS/Page/PageService.cs @@ -162,7 +162,7 @@ public override PageEntity Get(params object[] primaryKey) return page; } - public override ServiceResult Add(PageEntity item) + public override ErrorOr Add(PageEntity item) { if (!item.IsPublishedPage && Count(m => m.Url == item.Url && m.IsPublishedPage == false) > 0) { @@ -183,7 +183,7 @@ public override ServiceResult Add(PageEntity item) return result; } - public override ServiceResult Update(PageEntity item) + public override ErrorOr Update(PageEntity item) { if (Count(m => m.ID != item.ID && m.Url == item.Url && m.IsPublishedPage == false) > 0) { @@ -200,9 +200,9 @@ public override ServiceResult Update(PageEntity item) return result; } - public ServiceResult Publish(PageEntity item) + public ErrorOr Publish(PageEntity item) { - var result = new ServiceResult(); + var result = new ErrorOr(); result.Result = item; try { diff --git a/src/ZKEACMS/PendingTask/IPendingTaskHandler.cs b/src/ZKEACMS/PendingTask/IPendingTaskHandler.cs index d72db594..2a5e86d9 100644 --- a/src/ZKEACMS/PendingTask/IPendingTaskHandler.cs +++ b/src/ZKEACMS/PendingTask/IPendingTaskHandler.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using System; using System.Collections.Generic; using System.Linq; @@ -13,7 +13,7 @@ namespace ZKEACMS.PendingTask { public interface IPendingTaskHandler { - Task> ExecuteAsync(object context); + Task> ExecuteAsync(object context); T Deserialize(string rowData); } } diff --git a/src/ZKEACMS/PendingTask/PendingTaskHandler.cs b/src/ZKEACMS/PendingTask/PendingTaskHandler.cs index f3b72f83..eb97d7f6 100644 --- a/src/ZKEACMS/PendingTask/PendingTaskHandler.cs +++ b/src/ZKEACMS/PendingTask/PendingTaskHandler.cs @@ -2,7 +2,7 @@ * Copyright (c) ZKEASOFT. All rights reserved. * http://www.zkea.net/licenses */ -using Easy.RepositoryPattern; +using Easy; using Easy.Serializer; using System; using System.Collections.Generic; @@ -19,6 +19,6 @@ public T Deserialize(string rowData) return JsonConverter.Deserialize(rowData); } - public abstract Task> ExecuteAsync(object context); + public abstract Task> ExecuteAsync(object context); } } diff --git a/src/ZKEACMS/Rule/RuleService.cs b/src/ZKEACMS/Rule/RuleService.cs index 31f31605..c9563c70 100644 --- a/src/ZKEACMS/Rule/RuleService.cs +++ b/src/ZKEACMS/Rule/RuleService.cs @@ -74,7 +74,7 @@ private string FormatValue(string value) } return string.Format("'{0}'", value.Replace("\\", "\\\\").Replace("'", "\\'")); } - public override ServiceResult Add(Rule item) + public override ErrorOr Add(Rule item) { item = Init(item); try @@ -87,7 +87,7 @@ public override ServiceResult Add(Rule item) } return base.Add(item); } - public override ServiceResult Update(Rule item) + public override ErrorOr Update(Rule item) { item = Init(item); try diff --git a/src/ZKEACMS/Setting/ApplicationSettingService.cs b/src/ZKEACMS/Setting/ApplicationSettingService.cs index 5e5ce62d..347e1334 100644 --- a/src/ZKEACMS/Setting/ApplicationSettingService.cs +++ b/src/ZKEACMS/Setting/ApplicationSettingService.cs @@ -36,7 +36,7 @@ public override IQueryable Get() return CurrentDbSet.AsNoTracking(); } - public override ServiceResult Add(ApplicationSetting item) + public override ErrorOr Add(ApplicationSetting item) { lock (ApplicationSetting) { @@ -76,7 +76,7 @@ public string Get(string settingKey, string defaultValue) return setting.Value; } - public override ServiceResult Update(ApplicationSetting item) + public override ErrorOr Update(ApplicationSetting item) { _cacheManager.Remove(item.SettingKey); return base.Update(item); diff --git a/src/ZKEACMS/Theme/ThemeService.cs b/src/ZKEACMS/Theme/ThemeService.cs index 94e11665..6b3826e4 100644 --- a/src/ZKEACMS/Theme/ThemeService.cs +++ b/src/ZKEACMS/Theme/ThemeService.cs @@ -84,12 +84,12 @@ public void CancelPreview() { _cookie.Delete(_preViewCookieName); } - public override ServiceResult Add(ThemeEntity item) + public override ErrorOr Add(ThemeEntity item) { ClearCache(); return base.Add(item); } - public override ServiceResult Update(ThemeEntity item) + public override ErrorOr Update(ThemeEntity item) { ClearCache(); return base.Update(item); diff --git a/src/ZKEACMS/Widget/SimpleWidgetService.cs b/src/ZKEACMS/Widget/SimpleWidgetService.cs index 91728ac4..7b45f0cf 100644 --- a/src/ZKEACMS/Widget/SimpleWidgetService.cs +++ b/src/ZKEACMS/Widget/SimpleWidgetService.cs @@ -27,31 +27,31 @@ public override T Get(params object[] primaryKeys) var item = WidgetBasePartService.Get(primaryKeys); return item.CopyTo(JsonConverter.Deserialize(item.ExtendData ?? "{}")) as T; } - public override ServiceResult Add(T item) + public override ErrorOr Add(T item) { item.ID = Guid.NewGuid().ToString("N"); item.ExtendData = JsonConverter.Serialize(item); WidgetBasePartService.Add(item.ToWidgetBasePart()); - return new ServiceResult(); + return new ErrorOr(); } - public override ServiceResult AddRange(params T[] items) + public override ErrorOr AddRange(params T[] items) { foreach (var item in items) { item.ExtendData = JsonConverter.Serialize(item); } WidgetBasePartService.AddRange(items.Select(m => m.ToWidgetBasePart()).ToArray()); - return new ServiceResult(); + return new ErrorOr(); } - public override ServiceResult Update(T item) + public override ErrorOr Update(T item) { item.ExtendData = JsonConverter.Serialize(item); var basePart = WidgetBasePartService.Get(item.ID); item.CopyTo(basePart); WidgetBasePartService.Update(basePart); - return new ServiceResult(); + return new ErrorOr(); } - public override ServiceResult UpdateRange(params T[] items) + public override ErrorOr UpdateRange(params T[] items) { foreach (var item in items) { @@ -64,7 +64,7 @@ public override ServiceResult UpdateRange(params T[] items) item.CopyTo(baseParts.FirstOrDefault(m => m.ID == item.ID)); } WidgetBasePartService.UpdateRange(baseParts.ToArray()); - return new ServiceResult(); + return new ErrorOr(); } public override IList Get(Expression> filter) { diff --git a/src/ZKEACMS/Widget/WidgetBasePartService.cs b/src/ZKEACMS/Widget/WidgetBasePartService.cs index fdf02d4d..c54f7f16 100644 --- a/src/ZKEACMS/Widget/WidgetBasePartService.cs +++ b/src/ZKEACMS/Widget/WidgetBasePartService.cs @@ -85,7 +85,7 @@ List getWidgets(int[] p) return getWidgets(roleId); } - public override ServiceResult Update(WidgetBasePart item) + public override ErrorOr Update(WidgetBasePart item) { var result = base.Update(item); if (!result.HasError) diff --git a/src/ZKEACMS/Widget/WidgetService.cs b/src/ZKEACMS/Widget/WidgetService.cs index 5550239d..edc5de75 100644 --- a/src/ZKEACMS/Widget/WidgetService.cs +++ b/src/ZKEACMS/Widget/WidgetService.cs @@ -37,7 +37,7 @@ public override IQueryable Get() { return CurrentDbSet.AsNoTracking(); } - public override ServiceResult Add(T item) + public override ErrorOr Add(T item) { return BeginTransaction(() => { @@ -47,7 +47,7 @@ public override ServiceResult Add(T item) var baseResult = WidgetBasePartService.Add(basePart); if (baseResult.HasError) { - var result = new ServiceResult(); + var result = new ErrorOr(); foreach (var item in baseResult.Errors) { result.AddError(item.ParameterName, item.Message); @@ -59,7 +59,7 @@ public override ServiceResult Add(T item) }); } - public override ServiceResult Update(T item) + public override ErrorOr Update(T item) { return BeginTransaction(() => { @@ -68,7 +68,7 @@ public override ServiceResult Update(T item) var baseResult = WidgetBasePartService.Update(basePart); if (baseResult.HasError) { - var result = new ServiceResult(); + var result = new ErrorOr(); foreach (var item in baseResult.Errors) { result.AddError(item.ParameterName, item.Message); @@ -78,7 +78,7 @@ public override ServiceResult Update(T item) return base.Update(item); }); } - public override ServiceResult UpdateRange(params T[] items) + public override ErrorOr UpdateRange(params T[] items) { var ids = items.Select(m => m.ID).ToArray(); var baseParts = WidgetBasePartService.Get(m => ids.Contains(m.ID)); @@ -92,7 +92,7 @@ public override ServiceResult UpdateRange(params T[] items) var baseResult = WidgetBasePartService.UpdateRange(baseParts.ToArray()); if (baseResult.HasError) { - var result = new ServiceResult(); + var result = new ErrorOr(); foreach (var item in baseResult.Errors) { result.AddError(item.ParameterName, item.Message); diff --git a/src/ZKEACMS/Zone/ZoneService.cs b/src/ZKEACMS/Zone/ZoneService.cs index ed16b419..bec6b30e 100644 --- a/src/ZKEACMS/Zone/ZoneService.cs +++ b/src/ZKEACMS/Zone/ZoneService.cs @@ -35,7 +35,7 @@ public override IQueryable Get() return CurrentDbSet.AsNoTracking(); } - public override ServiceResult Add(ZoneEntity item) + public override ErrorOr Add(ZoneEntity item) { item.ID = Guid.NewGuid().ToString("N");