public async Task RemoveTimeSpanItemAsync(int id) { _manualResetEvent.WaitOne(); try { TimeSpanItemContext timespanItemContext = new TimeSpanItemContext(); var timespanItem = await timespanItemContext.TimeSpanItems.Where(x => x.Id == id).Select(x => x).FirstOrDefaultAsync(); if (timespanItem != null) { timespanItemContext.Remove(timespanItem); await timespanItemContext.SaveChangesAsync(); } } catch (Exception e) { if (_exceptionLogItemContext != null) { await AddExceptionLogItem(new ExceptionLogItem() { TimeStamp = DateTime.Now, Message = e.Message, Source = e.Source, StackTrace = e.StackTrace }); } } _manualResetEvent.Set(); }
public async Task <int> AddTimeSpanItemAsync(TimeSpanItem timeSpanItem) { _manualResetEvent.WaitOne(); try { TimeSpanItemContext timeSpanItemContext = new TimeSpanItemContext(); timeSpanItem = (await timeSpanItemContext.AddAsync(timeSpanItem)).Entity; await timeSpanItemContext.SaveChangesAsync(); _manualResetEvent.Set(); return(timeSpanItem.Id); } catch (Exception e) { if (_exceptionLogItemContext != null) { await AddExceptionLogItem(new ExceptionLogItem() { TimeStamp = DateTime.Now, Message = e.Message, Source = e.Source, StackTrace = e.StackTrace }); } _manualResetEvent.Set(); return(int.MinValue); } }
public async Task UpdateTimeSpanItemAsync(TimeSpanItem timeSpanItem, bool remote = false) { _manualResetEvent.WaitOne(); if (timeSpanItem == null) { return; } try { TimeSpanItemContext timeSpanItemContext = new TimeSpanItemContext(); timeSpanItemContext.Entry(timeSpanItem).State = EntityState.Modified; if (remote) { var queriedTimespanItem = await timeSpanItemContext.TimeSpanItems.Where(x => x.Id == timeSpanItem.Id).Select(x => x).FirstOrDefaultAsync(); if (queriedTimespanItem != null) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { queriedTimespanItem.End = timeSpanItem.End; queriedTimespanItem.Occupancy = timeSpanItem.Occupancy; queriedTimespanItem.Start = timeSpanItem.Start; queriedTimespanItem.TimeStamp = timeSpanItem.TimeStamp; }); timeSpanItemContext.Update(queriedTimespanItem); } } else { timeSpanItemContext.Update(timeSpanItem); } await timeSpanItemContext.SaveChangesAsync(); } catch (Exception e) { if (_exceptionLogItemContext != null) { await AddExceptionLogItem(new ExceptionLogItem() { TimeStamp = DateTime.Now, Message = e.Message, Source = e.Source, StackTrace = e.StackTrace }); } } _manualResetEvent.Set(); }
public async Task RemoveTimeSpanItemAsync(TimeSpanItem timeSpanItem) { _manualResetEvent.WaitOne(); try { TimeSpanItemContext timeSpanItemContext = new TimeSpanItemContext(); timeSpanItemContext.Remove(timeSpanItem); await timeSpanItemContext.SaveChangesAsync(); } catch (Exception e) { if (_exceptionLogItemContext != null) { await AddExceptionLogItem(new ExceptionLogItem() { TimeStamp = DateTime.Now, Message = e.Message, Source = e.Source, StackTrace = e.StackTrace }); } } _manualResetEvent.Set(); }