using LANCommander.Client.Data.Models; using Microsoft.EntityFrameworkCore; using System.Linq.Expressions; namespace LANCommander.Client.Data { public class Repository : IDisposable where T : BaseModel { private DbContext Context; public Repository(DatabaseContext context) { Context = context; } private DbSet DbSet { get { return Context.Set(); } } public IQueryable Get(Expression> predicate) { return DbSet.AsQueryable().Where(predicate); } public async Task Find(Guid id) { return await DbSet.FindAsync(id); } public T FirstOrDefault(Expression> predicate) { return Get(predicate).FirstOrDefault(); } public async Task Add(T entity) { entity.CreatedOn = DateTime.Now; entity.UpdatedOn = DateTime.Now; await Context.AddAsync(entity); return entity; } public T Update(T entity) { entity.UpdatedOn = DateTime.Now; Context.Update(entity); return entity; } public void Delete(T entity) { Context.Remove(entity); } public async Task SaveChanges() { await Context.SaveChangesAsync(); } public void Dispose() { } } }