public async Task AddOrUpdateItem (MatrixCacheItem item) { var db = GetAsyncConnection (); var existItem =await db.FindAsync<MatrixCacheItem> (m => item.QueryString== m.QueryString).ConfigureAwait (false); if (existItem == null) { await db.InsertAsync (item).ConfigureAwait (false); } else { existItem.Created = DateTime.UtcNow; existItem.JsonData = item.JsonData; existItem.QueryString = item.QueryString; await db.UpdateAsync (existItem).ConfigureAwait (false); } }
private async Task RefreshMatrix (MatrixParameters parameters) { if (_matrixControl != null) { _matrixControl.SetFilterProperties (parameters.Goal, parameters.RowCount); if (LastSelectedControl != null) { LastSelectedControl.IsSelected = false; LastSelectedControl = null; } UpdateSelectedItem (null); _view.SetAnimation (true); string jsonString = ""; MatrixCacheItem cacheItem = null; ShowAnimation (); if (CrossConnectivity.Current.IsConnected) { var responce = await WebAccessTestDataHelper.GetMatrixData (parameters.QueryString); jsonString = responce.JsonData; if (!string.IsNullOrEmpty (jsonString)) { cacheItem = new MatrixCacheItem () { Created = DateTime.UtcNow, QueryString = parameters.ShortQueryString, JsonData = jsonString }; await _repository.AddOrUpdateItem (cacheItem); } else { if (responce.Status == HttpStatusCode.Unauthorized) { await _notificator.Notify (ToastNotificationType.Error, "Не удалось загрузить данные", "Неверный логин или пароль", TimeSpan.FromSeconds (2)); GoToLoginCommand.Execute (null); } } } else { cacheItem = await _repository.GetMatrixCacheItemByQueryString (parameters.ShortQueryString); if (cacheItem != null) jsonString = cacheItem.JsonData; } TreeMapRootGroup data = null; if (!string.IsNullOrEmpty (jsonString)) data = JsonConvert.DeserializeObject<TreeMapRootGroup> (jsonString); else data = new TreeMapRootGroup (); _matrixControl.DrawMatrix (data); var tableData = GetTableData (data); _tableView.FillTable (tableData); _view.SetAnimation (false); HideAnimation (); } }