Esempio n. 1
0
        protected void btn_dn_Click(object sender, EventArgs e)
        {
            DBCramming _db = new DBCramming();
            User       a   = new User();
            _Profile   b   = new _Profile();

            b.addProfile();
            a.UserID    = tk_btn.Text;
            a.pass      = mk_btn.Text;
            a.ProfileID = b._Profile1.ProfileID;
            if (a.pass.ToString() == remk_btn.Text.ToString())
            {
                _db.Users.Add(a);
                int res = _db.SaveChanges();
                if (res > 0)
                {
                    Response.Redirect("Dangnhap.aspx");
                }
                else
                {
                    Response.Write("Try Again!!!");
                }
            }
            else
            {
                Response.Write("Mật Khẩu Không Khớp. Vui Lòng Thử Lại");
            }
        }
Esempio n. 2
0
        public void addProfile()
        {
            DBCramming _db = new DBCramming();
            int        a   = _db.Database.SqlQuery <int>("Select TOP 1 ProfileID FROM Profiles order by ProfileID DESC").FirstOrDefault();

            _Profile1.ProfileID = ++a;
            _db.Profiles.Add(_Profile1);
            int c = _db.SaveChanges();
        }
Esempio n. 3
0
        public void addProfile(string _Hoten, DateTime _Ngaysinh, string _Diachi, string _Email, int _Reputation)
        {
            DBCramming _db = new DBCramming();
            int        a   = _db.Database.SqlQuery <int>("Select TOP 1 ProfileID FROM Profiles order by ProfileID DESC").FirstOrDefault();

            _Profile1.ProfileID  = ++a;
            _Profile1.Hoten      = _Hoten;
            _Profile1.NgaySinh   = _Ngaysinh;
            _Profile1.DiaChi     = _Diachi;
            _Profile1.Email      = _Email;
            _Profile1.Reputation = _Reputation;
            _db.Profiles.Add(_Profile1);
            int c = _db.SaveChanges();
        }
Esempio n. 4
0
        protected void btn_del_Click(object sender, EventArgs e)
        {
            DBCramming db    = new DBCramming();
            int        ansid = Int32.Parse(Request.QueryString["ans"]);

            var answer = new Answer {
                AnswerID = ansid
            };

            db.Answers.Attach(answer);
            db.Answers.Remove(answer);
            db.SaveChanges();

            Response.Redirect("Question.aspx");
        }
Esempio n. 5
0
        protected void Post_Answer(object sender, EventArgs e)
        {
            if (Session["id"] == null)
            {
                Response.Redirect("Dangnhap.aspx");
            }
            else
            {
                int        qid     = Int32.Parse(Request.QueryString["qid"]);
                DBCramming db      = new DBCramming();
                Answer     new_ans = new Answer();
                var        new_id  = from a in db.Answers
                                     select a.AnswerID;

                if (ansbody.Text == "")
                {
                    valid_lb.Text = "Nội dung không được để trống";
                }
                else
                {
                    new_ans.AnswerID   = new_id.Max() + 1;
                    new_ans.Body       = ansbody.Text;
                    new_ans.Likes      = 0;
                    new_ans.Posttime   = DateTime.Now;
                    new_ans.QuestionID = qid;
                    new_ans.UserID     = Session["id"].ToString();



                    db.Answers.Add(new_ans);
                    int res = db.SaveChanges();
                    if (res == 0)
                    {
                        valid_lb.Text = "Đã có lỗi vui long thử lại";
                    }
                    else
                    {
                        ansbody.Text = string.Empty;
                        loadData();
                    }
                }
            }
        }
Esempio n. 6
0
        protected void post_Btn_Click(object sender, EventArgs e)
        {
            DBCramming db = new DBCramming();

            Model.Question _q = new Model.Question();

            var id = from q in db.Questions
                     select q.QuestionID;

            string[] tags = tag.Text.Split(' ');
            if (tags.Length <= 3)
            {
                if (tag.Text == "")
                {
                    valid.Text = "Vui lòng nhập tối thiểu 1 tag";
                }
                else
                {
                    foreach (string t in tags)
                    {
                        var check = from tg in db.Tags
                                    where tg.TagName == t
                                    select tg.TagID;
                        if (check.Count() < 1)
                        {
                            var new_id = from tg in db.Tags

                                         select tg.TagID;
                            Tag new_tag = new Tag();
                            new_tag.TagID   = new_id.Max() + 1;
                            new_tag.TagName = t;
                            db.Tags.Add(new_tag);
                            db.SaveChanges();
                        }
                    }
                    if (title.Text == "")
                    {
                        valid.Text = "Tiêu đề không được rỗng";
                    }
                    else
                    {
                        if (body.Text == "")
                        {
                            valid.Text = "Nội dung không được rỗng";
                        }
                        else
                        {
                            _q.UserID     = Session["id"].ToString();
                            _q.QuestionID = id.Max() + 1;
                            _q.Title      = title.Text;
                            _q.Body       = body.Text;
                            _q.viewcount  = 0;
                            _q.Likes      = 0;
                            _q.Posttime   = DateTime.Now;

                            db.Questions.Add(_q);
                            int res = db.SaveChanges();

                            foreach (string t in tags)
                            {
                                QuestionTag new_qt = new QuestionTag();
                                var         new_id = from qt in db.QuestionTags
                                                     select qt.QTID;
                                var tag_id = from b in db.Tags
                                             where b.TagName == t
                                             select b.TagID;
                                new_qt.QTID       = new_id.Max() + 1;
                                new_qt.TagID      = tag_id.FirstOrDefault();
                                new_qt.QuestionID = _q.QuestionID;

                                db.QuestionTags.Add(new_qt);
                                db.SaveChanges();
                            }
                            if (res > 0)
                            {
                                Response.Redirect("Question.aspx");
                            }
                            else
                            {
                                valid.Text = "Đã có lỗi xảy ra vui lòng thử lại";
                            }
                        }
                    }
                }
            }
            else
            {
                valid.Text = "Vui lòng nhập ít hơn 3 tag";
            }
        }