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 CostTypeHotelNumberRepository : BaseRepository<Grp_CostTypeHotelNumber, Grp_CostTypeHotelNumberView>
    {
        public CostTypeHotelNumberRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
        { }

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

        public async Task<bool> DeleteCostTypeHotelNumberByDiid(int diid)
        {
            return await SoftDeleteAsync(x => x.Diid == diid);
        }


        public async Task<bool> SaveHotelNumber(List<Grp_CostTypeHotelNumber> List,int Userid,int diid)
        {
            bool isTrue = false;
            try
            {
                BeginTran();
                isTrue = await DeleteCostTypeHotelNumberByDiid(diid);
                if (List.Count > 0)
                {
                    List.ForEach(x => { x.CreateUserId = Userid; x.CreateTime = DateTime.Now; });
                    isTrue = Adds(List) > 0;
                }

                CommitTran();
            }
            catch (Exception)
            {
                RollbackTran();
                isTrue = false;
            }
            return isTrue;
        }
    }
}
