private void TipeEntryView_OnSaveData(object sender, EventArgs e) { using (new WaitCursorHandler()) { try { var listDataGrid = _view.ListDataGrid; var newModel = ((ModelEventArgs <TipeModel>)e).Value; var view = ((TipeEntryView)sender); if (newModel.id == default(uint)) { _services.Insert(newModel); view.Controls.ClearControls(); Messages.InfoSave(_typeName); _listObjs.Add(newModel); _bindingView.DataSource = _listObjs; if (listDataGrid.SelectedItem != null) { listDataGrid.SelectedItem = null; } listDataGrid.SelectedItem = newModel; } else { _services.Update(newModel); Messages.InfoUpdate(_typeName); view.Close(); var model = _bindingView.Where(b => b.id == newModel.id).FirstOrDefault(); if (model != null) { model.nama = newModel.nama; model.keterangan = newModel.keterangan; _bindingView.Refresh(); } } } catch (ArgumentException ex) { Messages.Error(ex); } catch (DataAccessException ex) { Messages.Error(ex); } } }
private void ShouldReturnSuccessForInsert() { var operationSecceded = false; var dataAccessJsonStr = string.Empty; var formattedJsonStr = string.Empty; try { for (int i = 1; i <= 10; i++) { var model = new TipeModel() { nama = $"Tipe #{i}", keterangan = $"Keterangan Tipe #{i}" }; _services.Insert(model); } operationSecceded = true; } catch (DataAccessException ex) { operationSecceded = ex.DataAccessStatusInfo.OperationSucceeded; dataAccessJsonStr = JsonConvert.SerializeObject(ex.DataAccessStatusInfo); formattedJsonStr = JToken.Parse(dataAccessJsonStr).ToString(); } try { Assert.True(operationSecceded); _testOutputHelper.WriteLine("Data berhasil ditambahkan."); } finally { _testOutputHelper.WriteLine(formattedJsonStr); } }