public async Task <int> CountCats() { using (var db = new CatsContext()) { return(await db.Cats.CountAsync()); } }
public async Task <List <CatContract> > GetCatsByGender(string gender) { using (var db = new CatsContext()) { return(await db.Genders.FirstOrDefaultAsync(g => g.Description.Equals(gender, StringComparison.CurrentCultureIgnoreCase))?.ContinueWith(t => { if (t.IsFaulted) { throw t.Exception; } return t.Result?.Cats?.Select(c => new CatContract(c)).ToList(); }, TaskContinuationOptions.OnlyOnRanToCompletion)); } }
public async Task <CatContract> GetCatByName(string name) { using (var db = new CatsContext()) { return(await db.Cats.FirstOrDefaultAsync(c => c.Name.ToLower().Equals(name.ToLower())).ContinueWith(t => { if (t.IsFaulted) { throw t.Exception; } return new CatContract(t.Result); }, TaskContinuationOptions.OnlyOnRanToCompletion)); } }