/*
     * CREATED:     C. Stanhope		MAR 23 2018
     *
     * CareSiteDDL_SelectedIndexChanged()
     * Triggered when the care site DDL's selected field is changed. If the DDL is changed to "Select...", a message is displayed and the manage care site form is hidden. If the user selects a care site, the manage care site form is displayed and populated with the proper information.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * MessageUserControl.ShowInfoMessage()
     * CareSiteController.GetCareSiteByCareSiteID()
     * MessageUserControl.ShowErrorMessage()
     */
    protected void CareSiteDDL_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (CareSiteDDL.SelectedIndex == 0)
        {
            MessageUserControl.ShowInfoMessage("Please select a care site to manage.");
            AccountForm.Visible = false;
            selectedCareSite    = null;
        }
        else
        {
            int selectedID;

            if (int.TryParse(CareSiteDDL.SelectedValue, out selectedID))
            {
                selectedCareSite = careSiteController.GetCareSiteByCareSiteID(selectedID);

                // populate form with info from database
                CareSiteNameTextBox.Text  = selectedCareSite.caresitename;
                AddressTextBox.Text       = selectedCareSite.address;
                CityTextBox.Text          = selectedCareSite.city;
                ProvinceDDL.SelectedValue = selectedCareSite.province;
            }
            else
            {
                MessageUserControl.ShowErrorMessage("An error occurred converting the care site drop-down list value. Please try again. If error persists, please contact your administrator.");
            }
        }
    }
Example #2
0
        public void DeactivateCareSite(CareSiteDTO deactivateCareSite)
        {
            using (var context = new MSSContext())
            {
                var caresite = context.caresites.Find(deactivateCareSite.caresiteid);
                caresite.activeyn = false;

                var existingCareSite = context.Entry(caresite);
                existingCareSite.State = EntityState.Modified;
                context.SaveChanges();
            }
        }
 /*
  * CREATED:     C. Stanhope		MAR 23 2018
  *
  * Page_Load()
  * Triggered on page load and is used to show or hide the form depending on whether the user has selected a care site from the drop-down list.
  *
  * PARAMETERS:
  * object sender - references the object that raised the Page_Load event
  * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
  *
  * RETURNS:
  * void
  *
  * ODEV METHOD CALLS:
  * None
  */
 protected void Page_Load(object sender, EventArgs e)
 {
     if (CareSiteDDL.SelectedIndex == 0)
     {
         AccountForm.Visible = false;
         selectedCareSite    = null;
     }
     else
     {
         AccountForm.Visible = true;
     }
 }
Example #4
0
        /*
         * CREATED:     H. L'Heureux, H. Conant        MAR 13 2018
         *
         * GetCareSiteName()
         * This method will accept a care site id and return the name of that care site.
         *
         * PARAMETERS:
         * int careSiteID - the ID of the care site in question
         *
         * RETURNS:
         * int - the care site ID
         *
         * METHOD CALLS: <- Holly: any method calls not just to metods you have made (ex .Find(), CareSiteDTO())
         * None
         */
        public string GetCareSiteName(int careSiteID)
        {
            using (var context = new MSSContext())
            {
                var careSite = context.caresites.Find(careSiteID);

                CareSiteDTO tempCareSite = new CareSiteDTO();

                tempCareSite.caresitename = careSite.caresitename;

                return(tempCareSite.caresitename);
            }
        }
