src/ZKEACMS.Article/Service/ArticleService.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using Easy.RepositoryPattern;
using System;
using System.Collections.Generic;
using ZKEACMS.Article.Models;
using Easy;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using Easy.Extend;
using ZKEACMS.Event;

namespace ZKEACMS.Article.Service
{
    public class ArticleService : ServiceBase<ArticleEntity, CMSDbContext>, IArticleService
    {
        private readonly ILocalize _localize;
        private readonly IEventManager _eventManager;
        public ArticleService(IApplicationContext applicationContext, 
            ILocalize localize, 
            CMSDbContext dbContext,
            IEventManager eventManager) 
            : base(applicationContext, dbContext)
        {
            _localize = localize;
            _eventManager = eventManager;
        }
        public override ServiceResult<ArticleEntity> Add(ArticleEntity item)
        {
            ServiceResult<ArticleEntity> result;
            if (item.Url.IsNotNullAndWhiteSpace())
            {
                if (GetByUrl(item.Url) != null)
                {
                    result = new ServiceResult<ArticleEntity>();
                    result.RuleViolations.Add(new RuleViolation("Url", _localize.Get("URL already exists")));
                    return result;
                }
            }
            _eventManager.Trigger(Events.OnArticleAdding, item);
            result = base.Add(item);
            if (!result.HasViolation)
            {
                _eventManager.Trigger(Events.OnArticleAdded, item);
            }
            return result;
        }
        public override ServiceResult<ArticleEntity> Update(ArticleEntity item)
        {
            ServiceResult<ArticleEntity> result;
            if (item.Url.IsNotNullAndWhiteSpace())
            {
                if (Count(m => m.Url == item.Url && m.ID != item.ID) > 0)
                {
                    result = new ServiceResult<ArticleEntity>();
                    result.RuleViolations.Add(new RuleViolation("Url", _localize.Get("URL already exists")));
                    return result;
                }
后面还有 62 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。