Ejemplo n.º 1
0
        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 isManager = user.IsInRole(DbHelper.StaticValues.Roles.Manager);
                    var isTeacher = user.IsInRole(DbHelper.StaticValues.Roles.Teacher);

                    if (!isTeacher && !isManager)
                    {
                        Response.Redirect("~/");
                        return;
                    }


                    SetMarkCompletionDialog();

                    var edit = (Session["editMode"] as string) == "1";


                    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 teacherRoleId = usrHelper.GetRole(Academic.DbHelper.DbHelper.StaticValues.Roles.Teacher)
                                                        .Id;
                                    lbldNotice.Visible = !cls.ClassUsers.Any(x => x.RoleId == teacherRoleId &&
                                                                             !(x.Void ?? false));


                                    //lblStartDate.Text =cls.StartDate==null?" - ": cls.StartDate.Value.ToString("D");
                                    //lblEndDate.Text = cls.EndDate==null?" - ":cls.EndDate.Value.ToString("D");
                                    var clsname        = cls.GetName;
                                    var coursefullname = cls.GetCourseFullName;
                                    lblTitle.Text = clsname;

                                    if (cls.SessionComplete ?? false)
                                    {
                                        imgIndicate.ToolTip = "Complete";
                                        imgIndicate.Visible = true;
                                    }
                                    else if (cls.StartDate <= DateTime.Now && cls.EndDate >= DateTime.Now)
                                    {
                                        imgIndicate.Visible  = true;
                                        imgIndicate.ToolTip  = "Active";
                                        imgIndicate.ImageUrl = "~/Content/Icons/Start/active_icon_10px.png";
                                    }
                                    else
                                    {
                                        imgIndicate.Visible  = true;
                                        imgIndicate.ToolTip  = "Due";
                                        imgIndicate.ImageUrl = "~/Content/Icons/Watch/alarm_clock_14px.png";
                                    }

                                    lblEnrollmentMethod.Text = cls.EnrollmentMethod == 0
                                    ? "Auto"
                                    : (cls.EnrollmentMethod == 1) ? "Manual" : "Self";

                                    var autoEnrollment = cls.EnrollmentMethod == 0;

                                    var curTeach = helper.IsTheUserCurrentlyTeacher(user.Id,
                                                                                    cls.IsRegular ? cls.SubjectStructure.SubjectId : cls.SubjectId ?? 0);


                                    if (edit && (isManager || curTeach) && !(cls.SessionComplete ?? false))
                                    {
                                        lnkMarkCompletion.Visible = true;
                                        lnkEnrollStudents.Visible = (!autoEnrollment || isManager);//&& (isTeacher || isManager);
                                        lnkEnrollTeachers.Visible = isManager;
                                    }



                                    hidOrderby.Value = autoEnrollment ? "crn" : "name";

                                    LoadSitemap(cls);
                                    var from = Request.QueryString["from"];
                                    lnkReport.NavigateUrl         = "~/Views/Report/?ccId=" + cls.Id + "&from=" + from;
                                    lnkEnrollStudents.NavigateUrl = "~/Views/Class/Enrollment/Enrollment.aspx?ccId=" +
                                                                    hidSubjectSessionId.Value + "&type=student";
                                    lnkEnrollTeachers.NavigateUrl = "~/Views/Class/Enrollment/Enrollment.aspx?ccId=" +
                                                                    hidSubjectSessionId.Value + "&type=teacher";


                                    lblClassName.Text  = clsname;        //cls.IsRegular ? cls.GetName : cls.Name;
                                    lblCourseName.Text = coursefullname; //cls.IsRegular
                                    //? cls.SubjectStructure.Subject.FullName
                                    //: cls.Subject.FullName;


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



                                    //grouping
                                    //var grp = "No grouping";
                                    //if (cls.HasGrouping)
                                    //{
                                    //    grp = "";
                                    //    cls.SubjectClassGrouping.ToList().ForEach(c =>
                                    //    {
                                    //        grp += cls.Name + ", ";
                                    //    });
                                    //    grp = grp.TrimEnd(new char[] { ',' });
                                    //}
                                    //lblGrouping.Text = grp;



                                    //ListView1.DataSource = helper.ListSubjectSessionEnrolledUsers(clsId);
                                    //ListView1.DataSource = helper.ListEnrolledUsers(clsId);
                                    // ListView1.DataBind();
                                }
                            }
                    }
                }
            }
        }