using OASystem.Domain.Entities.Groups;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OASystem.Infrastructure.Repositories.Groups
{
    public class GroupCostRepository:BaseRepository<Grp_GroupCost, GroupCostView>
    {
        public GroupCostRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
        {}

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

        public List<Grp_GroupCost> GetAll()
        {
            return Query(x=> x.IsDel < 1).ToList();
        }

        public async Task<bool> SaveGroupCostList(List<Grp_GroupCost> costList,int diid)
        {
            BeginTran();
            bool isTrue = await DeleteGroupCostList(diid);
            if (costList.Count > 0)
            {
                isTrue = Adds(costList) > 0;
            }
            if (isTrue)
            {
                CommitTran();
            }
            else
            {
                RollbackTran();
            }

            return isTrue; 
        }


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


    }
}
