private void TipeEntryView_OnSaveData(object sender, EventArgs e)
        {
            using (new WaitCursorHandler())
            {
                try
                {
                    var listDataGrid = _view.ListDataGrid;
                    var newModel     = ((ModelEventArgs <TipeBarangModel>)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);
                }
            }
        }
Example #2
0
        private void ShouldReturnSuccessForInsert()
        {
            var operationSucceded = false;
            var dataAccessJsonStr = string.Empty;
            var formattedJsonStr  = string.Empty;

            try
            {
                for (int i = 1; i <= 10; i++)
                {
                    var model = new TipeBarangModel()
                    {
                        nama       = $"Tipe #{i}",
                        keterangan = $"Keterangan Tipe #{i}"
                    };

                    _services.Insert(model);
                }

                operationSucceded = true;
            }
            catch (DataAccessException ex)
            {
                operationSucceded = ex.DataAccessStatusInfo.OperationSucceeded;
                dataAccessJsonStr = JsonConvert.SerializeObject(ex.DataAccessStatusInfo);
                formattedJsonStr  = JToken.Parse(dataAccessJsonStr).ToString();
            }

            try
            {
                Assert.True(operationSucceded);
                _testOutputHelper.WriteLine("Data berhasil ditambahkan.");
            }
            finally
            {
                _testOutputHelper.WriteLine(formattedJsonStr);
            }
        }