using Hotline.IndustryClassification;
using Hotline.Repository.SqlSugar.DataPermissions;
using SqlSugar;
using XF.Domain.Dependency;

namespace Hotline.Repository.SqlSugar.IndustryClassification
{
    public class IndustryClassificationRepositpry : BaseRepository<IndustrialManagement>, IIndustryClassificationRepositpry, IScopeDependency
    {
        public IndustryClassificationRepositpry(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider) : base(uow, dataPermissionFilterBuilder, serviceProvider)
        {
        }

        public async Task SetIndustrialManagementAsync(IndustrialManagement dto, CancellationToken cancellationToken)
        {
            await Db.UpdateNav(dto)
                .Include(d => d.Orgs)
                .ExecuteCommandAsync();
        }

        public async Task DelIndustrialManagementAsync(string id, CancellationToken cancellationToken)
        {
            var sql = @"delete from  ""industrial_management"" where ""Id""='{0}';
                        delete from ""industry_associations"" where ""IndustrialManagementId""='{0}'";
            sql = string.Format(sql, id);
            await Db.Ado.ExecuteCommandAsync(sql);

        }
    }
}
