src/ZKEACMS.Shop/Service/BasketService.cs

(开头部分) 3KB

这里只显示每个文件的开头 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.Threading.Tasks;
using ZKEACMS.Shop.Models;
using Microsoft.EntityFrameworkCore;
using Easy;
using ZKEACMS.Shop.Filter;
using ZKEACMS.Product.Service;

namespace ZKEACMS.Shop.Service
{
    public class BasketService : ServiceBase<Basket, CMSDbContext>, IBasketService
    {
        private readonly IProductService _productService;
        private readonly IOrderService _orderService;
        public BasketService(IApplicationContext applicationContext, IProductService productService, IOrderService orderService, CMSDbContext dbContext) 
            : base(applicationContext, dbContext)
        {
            _productService = productService;
            _orderService = orderService;
        }
        
        public override IQueryable<Basket> Get()
        {
            if (ApplicationContext.CurrentCustomer != null)
            {
                return base.Get().Where(m => m.UserId == ApplicationContext.CurrentCustomer.UserID);
            }
            return null;
        }
        public override Basket Get(params object[] primaryKey)
        {
            if (ApplicationContext.CurrentCustomer != null)
            {
                var basket = base.Get(primaryKey);
                if (ApplicationContext.CurrentCustomer.UserID == basket.UserId)
                {
                    return basket;
                }
            }
            return null;
        }
        public override ServiceResult<Basket> Add(Basket item)
        {
            if (ApplicationContext.CurrentCustomer != null)
            {
                var baskets = Get(m => m.UserId == ApplicationContext.CurrentCustomer.UserID && m.ProductId == item.ProductId);
                var product = _productService.Get(item.ProductId);
                if (baskets.Any(m => m.Description == item.Description) && product != null)
                {
                    foreach (var basket in baskets.Where(m => m.Description == item.Description))
                    {
                        basket.Quantity += item.Quantity;
                        base.Update(basket);
后面还有 49 行代码,解锁后查看完整代码

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

AI 解读 AI

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

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