コード例 #1
0
ファイル: SelfEnrolment.aspx.cs プロジェクト: skrishnau/LMS
        protected void Page_Load(object sender, EventArgs e)
        {
            CustomDialog.OkClick     += CustomDialog_OkClick;
            CustomDialog.CancelClick += CustomDialog_CancelClick;
            var user = Page.User as CustomPrincipal;

            if (user != null)
            {
                if (!IsPostBack)
                {
                    var classId = Request.QueryString["ccId"];
                    if (classId != null)
                    {
                        var clsId = Convert.ToInt32(classId);
                        SubjectClassId = clsId;

                        using (var helper = new DbHelper.Classes())
                            using (var usrHelper = new DbHelper.User())
                            {
                                var cls = helper.GetSubjectSession(clsId);
                                if (cls != null)
                                {
                                    var subject = cls.IsRegular ? cls.SubjectStructure.Subject : cls.Subject;
                                    ListOfSectionsInCourseUC.UserId   = user.Id;
                                    ListOfSectionsInCourseUC.CourseId = subject.Id;

                                    var teacherRoleId = usrHelper.GetRole(Academic.DbHelper.DbHelper.StaticValues.Roles.Teacher)
                                                        .Id;
                                    lbldNotice.Visible = !cls.ClassUsers.Any(x => x.RoleId == teacherRoleId &&
                                                                             !(x.Void ?? false));
                                    var clsname = cls.GetName;
                                    lblTitle.Text      = clsname;
                                    lblClassName.Text  = clsname;          //cls.IsRegular ? cls.GetName : cls.Name;
                                    lblCourseName.Text = subject.FullName; //cls.IsRegular

                                    lblEndDate.Text   = cls.EndDate == null ? " - " : cls.EndDate.Value.ToString("D");
                                    lblStartDate.Text = cls.StartDate == null ? " - " : cls.StartDate.Value.ToString("D");


                                    if (!(user.IsInRole("manager") || user.IsInRole("teacher")))
                                    {
                                        var joinedClass = helper.HasTheUserAlreadyJoinedThisClass(user.Id, cls.Id);
                                        if (!(cls.SessionComplete ?? false) &&
                                            cls.EnrollmentMethod == 2)
                                        {
                                            if (joinedClass != null)
                                            {
                                                lblJoinLastDate.Text = joinedClass.StartDate.HasValue
                                                ? joinedClass.StartDate.Value.ToString("D")
                                                : "-";
                                                lblJoinLstDateTitle.Text = "Joined on";

                                                SetEnrollDialog(false);
                                                btnEnroll.Text    = "Remove enrolment";
                                                btnEnroll.Visible = true;
                                            }
                                            else if ((cls.JoinLastDate ?? DateTime.MaxValue.Date) >= DateTime.Now.Date)
                                            {
                                                lblJoinLastDate.Text = cls.JoinLastDate.HasValue
                                                ? cls.JoinLastDate.Value.ToString("D")
                                                : "-";

                                                SetEnrollDialog(true);
                                                btnEnroll.Visible = true;
                                            }
                                            //lnkEnrollNow.NavigateUrl = "";
                                        }
                                        //else if (joinedClass!=null && !(cls.SessionComplete ?? false))
                                        //{

                                        //}
                                    }
                                    else
                                    {
                                        lblJoinLastDate.Text = cls.JoinLastDate == null ? " - " : cls.JoinLastDate.Value.ToString("D");
                                    }

                                    lnkViewCourse.Visible     = true;
                                    lnkViewCourse.NavigateUrl = "~/Views/Course/Section/?SubId=" + subject.Id;
                                    hidOrderby.Value          = "name";
                                    LoadSitemap(cls);
                                }
                            }
                    }
                }
            }
        }