/// <summary> /// This method populates the page controls from the passed CoachingLog object /// </summary> /// <param name="coachingLog">The CoachingLog object with values to populate the page controls</param> private void PopulatePage(Models.CoachingLog coachingLog) { //Set the page controls to the values from the object //Basic info deLogDate.Value = coachingLog.LogDate; ddCoach.SelectedItem = ddCoach.Items.FindByValue(coachingLog.CoachFK); ddTeacher.SelectedItem = ddTeacher.Items.FindByValue(coachingLog.TeacherFK); txtDurationMinutes.Value = coachingLog.DurationMinutes; //Observations ddOBSObserving.SelectedItem = ddOBSObserving.Items.FindByValue(coachingLog.OBSObserving); ddOBSModeling.SelectedItem = ddOBSModeling.Items.FindByValue(coachingLog.OBSModeling); ddOBSVerbalSupport.SelectedItem = ddOBSVerbalSupport.Items.FindByValue(coachingLog.OBSVerbalSupport); ddOBSSideBySide.SelectedItem = ddOBSSideBySide.Items.FindByValue(coachingLog.OBSSideBySide); ddOBSProblemSolving.SelectedItem = ddOBSProblemSolving.Items.FindByValue(coachingLog.OBSProblemSolving); ddOBSReflectiveConversation.SelectedItem = ddOBSReflectiveConversation.Items.FindByValue(coachingLog.OBSReflectiveConversation); ddOBSEnvironment.SelectedItem = ddOBSEnvironment.Items.FindByValue(coachingLog.OBSEnvironment); ddOBSOtherHelp.SelectedItem = ddOBSOtherHelp.Items.FindByValue(coachingLog.OBSOtherHelp); ddOBSConductTPOT.SelectedItem = ddOBSConductTPOT.Items.FindByValue(coachingLog.OBSConductTPOT); ddOBSConductTPITOS.SelectedItem = ddOBSConductTPITOS.Items.FindByValue(coachingLog.OBSConductTPITOS); ddOBSOther.SelectedItem = ddOBSOther.Items.FindByValue(coachingLog.OBSOther); txtOBSOtherSpecify.Value = coachingLog.OBSOtherSpecify; //Meetings ddMEETProblemSolving.SelectedItem = ddMEETProblemSolving.Items.FindByValue(coachingLog.MEETProblemSolving); ddMEETReflectiveConversation.SelectedItem = ddMEETReflectiveConversation.Items.FindByValue(coachingLog.MEETReflectiveConversation); ddMEETEnvironment.SelectedItem = ddMEETEnvironment.Items.FindByValue(coachingLog.MEETEnvironment); ddMEETRoleplay.SelectedItem = ddMEETRoleplay.Items.FindByValue(coachingLog.MEETRoleplay); ddMEETVideo.SelectedItem = ddMEETVideo.Items.FindByValue(coachingLog.MEETVideo); ddMEETGraphic.SelectedItem = ddMEETGraphic.Items.FindByValue(coachingLog.MEETGraphic); ddMEETGoalSetting.SelectedItem = ddMEETGoalSetting.Items.FindByValue(coachingLog.MEETGoalSetting); ddMEETPerformance.SelectedItem = ddMEETPerformance.Items.FindByValue(coachingLog.MEETPerformance); ddMEETMaterial.SelectedItem = ddMEETMaterial.Items.FindByValue(coachingLog.MEETMaterial); ddMEETDemonstration.SelectedItem = ddMEETDemonstration.Items.FindByValue(coachingLog.MEETDemonstration); ddMEETOther.SelectedItem = ddMEETOther.Items.FindByValue(coachingLog.MEETOther); txtMEETOtherSpecify.Value = coachingLog.MEETOtherSpecify; //Follow-up ddFUEmail.SelectedItem = ddFUEmail.Items.FindByValue(coachingLog.FUEmail); ddFUPhone.SelectedItem = ddFUPhone.Items.FindByValue(coachingLog.FUPhone); ddFUInPerson.SelectedItem = ddFUInPerson.Items.FindByValue(coachingLog.FUInPerson); }
protected void Page_Load(object sender, EventArgs e) { //Get the user's current program role currentProgramRole = Utilities.GetProgramRoleFromSession(Session); //Get the CoachingLog PK from the query string if (!string.IsNullOrWhiteSpace(Request.QueryString["CoachingLogPK"])) { int.TryParse(Request.QueryString["CoachingLogPK"], out currentCoachingLogPK); } //Don't allow aggregate viewers into this page if (currentProgramRole.RoleFK.Value == (int)Utilities.ProgramRoleFKs.AGGREGATE_DATA_VIEWER) { Response.Redirect("/Pages/CoachingLogDashboard.aspx?messageType=NotAuthorized"); } using (PyramidContext context = new PyramidContext()) { //Get the CoachingLog from the database currentCoachingLog = context.CoachingLog .AsNoTracking() .Include(cl => cl.Program) .Where(a => a.CoachingLogPK == currentCoachingLogPK) .FirstOrDefault(); //Check to see if the CoachingLog from the database exists if (currentCoachingLog == null) { //The CoachingLog from the database doesn't exist, set the current CoachingLog to a default value currentCoachingLog = new Models.CoachingLog(); //Set the program label to the current user's program lblProgram.Text = currentProgramRole.ProgramName; } else { //Set the program label to the form's program lblProgram.Text = currentCoachingLog.Program.ProgramName; } } //Prevent users from viewing CoachingLogs from other programs if (currentCoachingLog.CoachingLogPK > 0 && !currentProgramRole.ProgramFKs.Contains(currentCoachingLog.ProgramFK)) { Response.Redirect(string.Format("/Pages/CoachingLogDashboard.aspx?messageType={0}", "NOCoachingLog")); } //Get the proper program fk currentProgramFK = (currentCoachingLog.CoachingLogPK > 0 ? currentCoachingLog.ProgramFK : currentProgramRole.CurrentProgramFK.Value); //Set the max value for the coaching date deLogDate.MaxDate = DateTime.Now; if (!IsPostBack) { //Hide the master page title ((Dashboard)this.Master).HideTitle(); //Check to see if this is an edit or view if (currentCoachingLogPK > 0) { //This is an edit or view //Populate the page PopulatePage(currentCoachingLog); //Bind the dropdowns BindDropDowns(currentCoachingLog.LogDate, currentCoachingLog.ProgramFK, currentCoachingLog.CoachFK, currentCoachingLog.TeacherFK); } else { //This is an add, make the coach and teacher dropdown read-only for now ddCoach.ReadOnly = true; ddTeacher.ReadOnly = true; } //Get the action from the query string string action; if (Request.QueryString["action"] != null) { action = Request.QueryString["action"]; } else { action = "View"; } //Allow adding/editing depending on the user's role and the action if (currentCoachingLog.CoachingLogPK == 0 && currentProgramRole.AllowedToEdit.Value) { //Show the submit button submitCoachingLog.ShowSubmitButton = true; //Show certain controls hfViewOnly.Value = "False"; //Enable page controls EnableControls(true); //Set the page title lblPageTitle.Text = "Add New Classroom Coaching Log"; } else if (currentCoachingLog.CoachingLogPK > 0 && action.ToLower() == "edit" && currentProgramRole.AllowedToEdit.Value) { //Show the submit button submitCoachingLog.ShowSubmitButton = true; //Show certain controls hfViewOnly.Value = "False"; //Enable page controls EnableControls(true); //Set the page title lblPageTitle.Text = "Edit Classroom Coaching Log"; } else { //Hide the submit button submitCoachingLog.ShowSubmitButton = false; //Hide certain controls hfViewOnly.Value = "True"; //Disable page controls EnableControls(false); //Set the page title lblPageTitle.Text = "View Classroom Coaching Log"; } //Set focus to the coaching date field deLogDate.Focus(); } }
/// <summary> /// This method fires when the user clicks the Save button in the /// submitCoachingLog user control /// </summary> /// <param name="sender">The submitCoachingLog control</param> /// <param name="e">The Click event</param> protected void submitCoachingLog_Click(object sender, EventArgs e) { if (currentProgramRole.AllowedToEdit.Value) { //To hold the success message type string successMessageType = null; //Fill the CoachingLog fields from the form //Basic info currentCoachingLog.LogDate = Convert.ToDateTime(deLogDate.Value); currentCoachingLog.CoachFK = Convert.ToInt32(ddCoach.Value); currentCoachingLog.TeacherFK = Convert.ToInt32(ddTeacher.Value); currentCoachingLog.DurationMinutes = Convert.ToInt32(txtDurationMinutes.Value); //Observations currentCoachingLog.OBSObserving = Convert.ToBoolean(ddOBSObserving.Value); currentCoachingLog.OBSModeling = Convert.ToBoolean(ddOBSModeling.Value); currentCoachingLog.OBSVerbalSupport = Convert.ToBoolean(ddOBSVerbalSupport.Value); currentCoachingLog.OBSSideBySide = Convert.ToBoolean(ddOBSSideBySide.Value); currentCoachingLog.OBSProblemSolving = Convert.ToBoolean(ddOBSProblemSolving.Value); currentCoachingLog.OBSReflectiveConversation = Convert.ToBoolean(ddOBSReflectiveConversation.Value); currentCoachingLog.OBSEnvironment = Convert.ToBoolean(ddOBSEnvironment.Value); currentCoachingLog.OBSOtherHelp = Convert.ToBoolean(ddOBSOtherHelp.Value); currentCoachingLog.OBSConductTPOT = Convert.ToBoolean(ddOBSConductTPOT.Value); currentCoachingLog.OBSConductTPITOS = Convert.ToBoolean(ddOBSConductTPITOS.Value); currentCoachingLog.OBSOther = Convert.ToBoolean(ddOBSOther.Value); currentCoachingLog.OBSOtherSpecify = (txtOBSOtherSpecify.Value == null ? null : txtOBSOtherSpecify.Value.ToString()); //Meetings currentCoachingLog.MEETProblemSolving = Convert.ToBoolean(ddMEETProblemSolving.Value); currentCoachingLog.MEETReflectiveConversation = Convert.ToBoolean(ddMEETReflectiveConversation.Value); currentCoachingLog.MEETEnvironment = Convert.ToBoolean(ddMEETEnvironment.Value); currentCoachingLog.MEETRoleplay = Convert.ToBoolean(ddMEETRoleplay.Value); currentCoachingLog.MEETVideo = Convert.ToBoolean(ddMEETVideo.Value); currentCoachingLog.MEETGraphic = Convert.ToBoolean(ddMEETGraphic.Value); currentCoachingLog.MEETGoalSetting = Convert.ToBoolean(ddMEETGoalSetting.Value); currentCoachingLog.MEETPerformance = Convert.ToBoolean(ddMEETPerformance.Value); currentCoachingLog.MEETMaterial = Convert.ToBoolean(ddMEETMaterial.Value); currentCoachingLog.MEETDemonstration = Convert.ToBoolean(ddMEETDemonstration.Value); currentCoachingLog.MEETOther = Convert.ToBoolean(ddMEETOther.Value); currentCoachingLog.MEETOtherSpecify = (txtMEETOtherSpecify.Value == null ? null : txtMEETOtherSpecify.Value.ToString()); //Follow-up currentCoachingLog.FUEmail = Convert.ToBoolean(ddFUEmail.Value); currentCoachingLog.FUPhone = Convert.ToBoolean(ddFUPhone.Value); currentCoachingLog.FUInPerson = Convert.ToBoolean(ddFUInPerson.Value); if (currentCoachingLog.FUEmail || currentCoachingLog.FUPhone || currentCoachingLog.FUInPerson) { currentCoachingLog.FUNone = false; } else { currentCoachingLog.FUNone = true; } if (currentCoachingLogPK > 0) { //This is an edit using (PyramidContext context = new PyramidContext()) { //Set the success message successMessageType = "CoachingLogEdited"; //Set the edit-only fields currentCoachingLog.Editor = User.Identity.Name; currentCoachingLog.EditDate = DateTime.Now; //Get the existing CoachingLog record Models.CoachingLog existingCoachingLog = context.CoachingLog.Find(currentCoachingLog.CoachingLogPK); //Overwrite the existing CoachingLog record with the values from the form context.Entry(existingCoachingLog).CurrentValues.SetValues(currentCoachingLog); context.SaveChanges(); } //Redirect the user to the CoachingLog dashboard Response.Redirect(string.Format("/Pages/CoachingLogDashboard.aspx?messageType={0}", successMessageType)); } else { //This is an add using (PyramidContext context = new PyramidContext()) { //Set the success message successMessageType = "CoachingLogAdded"; //Set the create-only fields currentCoachingLog.Creator = User.Identity.Name; currentCoachingLog.CreateDate = DateTime.Now; currentCoachingLog.ProgramFK = currentProgramRole.CurrentProgramFK.Value; //Add the CoachingLog to the database context.CoachingLog.Add(currentCoachingLog); context.SaveChanges(); } //Redirect the user to the CoachingLog dashboard Response.Redirect(string.Format("/Pages/CoachingLogDashboard.aspx?messageType={0}", successMessageType)); } } }