Exemplo n.º 1
0
 public async Task <int> CountCats()
 {
     using (var db = new CatsContext())
     {
         return(await db.Cats.CountAsync());
     }
 }
Exemplo n.º 2
0
 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));
     }
 }
Exemplo n.º 3
0
 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));
     }
 }