Exemple #1
0
        public IEnumerable <IGrouping <string, TutorailChapter> > GetTutorailMenuAndContent(out TutorailChapter chapter)
        {
            TutorailChapter tcChapter = null;

            chapter = tcChapter;
            if (Request.QueryString["item"] == "" ||
                Request.QueryString["chapter"] == "")
            {
                return(null);
            }

            int intItemId;
            int intChapterId;

            if (!int.TryParse(Request.QueryString["item"], out intItemId))
            {
                return(null);
            }

            if (!int.TryParse(Request.QueryString["chapter"], out intChapterId))
            {
                return(null);
            }

            List <TutorailChapter> chapters;
            Stopwatch sw = new Stopwatch();

            using (var db = new TutorailsDBContext())
            {
                sw.Start();
                chapters = (from c in db.Chapters
                            where c.tutorialitem == intItemId
                            select c
                            ).OrderBy(c => c.chapter_seq).ToList <TutorailChapter>();
                sw.Stop();
                long t1 = sw.ElapsedMilliseconds;
                //var sqlParameter = new MySqlParameter("@tutorialitem", Request.QueryString["item"]);
                //sw.Start();
                //chapters = db.Chapters.SqlQuery("select * from dt_tutorial_chapter where tutorialitem = @tutorialitem", sqlParameter).ToList();
                //sw.Stop();
                //long t2 = sw.ElapsedMilliseconds;
                if (chapters == null || chapters.Count == 0)
                {
                    return(null);
                }

                chapter = (from c in db.Chapters
                           where c.id == intChapterId
                           select c).Single();

                var listChapterGroups = chapters.GroupBy(p => p.chapter_group);

                foreach (var group in listChapterGroups)
                {
                    group.OrderBy(c => c.chapter_seq);
                }

                return(listChapterGroups);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.drpCategory.SelectedIndexChanged += drpCategory_SelectedIndexChanged;
            this.drpTutorail.SelectedIndexChanged += drpTutorail_SelectedIndexChanged;
            this.btnGoto.Click += btnGoto_Click;

            if (!IsPostBack)
            {
                using (var tutoraildb = new TutorailsDBContext())
                {
                    List <TutorailCategory> categorys = tutoraildb.Categorys.ToList <TutorailCategory>();
                    this.drpCategory.DataSource     = categorys;
                    this.drpCategory.DataValueField = "id";
                    this.drpCategory.DataTextField  = "module_name";
                    this.drpCategory.DataBind();
                    this.drpCategory.SelectedIndex = 0;
                }
            }
        }
        void drpCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <TutorailItem> tutorails;
            int selectValue = int.Parse(drpCategory.SelectedValue);

            using (var tutoraildb = new TutorailsDBContext())
            {
                tutorails = (from i in tutoraildb.Items
                             where i.category == selectValue
                             select i).ToList <TutorailItem>();

                if (tutorails != null)
                {
                    this.drpTutorail.DataSource     = tutorails;
                    this.drpTutorail.DataTextField  = "item_name";
                    this.drpTutorail.DataValueField = "id";
                    this.drpTutorail.DataBind();
                }
            }
        }
        void drpTutorail_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <TutorailChapter> chapters;
            int selectValue = int.Parse(drpTutorail.SelectedValue);

            using (var tutoraildb = new TutorailsDBContext())
            {
                chapters = (from i in tutoraildb.Chapters
                            where i.tutorialitem == selectValue
                            select i).ToList <TutorailChapter>();

                if (chapters != null)
                {
                    this.drpChapter.DataSource     = chapters;
                    this.drpChapter.DataTextField  = "chapter_name";
                    this.drpChapter.DataValueField = "id";
                    this.drpChapter.DataBind();
                }
            }
        }