コード例 #1
0
 public ActionResult Post()
 {
     ConnManager conn = new ConnManager();
     List<QuestionType> items = conn.GetQuestionType();
     QuestionType types = new QuestionType();
     types.Types = items;
     return View(types);
 }
コード例 #2
0
        //[Route("")]
        public ActionResult UnAns(string ddType)
        {
            List<QuestionModel> questions = new List<QuestionModel>();
            //if (ModelState.IsValid)
            //{
            string strSQL = string.Empty;
            user = (Users)Session["User"];
            long val = 0;

            if (!string.IsNullOrEmpty(ddType))
            {
                try
                {
                    val = Convert.ToInt64(ddType);
                }
                catch
                {
                    return View("../Que/UnAns");
                }
                if (user != null && user.UserId == 1)
                    strSQL = "Select * from Question Where QuestionId > 37861 and QuestionTypeId = " + ddType + " order by questionid desc";
                else
                    strSQL = "Select top 75  * from Question Where QuestionId > 37861 and QuestionTypeId = " + ddType + " order by questionid desc";
            }
            else
            {
                if (user != null && user.UserId == 1)
                    strSQL = "Select * from Question Where QuestionId > 37861 order by questionid desc";
                else
                    strSQL = "Select top 75 * from Question Where QuestionId > 37861 order by questionid desc";
            }
                ConnManager connManager = new ConnManager();
                questions = connManager.GetQuestions(strSQL);
            //}

            ConnManager conn = new ConnManager();
            List<QuestionType> items = conn.GetQuestionType();
            ViewBag.DDItems = items;
            return View(questions);
        }
コード例 #3
0
        public ActionResult InsertQuestion(string txtTitle, string ddType, string EditorAskQuestion)
        {
            string strTemp = "";
            if (Session["User"] != null)
            {
                txtTitle = txtTitle.Replace("``", "<");
                txtTitle = txtTitle.Replace("~~", "&#");

                user = (Users)Session["User"];
                double dblQuestionID = 0;
                Question question = new Question();
                SqlConnection LclConn = new SqlConnection();
                SqlTransaction SetTransaction = null;
                bool IsinTransaction = false;
                if (LclConn.State != ConnectionState.Open)
                {
                    question.SetConnection = question.OpenConnection(LclConn);
                    SetTransaction = LclConn.BeginTransaction(IsolationLevel.ReadCommitted);
                    IsinTransaction = true;
                }
                else
                {
                    question.SetConnection = LclConn;
                }
                question.QuestionTitle = txtTitle;
                question.QuestionTypeId = int.Parse(ddType);
                question.OptionID = 1;

                //CleanBeforeInsert(ref EditorAskQuestion, ref strTemp);

                question.QuestionDetails = EditorAskQuestion;
                question.AskedDateTime = DateTime.Now;

                if (user.UserId == 1)
                {
                    int[] myy = new int[38] { 16, 17, 18, 19, 23, 24, 25, 26, 32, 34, 35, 37, 39, 40, 41, 42, 44, 45, 46, 47, 48, 51, 52, 54, 55, 56, 57, 58, 59, 63, 69, 70, 71, 72, 73, 82, 104, 106 };
                    Random ran = new Random();
                    int mynum = myy[ran.Next(0, myy.Length)];
                    question.AskedUser = mynum;
                }
                else
                {
                    question.AskedUser = user.UserId;
                }

                bool result = question.CreateQuestion(ref dblQuestionID, SetTransaction);

                if (IsinTransaction && result)
                {
                    SetTransaction.Commit();
                    Mail mail = new Mail();
                    mail.Body = "<a>www.codeanalyze.com/Soln.aspx?QId=" + dblQuestionID.ToString() + "&QT=" + txtTitle + "</a>";
                    mail.FromAdd = "*****@*****.**";
                    mail.Subject = txtTitle;
                    mail.ToAdd = "*****@*****.**";
                    mail.IsBodyHtml = true;

                    if (user.Email != "*****@*****.**")
                    {
                        mail.SendMail();
                    }
                }
                else
                {
                    SetTransaction.Rollback();
                }
                question.CloseConnection(LclConn);

                string title = txtTitle;
                System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9 -]");
                txtTitle = rgx.Replace(txtTitle, "");

                string strAck = "Question posted successfully, we will email you when users post answers.<br /> View your posted question ";
                if (Request.Url.ToString().Contains("localhost"))
                    strAck += "<a style=\"color:blue;text-decoration:underline\" href=\"/CodeAnalyzeMVC2015/Que/Ans/" + dblQuestionID.ToString() + "/" + txtTitle.ToString().Replace(" ", "-") + "\">here</a>";
                else
                    strAck += "<a style=\"color:blue;text-decoration:underline\" href=\"http://codeanalyze.com/Que/Ans/" + dblQuestionID.ToString() + "/" + txtTitle.ToString().Replace(" ", "-") + "\">here</a>";
                strAck += "<br />";

                ViewBag.Ack = strAck;
            }

            ConnManager conn = new ConnManager();
            List<QuestionType> items = conn.GetQuestionType();
            QuestionType types = new QuestionType();
            types.Types = items;
            return View("../Que/Post", types);
        }