using Aspose.Words.Lists;
using AutoMapper;
using NPOI.SS.Formula.Functions;
using OASystem.Domain.Entities.Customer;
using OASystem.Domain.Entities.Groups;
using OASystem.Domain.ViewModels.CRM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OASystem.Infrastructure.Repositories.Groups
{
    public class CheckBoxsRepository : BaseRepository<Grp_CheckBoxs, Grp_CheckBoxsView>
    {
        private readonly IMapper _mapper;
        public CheckBoxsRepository(SqlSugarClient sqlSugar, IMapper mapper) :
         base(sqlSugar)
        {
            _mapper = mapper;
        }

        public List<Grp_CheckBoxs> GetCheckBoxsByDiid(int diid)
        {
            return  Query(x=>x.Diid == diid).ToList();
        }

        public bool AddCheckBoxs(List<Grp_CheckBoxs> checkboxList)
        {
            return Adds(checkboxList) > 0;
        }

        public Task<bool> DelCheckBoxsByDiid(int diid)
        {
            return DeleteAsync(x => x.Diid == diid);
        }

        public async Task<bool> SaveCheckBoxs(List<Grp_CheckBoxs> checkboxList,int diid)
        {
            BeginTran();
            bool isTrue = await DelCheckBoxsByDiid(diid);
            if (checkboxList.Count > 0)
            {
                isTrue = AddCheckBoxs(checkboxList);
            }

            if (isTrue)
            {
                CommitTran();
            }
            else
            {
                RollbackTran();
            }

            return isTrue;

        }
    }
}
