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

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

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

            if (filter.DepartmentId != null && filter.DepartmentId != 0)
            {
                items = items.Where(x => x.DepartmentId == filter.DepartmentId);
            }
            return asNoTracking ? await items.OrderBy(x => x.Seq).AsNoTracking().ToListAsync() : await items.OrderBy(x => x.Seq).ToListAsync();
        }
    }
}