public SuratDinasModel Propose(SuratDinasAddDto suratDinas) { // CHECK ARGUMENT suratDinas.Empty().Throw("Data Surat Dinas kosong"); // CONVERT DTO >> MODEL var sd = new SuratDinasModel { TglJamCreate = DateTime.Now, PegID = suratDinas.PegID, NoSurat = suratDinas.NoSurat, NoKontrak = suratDinas.NoKontrak, TglMulai = suratDinas.TglMulai, TglSelesai = suratDinas.TglSelesai, Keperluan = suratDinas.Keperluan, TransportID = suratDinas.TransportID, KMAwal = suratDinas.KMAwal, RSID = suratDinas.RSID, JenisBiayaID = suratDinas.JenisBiayaID, KasBon = suratDinas.KasBon, ListApproval = from c in suratDinas.ListApproval select new SuratDinasApprovalModel { PegID = c.PegID, ApprovalTypeID = c.ApprovalTypeID, } }; // VALIDATE MODEL Validate(sd); // UPDATE REPO using (var trans = TransHelper.NewScope()) { // generate id sd.SuratDinasID = _paramNoBL.GenNewID("LG", ParamNoLengthEnum.Code_13); foreach (var item in sd.ListApproval) { item.SuratDinasID = sd.SuratDinasID; } // insert ke db _suratDinasDal.Insert(sd); _suratDinasApprovalDal.Delete(sd); foreach (var item in sd.ListApproval) { _suratDinasApprovalDal.Insert(item); } // commit changes trans.Complete(); } return(sd); }
public LaporanDinasModel Add(LaporanDinasAddDto laporanDinas) { // validate argument // convert DTO >> Model var ld = new LaporanDinasModel { TglJamCreate = DateTime.Now, PegID = laporanDinas.PegID, SuratDinasID = laporanDinas.SuratDinasID, TglMulai = laporanDinas.TglMulai, TglSelesai = laporanDinas.TglSelesai, HasilKerja = laporanDinas.HasilKerja, KMAkhir = laporanDinas.KMAkhir }; if (ld is null) { throw new ArgumentNullException(nameof(ld)); } ld = R01_PegIDHarusVaid(ld); ld = R02_SuratDinasIDHarusTerdaftar(ld); ld = R03_PegIDRequestAndReportHarusSama(ld); ld = R04_TglSelesaiSetelahTglMulaiDiSuratDinas(ld); ld = R05_HasilKerjaTidakBolehKosong(ld); ld = R06_OpsiKendaraanOperasionalKMAkhirHarusTerisi(ld); ld = R07_OtherTransportKMAkhirSet0(ld); ld = R08_DisetujuiAtasanHarusTerdaftarDiDatabase(ld); ld = R09_IsSignedDiketahuiDisetFalse(ld); //proses simpan using (var trans = TransHelper.NewScope()) { //generate id ld.LaporanDinasID = _paramNoBL.GenNewID("LD", ParamNoLengthEnum.Code_13); //insert ke db _laporanDinasDal.Insert(ld); //commit changes trans.Complete(); } return(ld); }
public PegModel Add(PegAddDto peg) { // INPUT VALIDATION peg.Empty().Throw("DATA PEGAWAI empty"); // CONVERT DTO >> MODEL var pg = new PegModel { PegName = peg.PegName, JabatanID = peg.JabatanID }; pg = Validate(pg); // BUSINESS VALIDATION var listPeg = _pegDal.ListData(); if (listPeg != null) { var exist = listPeg.FirstOrDefault(x => x .PegName.Trim().ToLower() == peg.PegName.Trim().ToLower()); exist.NotEmpty().Throw("Pegawai already exist"); } var jbtn = _jabatanDal.GetData(pg); jbtn.Empty().Throw("JABATAN ID invalid"); pg.JabatanName = jbtn.JabatanName; // REPO-OP using (var trans = TransHelper.NewScope()) { pg.PegID = _paramNoBL.GenNewID("PG", ParamNoLengthEnum.Code_5); _pegDal.Insert(pg); trans.Complete(); } // RETURN return(pg); }