async Task <TvControlTask[]> ITasksService.GetTasksAsync()
        {
            TvControlTask[] tasks = await this.tasksServiceImplementation.GetTasksAsync().ConfigureAwait(false);

            using (var context = new TvControlContext()) {
                if (tasks == null || !tasks.Any())
                {
                    List <TvControlTaskDbo> localTasks = await context.Tasks.ToListAsync().ConfigureAwait(false);

                    tasks = Mapper.Map <TvControlTask[]>(localTasks);
                }
                else
                {
                    // override local tasks
                    string tablename = nameof(context.Tasks);
                    await context.Database.ExecuteSqlCommandAsync($"DELETE FROM [{tablename}]");

                    await context.Tasks.AddRangeAsync(Mapper.Map <TvControlTaskDbo[]>(tasks)).ConfigureAwait(false);

                    await context.SaveChangesAsync().ConfigureAwait(false);
                }
            }

            return(tasks);
        }
 public async Task UpdateTaskAsync(TvControlTask task)
 {
     using (var context = new TvControlContext())
     {
         context.Entry(Mapper.Map <TvControlTaskDbo>(task)).State = EntityState.Modified;
         await context.SaveChangesAsync().ConfigureAwait(false);
     }
     await this.tasksServiceImplementation.UpdateTaskAsync(task).ConfigureAwait(false);
 }
 public async Task DeleteTaskAsync(string id)
 {
     using (var context = new TvControlContext())
     {
         context.Tasks.Remove(new TvControlTaskDbo {
             Id = id
         });
         await context.SaveChangesAsync().ConfigureAwait(false);
     }
     await this.tasksServiceImplementation.DeleteTaskAsync(id).ConfigureAwait(false);
 }
 public async Task CreateTaskAsync(TvControlTask task)
 {
     using (var context = new TvControlContext())
     {
         if (string.IsNullOrWhiteSpace(task.Id))
         {
             task.Id = Guid.NewGuid().ToString("N");
         }
         context.Tasks.Add(Mapper.Map <TvControlTaskDbo>(task));
         await context.SaveChangesAsync().ConfigureAwait(false);
     }
     await this.tasksServiceImplementation.CreateTaskAsync(task);
 }