public Task <int> SaveTimerEntryAsync(TimerEntry entry, CancellationToken cancellationToken = default(CancellationToken)) { //If the Id is zero, it's an insert, also set the Id to 1 if (entry.Id == 0) { entry.Id = 1; return(Database.GetConnection(cancellationToken).InsertAsync(entry)); } else { return(Database.GetConnection(cancellationToken).UpdateAsync(entry)); } }
/// <summary> /// Starts timer /// </summary> public Task RecordAsync () { if (activeAssignment == null) return Task.Factory.StartNew (delegate { }); IsBusy = Recording = true; if (timerEntry == null) timerEntry = new TimerEntry (); timerEntry.Date = DateTime.Now; return service .SaveTimerEntryAsync (timerEntry) .ContinueOnCurrentThread (_ => IsBusy = false); }
/// <summary> /// Loads the timer entry /// </summary> public Task LoadTimerEntryAsync () { return service .GetTimerEntryAsync () .ContinueOnCurrentThread (t => { timerEntry = t.Result; if (timerEntry != null) { Recording = true; CurrentHours = Hours = (DateTime.Now - timerEntry.Date); timer.Enabled = true; } return timerEntry; }); }
public Task <int> DeleteTimerEntryAsync(TimerEntry entry, CancellationToken cancellationToken = default(CancellationToken)) { return(Database.GetConnection(cancellationToken).DeleteAsync(entry)); }
public Task<int> DeleteTimerEntryAsync (TimerEntry entry, CancellationToken cancellationToken) { return Task.Factory.StartNew (() => 1); }
public void DeleteTimerEntry () { var entry = new TimerEntry { Date = DateTime.Now.AddHours (-1) }; var task = service.SaveTimerEntryAsync (entry, CancellationToken.None); task.Wait (); var deleteTask = service.DeleteTimerEntryAsync (entry, CancellationToken.None); deleteTask.Wait (); Assert.That (deleteTask.Result, Is.EqualTo (1)); }
public void GetTimerEntry () { var entry = new TimerEntry { Date = DateTime.Now.AddHours (-1) }; var task = service.SaveTimerEntryAsync (entry, CancellationToken.None); task.Wait (); var getTask = service.GetTimerEntryAsync (CancellationToken.None); getTask.Wait (); var result = getTask.Result; Assert.That (entry.Id, Is.EqualTo (result.Id)); Assert.That (entry.Date, Is.EqualTo (result.Date)); }
public void SaveTimerEntry () { TimerEntry entry; var getTask = service.GetTimerEntryAsync(); getTask.Wait(); entry = getTask.Result; if (entry == null) { entry = new TimerEntry { Date = DateTime.Now.AddHours(-1) }; } try { var task = service.SaveTimerEntryAsync (entry, CancellationToken.None); task.Wait (); Assert.That (task.Result, Is.EqualTo (1)); } finally { var deleteTask = service.DeleteTimerEntryAsync (entry, CancellationToken.None); deleteTask.Wait (); } }
public Task<int> DeleteTimerEntryAsync (TimerEntry entry, CancellationToken cancellationToken = default(CancellationToken)) { return Database.GetConnection (cancellationToken).DeleteAsync (entry); }
public Task<int> SaveTimerEntryAsync (TimerEntry entry, CancellationToken cancellationToken = default(CancellationToken)) { //If the Id is zero, it's an insert, also set the Id to 1 if (entry.Id == 0) { entry.Id = 1; return Database.GetConnection (cancellationToken).InsertAsync (entry); } else { return Database.GetConnection (cancellationToken).UpdateAsync (entry); } }