private void Btn_Simpan_Click(object sender, RoutedEventArgs e) { try { _itemServices = new ItemServices(); if (JenisBarang.SelectedItem.GetType() != typeof(ItemType)) { MessageBox.Show("Jenis Barang harus dipilih", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (string.IsNullOrEmpty(NamaBarang.Text)) { MessageBox.Show("Nama Barang tidak boleh kosong", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (string.IsNullOrEmpty(HargaBarang.Text)) { MessageBox.Show("Harga Barang tidak boleh kosong", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (string.IsNullOrEmpty(OngkosKontainer.Text)) { MessageBox.Show("Ongkos Kontainer tidak boleh kosong", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } var Dto = new MasterItemDto(); Dto.NAMA_BARANG = NamaBarang.Text; Dto.HARGA = decimal.Parse(HargaBarang.Text); Dto.JENIS_BARANG = (ItemType)JenisBarang.SelectedItem; Dto.ONGKOS_CONTAINER = decimal.Parse(OngkosKontainer.Text); Dto.STATUS = Core.Status.Aktif; Dto.ID = int.Parse(IdBarang.Text); var DataExisting = _itemServices.GetAll().Where(x => !string.IsNullOrEmpty(x.NAMA_BARANG) && x.NAMA_BARANG.ToUpper() == Dto.NAMA_BARANG.ToUpper() && x.JENIS_BARANG == Dto.JENIS_BARANG).FirstOrDefault(); if (DataExisting != null && DataExisting.ID != Dto.ID) { MessageBox.Show("Barang sudah ada di database", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } _itemServices.Save(Dto); MessageBox.Show("Update Data Sukses", "Sukses", MessageBoxButton.OK, MessageBoxImage.Information); CloseWin(); } catch (Exception exp) { MessageBox.Show("Update Data Error", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }