Skip to content

Instantly share code, notes, and snippets.

@explorer14
Last active December 14, 2018 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save explorer14/bba6f961541346db0e409cc82c2a811d to your computer and use it in GitHub Desktop.
Save explorer14/bba6f961541346db0e409cc82c2a811d to your computer and use it in GitHub Desktop.
public class PeriodRepository : IPeriodRepository
{
// at this point, I have already created my DbContext which I will
// then use to generate the database by running EF Code First commands
private PeriodContext context;
public PeriodRepository(PeriodContext context)
{
this.context = context;
}
public async Task AddAsync(Period domainObject)
{
this.context.Set<Period>().Add(domainObject);
await this.context.SaveChangesAsync();
}
public async Task<IEnumerable<Period>> GetListAsync(
Expression<Func<Period, bool>> predicate)
{
return await this.context.Set<Period>()
.Include("Pots.Expenses").Where(predicate).ToListAsync();
}
public async Task<Period> GetOneAsync(Guid id)
{
return await this.context.Set<Period>()
.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Period updatedEntity)
{
this.context.Update(updatedEntity);
await this.context.SaveChangesAsync();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment