src/ZKEACMS.Product/Service/ProductCategoryService.cs

(开头部分) 2KB

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

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

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

namespace ZKEACMS.Product.Service
{
    public class ProductCategoryService : ServiceBase<ProductCategory, CMSDbContext>, IProductCategoryService
    {
        private readonly IProductService _productService;
        private readonly IProductCategoryTagService _productCategoryTagService;
        private readonly ILocalize _localize;
        public ProductCategoryService(IProductService productService, 
            IApplicationContext applicationContext,
            IProductCategoryTagService productCategoryTagService, 
            ILocalize localize,
            CMSDbContext dbContext)
            : base(applicationContext, dbContext)
        {
            _productService = productService;
            _productCategoryTagService = productCategoryTagService;
            _localize = localize;
        }
        public override ServiceResult<ProductCategory> Add(ProductCategory item)
        {
            if (item.Url.IsNotNullAndWhiteSpace())
            {
                if (GetByUrl(item.Url) != null)
                {
                    var result = new ServiceResult<ProductCategory>();
                    result.RuleViolations.Add(new RuleViolation("Url", _localize.Get("URL already exists")));
                    return result;
                }
            }
            return base.Add(item);
        }
        public override ServiceResult<ProductCategory> Update(ProductCategory item)
        {
            if (item.Url.IsNotNullAndWhiteSpace())
            {
                if (Count(m => m.Url == item.Url && m.ID != item.ID) > 0)
                {
                    var result = new ServiceResult<ProductCategory>();
                    result.RuleViolations.Add(new RuleViolation("Url", _localize.Get("URL already exists")));
                    return result;
                }
            }
            return base.Update(item);
        }
        public ProductCategory GetByUrl(string url)
        {
            return Get(m => m.Url == url).FirstOrDefault();
后面还有 17 行代码,解锁后查看完整代码

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

AI 解读 AI

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

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