コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["enrolledList"] = new List <UserClassViewModel>();
                var user = Page.User as CustomPrincipal;
                if (user != null)
                {
                    UserId = user.Id;
                    //============================ populate data in dropdownlist ===========//


                    var enrollmentDuration = new List <IdAndName>();
                    enrollmentDuration.Add(new IdAndName()
                    {
                        Id = 0, Name = "Unlimited"
                    });
                    enrollmentDuration.Add(new IdAndName()
                    {
                        Id = 1, Name = "1 day"
                    });

                    for (int i = 2; i <= 365; i++)
                    {
                        enrollmentDuration.Add(new IdAndName()
                        {
                            Id = i, Name = i + " days"
                        });
                    }

                    ddlEnrollmentDuration.DataSource = enrollmentDuration;
                    ddlEnrollmentDuration.DataBind();

                    //=================== End of Data population =======================//



                    using (var helper = new DbHelper.Classes())
                    {
                        ddlEnrollmentDuration.Enabled = false;
                        //var subsession = helper.GetSubjectSession()
                        var session = helper.GetSubjectSession(SubjectSessionId);

                        if (session == null)
                        {
                            Response.Redirect("~/Views/Course/");
                            return;
                        }

                        var role = GetRole(session, user);

                        if (role == "")
                        {
                            Response.Redirect("~/Views/Class/CourseClassDetail.aspx?ccId=" + session.Id);
                            return;
                        }


                        DbHelper.ComboLoader.LoadRoleForUserEnroll(ref ddlAssignRole, user.SchoolId, role);

                        hidSessionStartDate.Value = ((session.StartDate == null)
                            ? DateTime.Now.ToShortDateString()
                            : session.StartDate.Value.ToShortDateString());
                        var startingFrom = new List <IdAndName>()
                        {
                            new IdAndName()
                            {
                                Id = 0, Name = "Class Start Day (" + ((session.StartDate == null)?"not set":session.StartDate.Value.ToShortDateString()) + ")"
                            }
                            , new IdAndName()
                            {
                                Id = 1, Name = "Today " + DateTime.Now.ToShortDateString()
                            }
                        };
                        ddlStartingFrom.DataSource = startingFrom;
                        ddlStartingFrom.DataBind();


                        var asglist = helper.ListUsersOfSubjectSession(SubjectSessionId);
                        lstAsg.DataSource = asglist;
                        lstAsg.DataBind();

                        ViewState["enrolledList"] = helper.ListSessionUsers(SubjectSessionId);

                        var notasgList = helper.ListUsersNotInSubjectSession(
                            SubjectSessionId
                            , asglist.Select(x => x.Id).ToList()
                            , user.SchoolId
                            , EnrollType);
                        lstUnAsg.DataSource = notasgList;
                        lstUnAsg.DataSource = notasgList;
                        lstUnAsg.DataBind();

                        //AutoCompleteExtender1.ServiceMethod = "GetUnassignedUsersList";

                        //group populate
                        if (session.HasGrouping)
                        {
                            pnlGroup.Visible    = true;
                            ddlGroup.DataSource = session.SubjectClassGrouping.ToList();
                            ddlGroup.DataBind();
                        }
                        else
                        {
                            pnlGroup.Visible = false;
                        }
                    }
                    //DbHelper.ComboLoader.LoadStudentGroup(ref cmbGroup,
                    //    user.SchoolId, true, GroupId);
                    //SchoolId = user.SchoolId;
                    //lstUnAsg.DataSource =
                }
            }
            else
            {
            }
            //DateChooser1.Validate = false;
        }