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 WindreamIndexToWindreamSearchToDepartmentRepository : BaseRepository<WindreamIndexToWindreamSearchToDepartment>
    {
        public WindreamIndexToWindreamSearchToDepartmentRepository(WebApiContext context) : base(context)
        {
        }

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

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

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