private async Task Import() { ProgressDialogController dialogController = null; try { var uri = $"{FolderName}\\{FileName}"; if (!Directory.Exists(FolderName)) { await _dialogCoordinator.ShowMessageAsync(this, "Error", "Directory does not exists"); return; } if (File.Exists(uri)) { await _dialogCoordinator.ShowMessageAsync(this, "Error", "File already exists"); return; } if (!Scheme.IsSchemeValid()) { await _dialogCoordinator.ShowMessageAsync(this, "Error", "Selected Scheme is not valid\nRows or Columns are empty"); return; } dialogController = await _dialogCoordinator.ShowProgressAsync(this, "Cards Loading", "Loading..."); dialogController.SetIndeterminate(); var filter = Scheme.GetCardFilter(); var cards = await _repository.LoadCards(filter); cards.ForEach(x => x.Color = DefaultColorItems.LemonChiffon.SystemName); // Fill order numbers inside each cell cards .GroupBy(x => new { x.RowId, x.ColumnId }) .ToList() .ForEach(cell => { int i = -10; cell.ToList().ForEach(y => y.Order = i += 10); }); var columns = _scheme.Columns.Where(x => filter.BoardIds.Contains(x.BoardId) && filter.ColumnIds.Contains(x.Id)); if (DontImportUnusedColumns) { columns = columns.Where(x => cards.Exists(y => y.ColumnId == x.Id)); } var rows = _scheme.Rows.Where(x => filter.BoardIds.Contains(x.BoardId) && filter.RowIds.Contains(x.Id)); if (DontImportUnusedRows) { rows = rows.Where(x => cards.Exists(y => y.RowId == x.Id)); } var boxViewModel = await _appModel.Create(uri); boxViewModel.Load(new Box { Boards = _scheme.Boards.Where(x => filter.BoardIds.Contains(x.Id)).ToList(), Columns = columns.ToList(), Rows = rows.ToList(), Cards = cards }); await dialogController.CloseAsync(); _appConfig.UpdateRecent(uri, false); _shell.ShowView <BoardView>( viewRequest: new BoardViewRequest { ViewId = uri, Box = boxViewModel }, options: new UiShowOptions { Title = "*" }); } catch (Exception e) { if (dialogController != null) { await dialogController.CloseAsync(); } await _dialogCoordinator.ShowMessageAsync(this, "Error", e.Message); } }
private async Task Import() { ProgressDialogController dialogController = null; try { var uri = $"{FolderName}\\{FileName}"; if (!Directory.Exists(FolderName)) { await _dialogCoordinator.ShowMessageAsync(this, "Error", "Directory does not exists"); return; } if (File.Exists(uri)) { await _dialogCoordinator.ShowMessageAsync(this, "Error", "File already exists"); return; } if (!Scheme.IsSchemeValid()) { await _dialogCoordinator.ShowMessageAsync(this, "Error", "Selected Scheme is not valid\nRows or Columns are empty"); return; } dialogController = await _dialogCoordinator.ShowProgressAsync(this, "Cards Loading", "Loading..."); dialogController.SetIndeterminate(); var filter = Scheme.GetCardFilter(); var cards = await _repository.LoadCards(filter); var boxViewModel = await _appModel.Create(uri); boxViewModel.Load(new Box { Boards = _scheme.Boards.Where(x => filter.BoardIds.Contains(x.Id)).ToList(), Columns = _scheme.Columns.Where(x => filter.BoardIds.Contains(x.BoardId) && filter.ColumnIds.Contains(x.Id)).ToList(), Rows = _scheme.Rows.Where(x => filter.BoardIds.Contains(x.BoardId) && filter.RowIds.Contains(x.Id)).ToList(), Cards = cards }); await dialogController.CloseAsync(); _appConfig.UpdateRecent(uri, false); _shell.ShowView <BoardView>( viewRequest: new BoardViewRequest { ViewId = uri, Box = boxViewModel }, options: new UiShowOptions { Title = "*" }); } catch (Exception e) { if (dialogController != null) { await dialogController.CloseAsync(); } await _dialogCoordinator.ShowMessageAsync(this, "Error", e.Message); } }