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

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

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

            return asNoTracking ? await items.AsNoTracking().ToListAsync() : await items.ToListAsync();
        }
    }
}