Пример #1
0
        public void InsertTest()
        {
            using (var trans = TransHelper.NewScope())
            {
                //  arrange
                var expected = BPKasDataFactory();

                //  act
                _bpKasDal.Insert(expected);


                //  assert
            }
        }
Пример #2
0
        private BPKasModel Save(BPKasModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            //  validate jenis kas di detil;
            foreach (var item in model.ListDetil)
            {
                var jenisKas = _jenisKasBL.GetData(item.JenisKasID);
                if (jenisKas == null)
                {
                    throw new ArgumentException("Invalid Jenis Kas");
                }
                else
                {
                    item.JenisKasName = jenisKas.JenisKasName;
                }
            }

            //  update nilai total di header
            model.NilaiTotalKas  = model.ListDetil.Sum(x => x.NilaiKasMasuk);
            model.NilaiTotalKas -= model.ListDetil.Sum(x => x.NilaiKasKeluar);

            //  delete data lama
            using (var trans = TransHelper.NewScope())
            {
                _bpKasDetilDal.Delete(model.BPKasID);
                _bpKasDal.Delete(model.BPKasID);

                _bpKasDal.Insert(model);
                foreach (var item in model.ListDetil)
                {
                    _bpKasDetilDal.Insert(item);
                }

                trans.Complete();
            }

            return(model);
        }