private void BarangEntryView_OnSaveData(object sender, EventArgs e) { using (new WaitCursorHandler()) { try { var listDataGrid = _view.ListDataGrid; var newModel = ((ModelEventArgs <BarangModel>)e).Value; var barangEntryView = ((BarangEntryView)sender); if (newModel.id == default(uint)) { _barangServices.Insert(newModel); barangEntryView.Controls.ClearControls(); Messages.InfoSave(_typeName); _listObjs.Add(newModel); _bindingView.DataSource = _listObjs; if (listDataGrid.SelectedItem != null) { listDataGrid.SelectedItem = null; } listDataGrid.SelectedItem = newModel; } else { _barangServices.Update(newModel); Messages.InfoUpdate(_typeName); barangEntryView.Close(); var model = _bindingView.Where(b => b.id == newModel.id).FirstOrDefault(); if (model != null) { model.nama = newModel.nama; model.tipe_id = newModel.tipe_id; model.stok_akhir = newModel.stok_akhir; model.keterangan = newModel.keterangan; _bindingView.Refresh(); } } } catch (ArgumentException ex) { Messages.Error(ex); } catch (DataAccessException ex) { Messages.Error(ex); } } }
private void ShouldReturnSuccessForUpdate() { var operationSecceded = false; var dataAccessJsonStr = string.Empty; var formattedJsonStr = string.Empty; try { var model = new BarangModel { id = 1, tipe_id = 1, sub_tipe_id = 1, supplier_id = 1, kode = "kode_barang_1_Update_", nama = "Nama Barang #1 (Update)" }; _services.Update(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 diubah."); } finally { _testOutputHelper.WriteLine(formattedJsonStr); } }