src/ZKEACMS.Product/Service/ProductCategoryApiService.cs
(开头部分) 2KB这里只显示每个文件的开头 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 System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZKEACMS.Product.Models;
namespace ZKEACMS.Product.Service
{
public class ProductCategoryApiService : IProductCategoryApiService
{
private readonly IProductCategoryService _productCategoryService;
public ProductCategoryApiService(IProductCategoryService productCategoryService)
{
_productCategoryService = productCategoryService;
}
public ServiceResult<ProductCategory> Create(ProductCategory productCategory)
{
var validResult = ValidParentId(productCategory);
if (validResult.HasViolation) return validResult;
return _productCategoryService.Add(productCategory);
}
private ServiceResult<ProductCategory> ValidParentId(ProductCategory productCategory)
{
ServiceResult<ProductCategory> result = new ServiceResult<ProductCategory>();
if (productCategory.ParentID > 0)
{
var parentProductCategory = _productCategoryService.Get(productCategory.ParentID);
if (parentProductCategory == null)
{
result.AddRuleViolation("ParentID", "Parent is not exist");
}
}
return result;
}
public void Delete(int id)
{
_productCategoryService.Remove(id);
}
public ProductCategory Get(int id)
{
return _productCategoryService.Get(id);
}
public ProductCategory GetByName(string name)
{
return _productCategoryService.GetByUrl(name);
}
public ServiceResult<ProductCategory> Update(ProductCategory productCategory)
{
后面还有 7 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。