Beispiel #1
0
        public HistoriTes GetLastSoal(int sesiId, bool cekJawaban = true, int incrementSoalNumber = 1)
        {
            HistoriTes obj = null;

            using (IDbContext context = new DbContext())
            {
                _repository = new BankSoalRepository(context);
                obj         = _repository.GetLastSoal(sesiId, cekJawaban, incrementSoalNumber);
            }

            return(obj);
        }
Beispiel #2
0
        public int Update(HistoriTes obj)
        {
            var result = 0;

            using (IDbContext context = new DbContext())
            {
                _repository = new HistoriTesRepository(context);
                result      = _repository.Update(obj);
            }

            return(result);
        }
Beispiel #3
0
        public void Soal(string userId, ref string msgToReplay)
        {
            var lastSession = GetLastSession(userId);

            if (lastSession == null)
            {
                msgToReplay = SESSION_TIMEOUT;
            }
            else
            {
                // cek soal terakhir sudah dijawab atau belum
                var lastSoal = GetLastSoal(lastSession.sesi_id);

                if (lastSoal != null && string.IsNullOrEmpty(lastSoal.jawaban))
                {
                    msgToReplay = @"Maaf soal terakhir belum dijawab, ketik *soalterakhir* untuk melihat soal terakhir.";
                }
                else
                {
                    var newSoal = GetNewSoal(lastSession.sesi_id);
                    if (newSoal == null)
                    {
                        msgToReplay = TES_SELESAI;
                    }
                    else
                    {
                        msgToReplay = newSoal.soal + "\r\n\r\n" +
                                      "Ketik: *jawab jawaban* untuk menjawab. Contoh: *jawab a*";

                        msgToReplay = msgToReplay.Replace("[A]", "*[A]*");
                        msgToReplay = msgToReplay.Replace("[B]", "*[B]*");
                        msgToReplay = msgToReplay.Replace("[C]", "*[C]*");
                        msgToReplay = msgToReplay.Replace("[D]", "*[D]*");
                        msgToReplay = msgToReplay.Replace("[E]", "*[E]*");
                        msgToReplay = msgToReplay.Replace("BACAAN", "*BACAAN*");
                        msgToReplay = msgToReplay.Replace("PERTANYAAN", "*PERTANYAAN*");

                        msgToReplay = string.Format("*Soal Nomor {0}*", newSoal.nomor_soal) + ":\r\n\r\n" +
                                      msgToReplay;

                        var histori = new HistoriTes
                        {
                            user_id      = userId,
                            sesi_id      = lastSession.sesi_id,
                            tanggal      = DateTime.Now,
                            bank_soal_id = newSoal.bank_soal_id
                        };

                        SaveHistoriTes(histori);
                    }
                }
            }
        }
        public int Update(HistoriTes obj)
        {
            var result = 0;

            try
            {
                result = _context.Db.Update <HistoriTes>(obj) ? 1 : 0;
            }
            catch (Exception ex)
            {
                //_log.Error("Error:", ex);
            }

            return(result);
        }
        public int Save(HistoriTes obj)
        {
            var result = 0;

            try
            {
                _context.Db.Insert <HistoriTes>(obj);
                result = 1;
            }
            catch (Exception ex)
            {
                //_log.Error("Error:", ex);
            }

            return(result);
        }
Beispiel #6
0
        public HistoriTes GetLastSoal(int sesiId, bool cekJawaban = true, int incrementSoalNumber = 1)
        {
            HistoriTes obj = null;

            try
            {
                var sql = @"select histori_tes.histori_tes_id, histori_tes.user_id, histori_tes.sesi_id, histori_tes.tanggal, histori_tes.jawaban, 
                            histori_tes.hasil_jawaban, histori_tes.batal, 
                            bank_soal.bank_soal_id, bank_soal.soal, bank_soal.jawaban, bank_soal.analisa
                            from histori_tes inner join bank_soal on bank_soal.bank_soal_id = histori_tes.bank_soal_id
                            {WHERE}
                            order by histori_tes.histori_tes_id desc 
                            limit 1";

                if (cekJawaban)
                {
                    sql = sql.Replace("{WHERE}", "where histori_tes.sesi_id = @sesiId and histori_tes.batal = 0 and histori_tes.jawaban is null");
                }
                else
                {
                    sql = sql.Replace("{WHERE}", "where histori_tes.sesi_id = @sesiId and histori_tes.batal = 0");
                }

                obj = _context.Db.Query <HistoriTes, BankSoal, HistoriTes>(sql, (histori, soal) =>
                {
                    histori.bank_soal_id = soal.bank_soal_id;
                    histori.BankSoal     = soal;

                    return(histori);
                }, new { sesiId }, splitOn: "bank_soal_id").SingleOrDefault();

                if (obj != null)
                {
                    IHistoriTesRepository repo = new HistoriTesRepository(_context);
                    obj.BankSoal.nomor_soal = repo.GetSoalNumber(sesiId, incrementSoalNumber);
                }
            }
            catch (Exception ex)
            {
                //_log.Error("Error:", ex);
            }

            return(obj);
        }
 public int Delete(HistoriTes obj)
 {
     throw new NotImplementedException();
 }
Beispiel #8
0
 private void UpdateHistoriTes(HistoriTes obj)
 {
     IHistoriTesController controller = new HistoriTesController();
     var result = controller.Update(obj);
 }