public void Update_ValidDat_NoEx() { using (var trans = TransHelper.NewScope()) { // arrang var expected = DepositDataFactory(); // act _depositDal.Update(expected); // assert } }
public DepositModel Save(DepositModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } // cek pihak ke dua var pihakKedua = _pihakKeduaBL.GetData(model.PihakKeduaID); if (pihakKedua == null) { var errMsg = string.Format("PihakKeduaID invalid"); throw new ArgumentException(errMsg); } else { model.PihakKeduaName = pihakKedua.PihakKeduaName; } // cek jenis bayar var jenisBayar = _jenisBayarBL.GetData(model.JenisBayarID); if (jenisBayar == null) { throw new ArgumentException("JenisBayarID Invalid "); } else { model.JenisBayarName = jenisBayar.JenisBayarName; model.JenisKasID = jenisBayar.JenisKasID; model.JenisKasName = jenisBayar.JenisKasName; } if (model.ListBrg != null) { foreach (var item in model.ListBrg) { var brg = _brgBL.GetData(item.BrgID); if (brg == null) { throw new ArgumentException("BrgID invalid"); } } } // cek nilai deposit if (model.NilaiDeposit <= 0) { throw new ArgumentException("Nilai Deposit tidak boleh minus"); } // proses simpan using (var trans = TransHelper.NewScope()) { if (model.DepositID.Trim() == "") { model.DepositID = GenNewID(); _depositDal.Insert(model); if (model.ListBrg != null) { foreach (var item in model.ListBrg) { item.DepositID = model.DepositID; _depositDetilDal.Insert(item); } } } else { _depositDetilDal.Delete(model.DepositID); _depositDal.Update(model); if (model.ListBrg != null) { foreach (var item in model.ListBrg) { item.DepositID = model.DepositID; _depositDetilDal.Insert(item); } } } trans.Complete(); } return(model); }