Exemplo n.º 1
0
 /// <summary>
 /// This method populates the page controls from the passed NewsEntry object
 /// </summary>
 /// <param name="newsEntry">The NewsEntry object with values to populate the page controls</param>
 private void PopulatePage(Models.NewsEntry newsEntry)
 {
     //Set the page controls to the values from the object
     deEntryDate.Value        = newsEntry.EntryDate;
     ddEntryType.SelectedItem = ddEntryType.Items.FindByValue(newsEntry.NewsEntryTypeCodeFK);
     ddProgram.SelectedItem   = ddProgram.Items.FindByValue(newsEntry.ProgramFK);
     ddHub.SelectedItem       = ddHub.Items.FindByValue(newsEntry.HubFK);
     ddState.SelectedItem     = ddState.Items.FindByValue(newsEntry.StateFK);
     ddCohort.SelectedItem    = ddCohort.Items.FindByValue(newsEntry.CohortFK);
 }
Exemplo n.º 2
0
        /// <summary>
        /// This method fires when the user clicks the Save button in the
        /// submitNewsEntry user control
        /// </summary>
        /// <param name="sender">The submitNewsEntry control</param>
        /// <param name="e">The Click event</param>
        protected void submitNewsEntry_Click(object sender, EventArgs e)
        {
            if (currentProgramRole.AllowedToEdit.Value || currentProgramRole.RoleFK.Value == (int)Utilities.ProgramRoleFKs.HUB_DATA_VIEWER)
            {
                //To hold the success message type
                string successMessageType = null;

                //Fill the NewsEntry fields from the form
                currentNewsEntry.EntryDate           = Convert.ToDateTime(deEntryDate.Value);
                currentNewsEntry.NewsEntryTypeCodeFK = Convert.ToInt32(ddEntryType.Value);

                //Set the proper FKs
                if (currentNewsEntry.NewsEntryTypeCodeFK == (int)Utilities.NewsTypeFKs.APPLICATION)
                {
                    currentNewsEntry.ProgramFK = null;
                    currentNewsEntry.HubFK     = null;
                    currentNewsEntry.StateFK   = null;
                    currentNewsEntry.CohortFK  = null;
                }
                else if (currentNewsEntry.NewsEntryTypeCodeFK == (int)Utilities.NewsTypeFKs.PROGRAM_WIDE)
                {
                    currentNewsEntry.ProgramFK = Convert.ToInt32(ddProgram.Value);
                    currentNewsEntry.HubFK     = null;
                    currentNewsEntry.StateFK   = null;
                    currentNewsEntry.CohortFK  = null;
                }
                else if (currentNewsEntry.NewsEntryTypeCodeFK == (int)Utilities.NewsTypeFKs.HUB_WIDE)
                {
                    currentNewsEntry.ProgramFK = null;
                    currentNewsEntry.HubFK     = Convert.ToInt32(ddHub.Value);
                    currentNewsEntry.StateFK   = null;
                    currentNewsEntry.CohortFK  = null;
                }
                else if (currentNewsEntry.NewsEntryTypeCodeFK == (int)Utilities.NewsTypeFKs.STATE_WIDE)
                {
                    currentNewsEntry.ProgramFK = null;
                    currentNewsEntry.HubFK     = null;
                    currentNewsEntry.StateFK   = Convert.ToInt32(ddState.Value);
                    currentNewsEntry.CohortFK  = null;
                }
                else if (currentNewsEntry.NewsEntryTypeCodeFK == (int)Utilities.NewsTypeFKs.COHORT_WIDE)
                {
                    currentNewsEntry.ProgramFK = null;
                    currentNewsEntry.HubFK     = null;
                    currentNewsEntry.StateFK   = null;
                    currentNewsEntry.CohortFK  = Convert.ToInt32(ddCohort.Value);
                }

                if (currentNewsEntryPK > 0)
                {
                    //This is an edit
                    using (PyramidContext context = new PyramidContext())
                    {
                        //Set the success message
                        successMessageType = "NewsEntryEdited";

                        //Set the edit-only fields
                        currentNewsEntry.Editor   = User.Identity.Name;
                        currentNewsEntry.EditDate = DateTime.Now;

                        //Get the existing NewsEntry record
                        Models.NewsEntry existingNewsEntry = context.NewsEntry.Find(currentNewsEntry.NewsEntryPK);

                        //Overwrite the existing NewsEntry record with the values from the form
                        context.Entry(existingNewsEntry).CurrentValues.SetValues(currentNewsEntry);
                        context.SaveChanges();
                    }

                    //Redirect the user to the news page
                    Response.Redirect(string.Format("/Pages/News.aspx?messageType={0}", successMessageType));
                }
                else
                {
                    //This is an add
                    using (PyramidContext context = new PyramidContext())
                    {
                        //Set the success message
                        successMessageType = "NewsEntryAdded";

                        //Set the create-only fields
                        currentNewsEntry.Creator    = User.Identity.Name;
                        currentNewsEntry.CreateDate = DateTime.Now;

                        //Add the NewsEntry to the database
                        context.NewsEntry.Add(currentNewsEntry);
                        context.SaveChanges();
                    }

                    //Redirect the user to the  this page
                    Response.Redirect(string.Format("/Pages/NewsManagement.aspx?NewsEntryPK={0}&Action=Edit&messageType={1}",
                                                    currentNewsEntry.NewsEntryPK.ToString(), successMessageType));
                }
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Get the user's current program role
            currentProgramRole = Utilities.GetProgramRoleFromSession(Session);

            //Get the News Entry PK from the query string
            if (!string.IsNullOrWhiteSpace(Request.QueryString["NewsEntryPK"]))
            {
                int.TryParse(Request.QueryString["NewsEntryPK"], out currentNewsEntryPK);
            }

            using (PyramidContext context = new PyramidContext())
            {
                //Get the News Entry from the database
                currentNewsEntry = context.NewsEntry.AsNoTracking()
                                   .Include(ne => ne.CodeNewsEntryType)
                                   .Where(ne => ne.NewsEntryPK == currentNewsEntryPK).FirstOrDefault();

                //Check to see if the News Entry from the database exists
                if (currentNewsEntry == null)
                {
                    //The NewsEntry from the database doesn't exist, set the current News Entry to a default value
                    currentNewsEntry = new Models.NewsEntry();
                }
            }

            //Prevent users from viewing entries from other programs
            if (currentProgramRole.RoleFK.Value == (int)Utilities.ProgramRoleFKs.DATA_COLLECTOR ||
                (currentNewsEntry.NewsEntryPK > 0 &&
                 ((currentNewsEntry.NewsEntryTypeCodeFK == (int)Utilities.NewsTypeFKs.PROGRAM_WIDE &&
                   !currentProgramRole.ProgramFKs.Contains(currentNewsEntry.ProgramFK.Value)) ||
                  (currentNewsEntry.NewsEntryTypeCodeFK == (int)Utilities.NewsTypeFKs.STATE_WIDE &&
                   currentProgramRole.StateFK.Value != currentNewsEntry.StateFK.Value) ||
                  (currentNewsEntry.NewsEntryTypeCodeFK == (int)Utilities.NewsTypeFKs.HUB_WIDE &&
                   currentProgramRole.HubFK.Value != currentNewsEntry.HubFK.Value) ||
                  (currentNewsEntry.NewsEntryTypeCodeFK == (int)Utilities.NewsTypeFKs.COHORT_WIDE &&
                   !currentProgramRole.CohortFKs.Contains(currentNewsEntry.CohortFK.Value)) ||
                  !currentNewsEntry.CodeNewsEntryType.RolesAuthorizedToModify.Contains(currentProgramRole.RoleFK.Value.ToString() + ","))))
            {
                Response.Redirect(string.Format("/Pages/News.aspx?messageType={0}", "NotAuthorized"));
            }

            //Show certain divs based on whether this is an add or edit
            if (currentNewsEntryPK > 0)
            {
                divAddOnlyMessage.Visible = false;
                divEditOnly.Visible       = true;
            }
            else
            {
                divAddOnlyMessage.Visible = true;
                divEditOnly.Visible       = false;
            }

            //Show the edit only div if this is an edit
            divEditOnly.Visible = (currentNewsEntryPK > 0 ? true : false);

            if (!IsPostBack)
            {
                //Hide the master page title
                ((LoggedIn)this.Master).HideTitle();

                //Bind the data bound controls
                BindDataBoundControls();

                //Check to see if this is an edit
                if (currentNewsEntryPK > 0)
                {
                    //This is an edit
                    //Populate the page
                    PopulatePage(currentNewsEntry);
                }

                //Get the action from the query string
                string action;
                if (Request.QueryString["action"] != null)
                {
                    action = Request.QueryString["action"];
                }
                else
                {
                    action = "View";
                }

                //Check for messages in the query string
                string messageType = Request.QueryString["messageType"];

                //Show the message if it exists
                if (!string.IsNullOrWhiteSpace(messageType))
                {
                    switch (messageType)
                    {
                    case "NewsEntryAdded":
                        msgSys.ShowMessageToUser("success", "Success", "News entry successfully added!<br/><br/>Specific items can now be added.", 10000);
                        break;

                    case "NotAuthorized":
                        msgSys.ShowMessageToUser("danger", "Not Authorized", "You are not authorized to view that information!", 10000);
                        break;

                    default:
                        break;
                    }
                }

                //Allow adding/editing depending on the user's role and the action
                if (currentNewsEntry.NewsEntryPK == 0 &&
                    (currentProgramRole.AllowedToEdit.Value ||
                     currentProgramRole.RoleFK.Value == (int)Utilities.ProgramRoleFKs.HUB_DATA_VIEWER))
                {
                    //Show the submit button
                    submitNewsEntry.ShowSubmitButton = true;

                    //Show certain controls
                    hfViewOnly.Value = "False";

                    //Enable page controls
                    EnableControls(true);

                    //Set the page title
                    lblPageTitle.Text = "Add New News Entry";
                }
                else if (currentNewsEntry.NewsEntryPK > 0 &&
                         action.ToLower() == "edit" &&
                         (currentProgramRole.AllowedToEdit.Value ||
                          currentProgramRole.RoleFK.Value == (int)Utilities.ProgramRoleFKs.HUB_DATA_VIEWER))
                {
                    //Show the submit button
                    submitNewsEntry.ShowSubmitButton = true;

                    //Show certain controls
                    hfViewOnly.Value = "False";

                    //Enable page controls
                    EnableControls(true);

                    //Set the page title
                    lblPageTitle.Text = "Edit News Entry";
                }
                else
                {
                    //Hide the submit button
                    submitNewsEntry.ShowSubmitButton = false;

                    //Hide certain controls
                    hfViewOnly.Value = "True";

                    //Disable page controls
                    EnableControls(false);

                    //Set the page title
                    lblPageTitle.Text = "View News Entry";
                }

                //Set the focus to the news entry date field
                deEntryDate.Focus();
            }
        }