private iTask UpdateCache(string id, iTask c)
        {
            iTask old;

            if (iTaskCache.TryGetValue(id, out old))
            {
                if (iTaskCache.TryUpdate(id, c, old))
                {
                    return(c);
                }
            }
            return(null);
        }
 public async Task <iTask> UpdateAsync(string id, iTask c)
 {
     return(await Task.Run(() =>
     {
         db.Tasks.Update(c);
         int affected = db.SaveChanges();
         if (affected == 1)
         {
             return Task.Run(() => UpdateCache(id, c));
         }
         return null;
     }));
 }
        public async Task <iTask> CreateAsync(iTask c)
        {
            EntityEntry <iTask> added = await db.Tasks.AddAsync(c);

            int affected = await db.SaveChangesAsync();

            if (affected == 1)
            {
                return(iTaskCache.AddOrUpdate(c.Id.ToString(), c,
                                              UpdateCache));
            }
            else
            {
                return(null);
            }
        }
        public async Task <bool> DeleteAsync(string id)
        {
            return(await Task.Run(() =>
            {
                id = id.ToUpper();

                iTask c = db.Tasks.Find(id);
                db.Tasks.Remove(c);
                int affected = db.SaveChanges();
                if (affected == 1)
                {
                    return Task.Run(() => iTaskCache.TryRemove(id, out c));
                }
                else
                {
                    return null;
                }
            }));
        }