Exemplo n.º 1
0
        public void DokterBL_GetById_Test()
        {
            //  arrange
            _dokterDal.Stub(x => x.GetById("A")).Return(new DokterModel());

            //  act
            var dummy = _dokterBL.GetById("A");

            //  assert
            _dokterDal.AssertWasCalled(x => x.GetById("A"));
        }
Exemplo n.º 2
0
        public void Save(JadwalHariModel jadwal)
        {
            //--validasi
            //  dokter
            if (_dokterBL.GetById(jadwal.KodeDokter).Nama.Trim() == "")
            {
                throw new ArgumentException("Invalid DOKTER");
            }

            //  layanan
            if (_layananBL.GetById(jadwal.KodeLayanan).Nama.Trim() == "")
            {
                throw new ArgumentException("Invalid LAYANAN");
            }

            //  hari
            if (jadwal.Hari < 1 || jadwal.Hari > 7)
            {
                throw new ArgumentException("Invalid HARI");
            }

            //  jam mulai
            TimeSpan jamMulai;

            if (!TimeSpan.TryParse(jadwal.JamMulai, out jamMulai))
            {
                throw new ArgumentException("Invalid JAM MULAI");
            }

            //  jam selesai
            TimeSpan jamSelesai;

            if (!TimeSpan.TryParse(jadwal.JamSelesai, out jamSelesai))
            {
                throw new ArgumentException("Invalid JAM SELESAI");
            }

            //  urutan jam mulai-jam selesai
            if (TimeSpan.Compare(jamMulai, jamSelesai) == 1)
            {
                throw new ArgumentException("Invalid JAM MULAI-SELESAI");
            }

            //--validasi detil per jam
            foreach (JadwalHariPerJamModel item in jadwal.JadwalPerJams)
            {
                //  format jam
                TimeSpan jamDetil;
                if (!TimeSpan.TryParse(item.Jam, out jamDetil))
                {
                    throw new ArgumentException("Invalid Format Detil JAM");
                }

                //  jam detil harus berada di range jam di header
                if (TimeSpan.Compare(jamMulai, jamDetil) == 1)
                {
                    throw new ArgumentException("Invalid Range Detil JAM");
                }
                if (TimeSpan.Compare(jamDetil, jamSelesai) == 1)
                {
                    throw new ArgumentException("Invalid Range Detil JAM");
                }

                //  booked tidak boleh melebihi max
                if (item.Booked > item.Max)
                {
                    throw new ArgumentException("Invalid BOOKED QTY");
                }
            }

            //  cek duplikasi dokter-hari-jam (case beda jadwal sama (ini)))
            //      ambil data header
            var result =
                from jadwalJam in jadwal.JadwalPerJams
                group jadwalJam by jadwalJam.Jam into jamGroup
                select new { Jam = jamGroup.Key, Count = jamGroup.Count() };

            if (result.ToList().Exists(x => x.Count > 1))
            {
                throw new ArgumentException("Duplicated JAM PRAKTEK");
            }


            TransactionOptions tranOption = new TransactionOptions
            {
                IsolationLevel = IsolationLevel.ReadCommitted
            };

            using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required, tranOption))
            {
                //  generate kode jadwal jika kosong
                if (jadwal.Kode.Trim() == "")
                {
                    ParamNoModel paramNo = _paramNoBL.GetById("JD");
                    jadwal.Kode = _paramNoBL.FormatKode(paramNo, 5, "");
                    _jadwalHariDal.Insert(jadwal);
                }
                else
                {
                    _jadwalHariDal.Update(jadwal);
                }
                tran.Complete();
            }
        }
        public DokterModel GetById(string id)
        {
            DokterModel retVal = _dokterBL.GetById(id);

            return(retVal);
        }