private void SubTipeEntryView_OnSaveData(object sender, EventArgs e) { using (new WaitCursorHandler()) { try { var listDataGrid = _view.ListDataGrid; var newModel = ((ModelEventArgs <SubTipeModel>)e).Value; var view = ((SubTipeEntryView)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 formattedJsonStr = string.Empty; try { for (int i = 1; i <= 10; i++) { var model = new SubTipeModel() { nama = $"Sub tipe #{i}", keterangan = $"Keterangan Sub tipe #{i}" }; _services.Insert(model); } operationSecceded = true; } catch (DataAccessException ex) { operationSecceded = false; formattedJsonStr = TestsHelper.DataAccessStatusInfoToJson(ex); } try { Assert.True(operationSecceded); _testOutputHelper.WriteLine("Data berhasil ditambahkan."); } finally { _testOutputHelper.WriteLine(formattedJsonStr); } }