コード例 #1
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);
        }
コード例 #2
0
 public ActionResult Post()
 {
     ConnManager conn = new ConnManager();
     List<QuestionType> items = conn.GetQuestionType();
     QuestionType types = new QuestionType();
     types.Types = items;
     return View(types);
 }
コード例 #3
0
        public List<QuestionType> GetQuestionType()
        {
            OpenConnection();
            DataTable DSQuestions = new DataTable();
            DSQuestions = GetDataTable("Select * from QuestionType");
            DisposeConn();

            List<QuestionType> types = new List<QuestionType>();
            QuestionType type;
            foreach (DataRow row in DSQuestions.Rows)
            {
                type = new QuestionType();
                type.TypeId = row["QuestionTypeId"].ToString();
                type.Type = row["QuestionType"].ToString();
                types.Add(type);
            }
            return types;
        }