using DAL.Models.Entities;
using DAL.Models.Filters;
using HRD.WebApi.Repositories;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DAL.Repositories
{
    public class WindreamColumnsToDepartmentRepository : BaseRepository<WindreamColumnsToDepartment>
    {
        public WindreamColumnsToDepartmentRepository(WebApiContext context) : base(context)
        {
        }

        public async Task<List<WindreamColumnsToDepartment>> GetListByFilterAsync(DepartmentFilter filter, bool asNoTracking = true)
        {
            var items = this.RepositoryContext.Set<WindreamColumnsToDepartment>().AsQueryable();

            if (filter.DepartmentId != null && filter.DepartmentId != 0)
            {
                items = items.Where(x => x.DepartmentId == filter.DepartmentId);
            }

            if (filter.WindreamSearchId != null && filter.WindreamSearchId != 0)
            {
                items = items.Where(x => x.WindreamSearchId == filter.WindreamSearchId);
            }

            return asNoTracking ? await items.OrderBy(x => x.Seq).AsNoTracking().ToListAsync() : await items.OrderBy(x => x.Seq).ToListAsync();
        }
    }
}