public async Task <Tasks> GetTaskById(int taskId) { using (var context = new TrackrContext()) { try { return(await(from x in this.Tasks where x.TaskId == taskId select x).SingleOrDefaultAsync <Tasks>()); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } } }
public async Task <IEnumerable <Tasks> > GetAllTasks() { using (var context = new TrackrContext()) { try { return(await(from x in this.Tasks select x).ToListAsync <Tasks>()); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } } }
public async Task <Tasks> DeleteTask(int taskId) { using (var context = new TrackrContext()) { try { var result = await context.Tasks.SingleOrDefaultAsync <Tasks>(x => x.TaskId == taskId); if (result != null) { context.Tasks.Remove(result); await context.SaveChangesAsync(); } return(result); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } } }
public async Task <Tasks> UpdateTask(Tasks task) { using (var context = new TrackrContext()) { try { var result = await context.Tasks.SingleOrDefaultAsync <Tasks>(x => x.TaskId == task.TaskId); if (result != null) { context.Entry(result).CurrentValues.SetValues(task); await context.SaveChangesAsync(); } return(result); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } } }
public async Task <Tasks> CreateTask(Tasks task) { using (var context = new TrackrContext()) { try { var result = await(from x in this.Tasks where x.TaskId == task.TaskId select x).SingleOrDefaultAsync <Tasks>(); if (result != null) { return(null); } await context.Tasks.AddAsync(task); await context.SaveChangesAsync(); return(task); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } } }
public async Task <IEnumerable <Tasks> > DeleteMatchingTasks(List <Tasks> tasksToDelete) { using (var context = new TrackrContext()) { try { var result = (from a in this.Tasks join b in tasksToDelete on a.TaskId equals b.TaskId select a); var resultList = await result.ToListAsync <Tasks>(); if (result != null) { context.Tasks.RemoveRange(result); await context.SaveChangesAsync(); } return(resultList); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } } }