DM.Service/IShopService.cs

(开头部分) 1KB

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

using AutoMapper;
using DM.Domain;
using DM.Models.Shop;
using DM.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DM.Service
{
    public interface IShopService
    {
        Task<bool> Save(SaveShop model);

        Task<List<T_Shop>> GetAll();

        Task<bool> DeleteById(int id);
    }

    public class ShopService : IShopService
    { 
       private readonly IShopRepository _shopRepository;
        private readonly IMapper _mapper;
        private readonly IOrderRepository _orderRepository;
        public ShopService(IShopRepository shopRepository, IMapper mapper, IOrderRepository orderRepository)
        {
            _shopRepository = shopRepository;
            _mapper = mapper;
            _orderRepository = orderRepository;
        }

        public async Task<List<T_Shop>> GetAll()
        {
            return await _shopRepository.GetAllListAsync();
        }

        public async Task<bool> Save(SaveShop model)
        {
            var shop=_mapper.Map<T_Shop>(model);
            shop.dt_Creat=DateTime.Now;
            if (shop.Ing_ShopID > 0)
            {
                await _shopRepository.UpdateAsync(shop);
            }
            else
            {
                await _shopRepository.InsertAsync(shop);
            }
            
            return true;
        }

        public async Task<bool> DeleteById(int id)
        {
            var exit= _orderRepository.GetAll().Any(o=>o.Ing_ShopID == id);
            if(exit) { throw new Exception("该店铺存在订单,无法删除"); }
            await _shopRepository.DeleteAsync(id);
            return true;
后面还有 3 行代码,购买后查看完整代码

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

AI 解读

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

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