public MCQ_QUESTION_DTO InsertUpdateMCQQuestionDetails(string sConnectionString, MCQ_QUESTION_DTO objMCQ_QUESTION_DTO, DataTable dt_MCQQuestionList, string Flag) { #region Paramters MCQ_QUESTION_DTO res = null; string sErrCode = string.Empty; PetaPoco.Database db = null; int out_nReturnValue; int out_nSQLErrCode; string out_sSQLErrMessage; #endregion Paramters try { #region Out Paramter var nReturnValue = new SqlParameter("@out_nReturnValue", System.Data.SqlDbType.Int); nReturnValue.Direction = System.Data.ParameterDirection.Output; nReturnValue.Value = 0; var nSQLErrCode = new SqlParameter("@out_nSQLErrCode", System.Data.SqlDbType.Int); nSQLErrCode.Direction = System.Data.ParameterDirection.Output; nSQLErrCode.Value = 0; var sSQLErrMessage = new SqlParameter("@out_sSQLErrMessage", System.Data.SqlDbType.VarChar); sSQLErrMessage.Direction = System.Data.ParameterDirection.Output; sSQLErrMessage.Value = ""; var inp_tblMCQQuestionList = new SqlParameter(); inp_tblMCQQuestionList.DbType = DbType.Object; inp_tblMCQQuestionList.ParameterName = "@inp_tblMCQQuestionType"; inp_tblMCQQuestionList.TypeName = "dbo.MCQQuestionType"; inp_tblMCQQuestionList.SqlValue = dt_MCQQuestionList; inp_tblMCQQuestionList.SqlDbType = SqlDbType.Structured; #endregion Out Paramter using (db = new PetaPoco.Database(sConnectionString, "System.Data.SqlClient") { EnableAutoSelect = false }) { using (var scope = db.GetTransaction()) { res = db.Fetch <MCQ_QUESTION_DTO>("exec st_MCQ_QuestionDetails @inp_tblMCQQuestionType,@QuestionId,@UserInfoID,@Question,@AnswerType,@OptionNumber,@inp_iOperation,@AttemptNo, @out_nReturnValue OUTPUT, @out_nSQLErrCode OUTPUT, @out_sSQLErrMessage OUTPUT", new { @inp_tblMCQQuestionType = inp_tblMCQQuestionList, @QuestionId = objMCQ_QUESTION_DTO.QuestionID, @UserInfoID = objMCQ_QUESTION_DTO.UserinfoID, @Question = objMCQ_QUESTION_DTO.Question, @AnswerType = objMCQ_QUESTION_DTO.AnswerTypes, @OptionNumber = objMCQ_QUESTION_DTO.OptionNumbers, @inp_iOperation = Flag, @AttemptNo = objMCQ_QUESTION_DTO.AttemptNo, @out_nReturnValue = nReturnValue, @out_nSQLErrCode = nSQLErrCode, @out_sSQLErrMessage = sSQLErrMessage }).SingleOrDefault(); if (Convert.ToInt32(nReturnValue.Value) != 0) { #region Error Code Exception e = new Exception(); out_nReturnValue = Convert.ToInt32(nReturnValue.Value); string sReturnValue = sLookUpPrefix + out_nReturnValue; e.Data[0] = sReturnValue; if (nSQLErrCode.Value != System.DBNull.Value) { out_nSQLErrCode = Convert.ToInt32(nSQLErrCode.Value); e.Data[1] = out_nSQLErrCode; } if (sSQLErrMessage.Value != System.DBNull.Value) { out_sSQLErrMessage = Convert.ToString(sSQLErrMessage.Value); e.Data[2] = out_sSQLErrMessage; } Exception ex = new Exception(db.LastSQL.ToString(), e); throw ex; #endregion Error Code } else { scope.Complete(); return(res); } } } } catch (Exception exp) { throw exp; } //return res; }
public IEnumerable <MCQ_QUESTION_DTO> GetMCQQuestionDetailsList(string i_sConnectionString, MCQ_QUESTION_DTO i_objMCQ_QUESTION_DTO, string Flag) { IEnumerable <MCQ_QUESTION_DTO> res = null; string sErrCode = string.Empty; #region Paramters int out_nReturnValue; int out_nSQLErrCode; string out_sSQLErrMessage; PetaPoco.Database db = null; #endregion Paramters try { var nReturnValue = new SqlParameter("@out_nReturnValue", System.Data.SqlDbType.Int); nReturnValue.Direction = System.Data.ParameterDirection.Output; // nReturnValue.Value = 0; var nSQLErrCode = new SqlParameter("@out_nSQLErrCode", System.Data.SqlDbType.Int); nSQLErrCode.Direction = System.Data.ParameterDirection.Output; nSQLErrCode.Value = 0; var sSQLErrMessage = new SqlParameter("@out_sSQLErrMessage", System.Data.SqlDbType.VarChar); sSQLErrMessage.Direction = System.Data.ParameterDirection.Output; sSQLErrMessage.Value = ""; sSQLErrMessage.Size = 500; var inp_tblMCQQuestionList = new SqlParameter(); inp_tblMCQQuestionList.DbType = DbType.Object; inp_tblMCQQuestionList.ParameterName = "@inp_tblMCQQuestionType"; inp_tblMCQQuestionList.TypeName = "dbo.MCQQuestionType"; inp_tblMCQQuestionList.SqlValue = null; inp_tblMCQQuestionList.SqlDbType = SqlDbType.Structured; // db = new PetaPoco.Database(i_sConnectionString, "System.Data.SqlClient"); using (db = new PetaPoco.Database(i_sConnectionString, "System.Data.SqlClient") { EnableAutoSelect = false }) { using (var scope = db.GetTransaction()) { res = db.Query <MCQ_QUESTION_DTO>("exec st_MCQ_QuestionDetails @inp_tblMCQQuestionType,@QuestionId,@UserInfoID,@Question,@AnswerType,@OptionNumber,@inp_iOperation,@AttemptNo, @out_nReturnValue OUTPUT, @out_nSQLErrCode OUTPUT, @out_sSQLErrMessage OUTPUT", new { @inp_tblMCQQuestionType = inp_tblMCQQuestionList, @QuestionId = 0, @UserInfoID = 0, @Question = "", @AnswerType = "", @OptionNumber = 1, @inp_iOperation = Flag, @AttemptNo = 0, @out_nReturnValue = nReturnValue, @out_nSQLErrCode = nSQLErrCode, @out_sSQLErrMessage = sSQLErrMessage }).ToList(); if (Convert.ToInt32(nReturnValue.Value) != 0) { Exception e = new Exception(); out_nReturnValue = Convert.ToInt32(nReturnValue.Value); string sReturnValue = sLookUpPrefix + out_nReturnValue; e.Data[0] = sReturnValue; if (nSQLErrCode.Value != System.DBNull.Value) { out_nSQLErrCode = Convert.ToInt32(nSQLErrCode.Value); e.Data[1] = out_nSQLErrCode; } if (sSQLErrMessage.Value != System.DBNull.Value) { out_sSQLErrMessage = Convert.ToString(sSQLErrMessage.Value); e.Data[2] = out_sSQLErrMessage; } Exception ex = new Exception(db.LastSQL.ToString(), e); throw ex; } else { scope.Complete(); } } } } catch (Exception exp) { throw exp; } return(res); }