using DataAccessLayer.Entities;
using DataAccessLayer.Filtering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace DataAccessLayer.Units
{
    public class UnitOfWork<T> : UnitOfWorkBase where T : EntityBase
    {

        public UnitOfWork(ISDbContext context) : base(context)
        {
            _repository = new BaseRepository<T>(context);
        }

        public async Task<T> GetByIdAsync(int id)
        {
            return await _repository.GetByIdAsync(id);
        }

        public async Task<IEnumerable<T>> GetAsync(Filter filter = null, string includeProperties = "")
        {
            return await _repository.GetAsync(filter, includeProperties);
        }

        public async Task UpdateAsync(T entity)
        {
            _repository.Update(entity);
            await SaveAsync();
        }

        public async Task CreateAsync(T entity)
        {
            _repository.Create(entity);
            await SaveAsync();
        }

        public async Task DeleteAsync(int id)
        {
            await _repository.DeleteAsync(id);
            await SaveAsync();
        }

        private BaseRepository<T> _repository;

    }
}
