Exemplo n.º 1
0
    protected void btnSaveDetails_OnClick(object sender, EventArgs e)
    {
        // Verify the currentuser is a teacher for this school
        var ua = new UserAccessor(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
        var recordaccessor = new RecordAccessor(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
        var studentaccessor = new StudentAccessor(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);

        var mu = Membership.GetUser();

        if (mu != null)
        {
            var user = ua.GetUserByLogin(mu.UserName);

            if (user.IsTeacher)
            {
                // Get the students involved
                var students = GetSelectedStudents();

                // Get the activity type
                var activitytype = hidRecordType.Value;

                // Get the subjects involved
                var subjects = GetSelectedSubjects();

                // Get the date
                var recordDate = DateTime.Parse(txtRecordDate.Text);

                // Get the details
                switch (activitytype)
                {
                    case "Activity":
                        var ad = pnlStudents.FindControl("recordactivity");
                        var ra = ad as RecordActivity;

                        var activity = new Activity();
                        activity.ActivityDate = recordDate;
                        activity.ActivityName = ra.ActivityName;
                        activity.Notes = ra.ActivityNote;
                        activity.TimeSpent = ra.TimeSpent;
                        activity.Users.Add(user);

                        foreach (var subject in subjects)
                        {
                            activity.Subjects.Add(subject);
                        }

                        foreach (var student in students)
                        {
                            activity.Children.Add(student);
                        }

                        recordaccessor.PersistActivity(activity);
                        Response.Redirect("~/Record.aspx");
                        break;
                    default:
                        break;
                }

            }
        }
    }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var mu = Membership.GetUser();

            if (mu != null)
            {
                var ca = new ChildAccessor(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
                var ua = new UserAccessor(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
                var sa = new SubjectAccessor(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
                var user = ua.GetUserByLogin(mu.UserName);
                //var cs = (ChildSelector)LoadControl("~/ChildSelector.ascx");

                //cs.Children = ca.GetChildrenByUser(user);

                var cs = pnlStudents.FindControl("childselector") as ChildSelector;
                if (cs != null)
                {
                    cs.Children = ca.GetChildrenByUser(user);
                }

                var ss = pnlSubjects.FindControl("subjectSelectionTool") as SubjectSelector;
                if (ss != null)
                {
                    ss.Subjects = sa.GetAllSubjects();
                }

            }
        }

        if (txtRecordDate.Text == string.Empty)
        {
            txtRecordDate.Text = DateTime.Today.ToShortDateString();
        }

        if (hidRecordType.Value == "Activity")
        {
            var ra = (RecordActivity) LoadControl("~/RecordActivity.ascx");
            ra.ID = "recordactivity";
            pnlRecordDetails.Controls.Add(ra);
        }
    }