示例#1
0
        public ReturDepositModel Save(ReturDepositModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            //  validate depositID
            var deposit = _depositBL.GetData(model.DepositID);

            if (deposit == null)
            {
                throw new ArgumentException("DepositID invalid");
            }
            else
            {
                model.PihakKeduaName = deposit.PihakKeduaName;
            }

            //  validate jenisKas
            var jenisKas = _jenisKasBL.GetData(model.JenisKasID);

            if (jenisKas == null)
            {
                throw new ArgumentException("JenisKasID invalid");
            }
            else
            {
                model.JenisKasName = jenisKas.JenisKasName;
            }

            //  cek nilai retur harus antara 0 dan sisa deposit
            if (model.NilaiReturDeposit > model.NilaiSisaDeposit)
            {
                throw new ArgumentException("NilaiReturDeposit Invalid");
            }
            if (model.NilaiReturDeposit <= 0)
            {
                throw new ArgumentException("NilaiReturDeposit Invalid minus");
            }

            //  proses simpan
            using (var trans = TransHelper.NewScope())
            {
                if (model.ReturDepositID.Trim() == "")
                {
                    model.ReturDepositID = GenNewID();
                }

                // hapus data lama
                _returDepositDal.Delete(model.ReturDepositID);
                //  simpan data baru
                _returDepositDal.Insert(model);

                trans.Complete();
            }
            return(model);
        }
        public void InsertTest()
        {
            using (var trans = TransHelper.NewScope())
            {
                //  arrange
                var expected = ReturDepositDataFactory();

                //  act
                _returDepositDal.Insert(expected);


                //  assert
            }
        }