Example #5
0
 public void UpdateCareSite(CareSiteDTO updatedCareSite)
 {
     using (var context = new MSSContext())
     {
         var caresite = context.caresites.Find(updatedCareSite.caresiteid);
         caresite.caresitename = updatedCareSite.caresitename;
         caresite.address      = updatedCareSite.address;
         caresite.city         = updatedCareSite.city;
         caresite.province     = updatedCareSite.province;
         var existingCareSite = context.Entry(caresite);
         existingCareSite.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #6
0
        public void AddCareSite(CareSiteDTO careSiteToAdd)
        {
            using (var context = new MSSContext())
            {
                caresite newCareSite = new caresite();
                newCareSite.caresitename = careSiteToAdd.caresitename;
                newCareSite.address      = careSiteToAdd.address;
                newCareSite.city         = careSiteToAdd.city;
                newCareSite.province     = careSiteToAdd.province;
                newCareSite.activeyn     = true;

                context.caresites.Add(newCareSite);
                context.SaveChanges();
            }
        }
    /*
     * CREATED:     C. Stanhope		MAR 23 2018
     * MODIFIED:   C. Stanhope     APR 6 2018
     *  - added try-catch for database access
     *
     * DeactivateCareSiteButton_Click()
     * Used to deactivate a care site in the database.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * MessageUserControl.ShowInfoMessage()
     * CareSiteController.GetCareSiteByCareSiteID()
     * MessageUserControl.ShowErrorMessage()
     */
    protected void DeactivateCareSiteButton_Click(object sender, EventArgs e)
    {
        if (selectedCareSite != null)
        {
            try
            {
                careSiteController.DeactivateCareSite(selectedCareSite);

                MessageUserControl.ShowSuccessMessage("The " + selectedCareSite.caresitename + " care site was successfully deactivated.");

                CareSiteDDL.SelectedIndex = 0;
                CareSiteNameTextBox.Text  = "";
                AddressTextBox.Text       = "";
                CityTextBox.Text          = "";
                AccountForm.Visible       = false;

                #region resetting care site ddl
                CareSiteDDL.AppendDataBoundItems = false; // clears old values
                CareSiteDDL.DataSourceID         = null;

                // get new list of care sites
                List <CareSiteDTO> ddlCareSites = careSiteController.GetActiveCareSites();

                // create a fake care site that acts as a "select" in the ddl
                CareSiteDTO fakeSelectCareSite = new CareSiteDTO();
                fakeSelectCareSite.caresiteid   = 0;
                fakeSelectCareSite.caresitename = "Select...";

                ddlCareSites.Add(fakeSelectCareSite);

                // put the new "select" care site at the top of the list
                ddlCareSites = ddlCareSites.OrderBy(site => site.caresiteid).ToList();

                // bind data source
                CareSiteDDL.DataSource = ddlCareSites;
                CareSiteDDL.DataBind();
                #endregion
            }
            catch (Exception ex)
            {
                MessageUserControl.ShowErrorMessage("Deactivating care site failed. Please try again. If error persists, please contact your administrator.", ex);
            }
        }
        else
        {
            MessageUserControl.ShowErrorMessage("No care site selected. The \"Deactivate Care Site\" button should not be available if no care site is selected. Please try again. If error persists, please contact your administrator.");
        }
    }
Example #8
0
 public List <CareSiteDTO> GetCareSites()
 {
     using (var context = new MSSContext())
     {
         List <CareSiteDTO> careSiteDTOs = new List <CareSiteDTO>();
         var careSites = context.caresites.ToList();
         foreach (caresite site in careSites)
         {
             CareSiteDTO temp = new CareSiteDTO();
             temp.caresiteid   = site.caresiteid;
             temp.caresitename = site.caresitename;
             careSiteDTOs.Add(temp);
         }
         return(careSiteDTOs);
     }
 }
Example #9
0
 public List <CareSiteDTO> GetActiveCareSites()
 {
     using (var context = new MSSContext())
     {
         var activeCareSitess = from aCareSite in context.caresites
                                where aCareSite.activeyn == true
                                select aCareSite;
         List <CareSiteDTO> careSiteDTOs = new List <CareSiteDTO>();
         foreach (caresite site in activeCareSitess)
         {
             CareSiteDTO temp = new CareSiteDTO();
             temp.caresiteid   = site.caresiteid;
             temp.caresitename = site.caresitename;
             careSiteDTOs.Add(temp);
         }
         return(careSiteDTOs);
     }
 }
Example #10
0
        /*
         * CREATED:    C. Stanhope         MAR 23 2018
         * MODIFIED:   C. Stanhope         MAR 24 2018
         *  - forgot to assign care site ID. Fixed now.
         *
         * GetCareSiteByCareSiteID()
         * Retrieves a care site object that matches the passed care site ID.
         *
         * PARAMETERS:
         * int careSiteID - the ID of the desired care site
         *
         * RETURNS:
         * CareSiteDTO - the desired care site
         *
         * ODEV METHOD CALLS:
         * None
         */
        public CareSiteDTO GetCareSiteByCareSiteID(int careSiteID)
        {
            using (var context = new MSSContext())
            {
                CareSiteDTO desiredCareSite = new CareSiteDTO();

                var tempCareSite = context.caresites.Find(careSiteID);

                desiredCareSite.caresiteid   = tempCareSite.caresiteid;
                desiredCareSite.caresitename = tempCareSite.caresitename;
                desiredCareSite.address      = tempCareSite.address;
                desiredCareSite.city         = tempCareSite.city;
                desiredCareSite.province     = tempCareSite.province;
                desiredCareSite.activeyn     = tempCareSite.activeyn;

                return(desiredCareSite);
            }
        }
Example #11
0
    /*
     * CREATED:     C. Stanhope		MAR 23 2018
     * MODIFIED:   C. Stanhope     MAR 24 2018
     *  - moved error list method to its own class and call it
     *  - changed validation to account for care site name length
     * MODIFIED:   C. Stanhope     APR 5 2018
     *  - trim whitespace on inputs
     * MODIFIED:   C. Stanhope     APR 6 2018
     *  - added try-catch for database access
     * MODIFIED:   C. Stanhope     APR 17 2018
     *  - fixed city regex to limit at 30 characters
     *  - fixed care site regex to limit at 80 characters
     *
     * AddCareSiteButton_Click()
     * Used to add a care site to the database. Validates all input fields.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * CareSiteController.AddCareSite()
     * MessageUserControl.ShowSuccessMessage()
     * MessageUserControl.ShowInfoMessage()
     * ErrorMessagesAndValidation.ErrorList()
     */
    protected void AddCareSiteButton_Click(object sender, EventArgs e)
    {
        bool          isValid   = true;
        List <string> errorList = new List <string>();

        #region regexes for validation
        Regex careSiteRegex = new Regex(@"^[A-z]{1}[A-z 0-9 .-]{4,79}$");
        Regex addressRegex  = new Regex(@"^[A-z 0-9 .#-]{1,40}$");
        Regex cityRegex     = new Regex(@"^[A-z]{1}[A-z .-]{0,29}$");
        #endregion

        #region get values from page and validate
        string careSiteName = CareSiteNameTextBox.Text.Trim();
        if (!careSiteRegex.IsMatch(careSiteName))
        {
            errorList.Add("Care site must be a minimum of 5 characters and a maximum of 80 characters long. It must start with a letter and can contain letters, numbers, and the following symbols: . -");
            isValid = false;
        }

        string address = AddressTextBox.Text.Trim();
        if (!addressRegex.IsMatch(address))
        {
            errorList.Add("Address must be a minimum of 1 letter and a maximum of 40 characters long. It can contain letters, numbers, and the following symbols: # . -");
            isValid = false;
        }

        string city = CityTextBox.Text.Trim();
        if (!cityRegex.IsMatch(city))
        {
            errorList.Add("City must be a minimum of 1 letter and a maximum of 30 characters long. It must start with a letter and can contain letters and the following symbols: . -");
            isValid = false;
        }

        string province = ProvinceDDL.SelectedValue;
        if (ProvinceDDL.SelectedIndex == 0)
        {
            errorList.Add("A province must be selected from the drop-down list");
            isValid = false;
        }

        #endregion

        if (isValid)
        {
            #region put valid data into DTO, add to database, show success message, clear page
            CareSiteDTO newCareSite = new CareSiteDTO();

            newCareSite.caresitename = careSiteName;
            newCareSite.address      = address;
            newCareSite.city         = city;
            newCareSite.province     = province;

            CareSiteController careSiteController = new CareSiteController();
            try
            {
                careSiteController.AddCareSite(newCareSite);

                // show message, clear page
                MessageUserControl.ShowSuccessMessage("New care site " + careSiteName + " was successfully added. Please navigate to the Manage Units page to add units to the new care site.");

                CareSiteNameTextBox.Text  = "";
                AddressTextBox.Text       = "";
                CityTextBox.Text          = "";
                ProvinceDDL.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageUserControl.ShowErrorMessage("Adding care site failed. Please try again. If error persists, please contact your administrator.", ex);
            }
            #endregion
        }
        else
        {
            MessageUserControl.ShowInfoList("The following errors caused adding a care site to fail: ", errorList);
        }
    }