Пример #1
0
        public List <UnitsPOCO> GetArchivedUnits(int siteID)
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    var archivedUnitList = from x in context.Units
                                           where x.archived_yn == true &&
                                           !x.unit_number.Contains("Not Applicable") &&
                                           x.site_id == siteID
                                           orderby x.unit_number ascending
                                           select new UnitsPOCO()
                    {
                        unitID       = x.unit_id,
                        unitNumber   = x.unit_number,
                        dateModified = x.date_modified,
                        username     = x.AdministratorAccount.username
                    };

                    return(archivedUnitList.ToList());
                }
                catch (Exception e)
                {
                    throw new Exception("Something went wrong. See " + e.Message);
                }
            }
        }//end of GetArchivedUnits
Пример #2
0
 public List <ContactSubmittedSurveyPOCO> GetContactRequestList(int siteID)
 {
     using (var context = new FSOSSContext())
     {
         try
         {
             var contactList = from x in context.SubmittedSurveys
                               where x.Unit.site_id == siteID &&
                               x.contact_request == true &&
                               x.contacted == false
                               orderby x.date_entered descending
                               select new ContactSubmittedSurveyPOCO
             {
                 submittedSurveyID  = x.submitted_survey_id,
                 unitNumber         = x.Unit.unit_number,
                 participantType    = x.ParticipantType.participant_description,
                 mealName           = x.Meal.meal_name,
                 dateEntered        = x.date_entered,
                 contactRequest     = x.contact_request,
                 contacted          = x.contacted,
                 contactRoomNumber  = x.contact_room_number,
                 contactPhoneNumber = x.contact_phone_number
             };
             return(contactList.ToList());
         }
         catch (Exception e)
         {
             throw new Exception("Please contact the Administrator with the error message: " + e.Message);
         }
     }
 }
Пример #3
0
        public List <ParticipantTypePOCO> GetArchivedParticipantTypeList()
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    var participantTypeList = from x in context.ParticipantTypes
                                              where x.archived_yn
                                              orderby x.participant_description ascending
                                              select new ParticipantTypePOCO()
                    {
                        participantTypeID          = x.participant_type_id,
                        participantTypeDescription = x.participant_description
                        ,
                        administratorAccountId = x.administrator_account_id,
                        username     = x.AdministratorAccount.username,
                        dateModified = x.date_modified,
                        archivedYn   = x.archived_yn
                    };

                    return(participantTypeList.ToList());
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
Пример #4
0
        public List <GenderPOCO> GetGenderList()
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    var genderList = from x in context.Genders
                                     where !x.archived_yn && !x.gender_description.Contains("Prefer not to Answer")
                                     orderby x.gender_description ascending
                                     select new GenderPOCO()
                    {
                        genderID               = x.gender_id,
                        genderDescription      = x.gender_description,
                        administratorAccountId = x.administrator_account_id,
                        username               = x.AdministratorAccount.username,
                        dateModified           = x.date_modified,
                        archivedYn             = x.archived_yn
                    };

                    return(genderList.ToList());
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
Пример #5
0
        public string NewSite_NewUnit(string newSiteName, int admin)
        {
            using (var context = new FSOSSContext())
            {
                string message = "";

                try
                {
                    //Grab the new site id, using the newSiteName
                    int siteId = (from x in context.Sites
                                  where x.site_name.Equals(newSiteName) &&
                                  x.archived_yn == false
                                  select x.site_id).FirstOrDefault();

                    //Add a new Unit with the unit_number "Not Applicable"
                    Unit newSite = new Unit()
                    {
                        administrator_account_id = admin,
                        site_id       = siteId,
                        date_modified = DateTime.Now,
                        unit_number   = "Not Applicable",
                        archived_yn   = false
                    };
                    context.Units.Add(newSite);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    message = "Oops, something went wrong. Check " + e.Message;
                }
                return(message);
            } //end of using var context
        }     // end of Addsite
Пример #6
0
        public List <UnitsPOCO> GetActiveUnitList(int site_id)
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    var unitList = from y in context.Units
                                   where y.site_id == site_id &&
                                   y.archived_yn == false &&
                                   !y.unit_number.Contains("Not Applicable")
                                   orderby y.unit_number ascending
                                   select new UnitsPOCO()
                    {
                        unitID       = y.unit_id,
                        unitNumber   = y.unit_number,
                        siteID       = y.site_id,
                        dateModified = y.date_modified,
                        username     = y.AdministratorAccount.username
                    };

                    return(unitList.ToList());
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        } // end of GetActiveUnitList
Пример #7
0
        public List <MealPOCO> GetArchivedMealList()
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    var mealList = from x in context.Meals
                                   where x.archived_yn
                                   orderby x.meal_name ascending
                                   select new MealPOCO()
                    {
                        mealID   = x.meal_id,
                        mealName = x.meal_name
                        ,
                        administratorAccountId = x.administrator_account_id,
                        username     = x.AdministratorAccount.username,
                        dateModified = x.date_modified,
                        archivedYn   = x.archived_yn
                    };

                    return(mealList.ToList());
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
Пример #8
0
        public List <AgeRangePOCO> GetArchivedAgeRangeList()
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    var ageList = from x in context.AgeRanges
                                  where x.archived_yn && !x.age_range_description.Contains("Prefer not to Answer")
                                  orderby x.age_range_description ascending
                                  select new AgeRangePOCO()
                    {
                        ageRangeID          = x.age_range_id,
                        ageRangeDescription = x.age_range_description
                        ,
                        administratorAccountId = x.administrator_account_id,
                        username     = x.AdministratorAccount.username,
                        dateModified = x.date_modified,
                        archivedYn   = x.archived_yn
                    };

                    return(ageList.ToList());
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
        public List <PotentialSurveyWordPOCO> GetArchivedSurveyWord()
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    // gets a list of survey word IDs, survey words, the date modified and the username from the potential survey words table where the survey word is archived
                    var potentialSurveyWordList = from x in context.PotentialSurveyWords
                                                  orderby x.survey_access_word
                                                  where x.archived_yn == true
                                                  select new PotentialSurveyWordPOCO()
                    {
                        surveyWordID = x.survey_word_id,
                        surveyWord   = x.survey_access_word,
                        dateModified = x.date_modified,
                        username     = x.AdministratorAccount.username
                    };

                    return(potentialSurveyWordList.ToList());
                }
                catch (Exception e) // if anything goes wrong with retieving the survey words to a list, display an user-friendly error message
                {
                    throw new Exception("Please contact the Administrator with the error message: " + e.Message);
                }
            }
        }
Пример #10
0
        public void UpdateQuestionsText(int questionid, string text)
        {
            using (var context = new FSOSSContext())
            {
                Regex validResponse = new Regex("^[a-zA-Z ?.'/]+$");

                if (text.Length.Equals(0)) // if no question entered into field, display an error
                {
                    throw new Exception("Question text field can't be empty");
                }
                else if (text.Length > 100) // if question is not the correct length (100 characters or less), display an error
                {
                    throw new Exception("Question must be 100 characters or less");
                }
                else if (!validResponse.IsMatch(text)) // if the response entered is not valid (numbers and special characters are entered), display an error
                {
                    throw new Exception("Please enter words with no numbers or special characters.");
                }
                var result = (from x in context.Questions
                              where x.question_id == questionid
                              select x).FirstOrDefault();

                result.question_text = text;

                context.SaveChanges();
            }
        }
Пример #11
0
        public List <SitePOCO> GetArchived()
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    var archived = from x in context.Sites
                                   where x.archived_yn == true
                                   orderby x.site_name ascending
                                   select new SitePOCO()
                    {
                        siteID                   = x.site_id,
                        siteName                 = x.site_name,
                        dateModified             = x.date_modified,
                        username                 = x.AdministratorAccount.username,
                        administrator_account_id = x.administrator_account_id,
                        archived_yn              = x.archived_yn
                    };

                    return(archived.ToList());
                }
                catch (Exception e)
                {
                    throw new Exception("Something went wrong. " + e.Message);
                }
            }
        }
Пример #12
0
 public SubmittedSurveyPOCO GetSubmittedSurvey(int subSurveyID)
 {
     using (var context = new FSOSSContext())
     {
         try
         {
             var survey = from x in context.SubmittedSurveys
                          where x.submitted_survey_id == subSurveyID
                          select new SubmittedSurveyPOCO
             {
                 submittedSurveyID = x.submitted_survey_id,
                 site               = x.Unit.Site.site_name,
                 unitNumber         = x.Unit.unit_number,
                 mealName           = x.Meal.meal_name,
                 participantType    = x.ParticipantType.participant_description,
                 ageRange           = x.AgeRange.age_range_description,
                 gender             = x.Gender.gender_description,
                 dateEntered        = x.date_entered,
                 contactRequest     = x.contact_request,
                 contacted          = x.contacted,
                 contactRoomNumber  = x.contact_room_number,
                 contactPhoneNumber = x.contact_phone_number
             };
             return(survey.FirstOrDefault());
         }
         catch (Exception e)
         {
             throw new Exception("Please contact the Administrator with the error message: " + e.Message);
         }
     }
 }
Пример #13
0
        public string UpdateQuestionResponses(int questionid, int ResponseId, string text, string value, string strQuestion)
        {
            string message = "";

            using (var context = new FSOSSContext())
            {
                Regex validResponse = new Regex("^[a-zA-Z ?.'/]+$");

                if (text.Length.Equals(0)) //if no response is entered, display an error
                {
                    throw new Exception("Edit field can't be empty");
                }
                else if (text.Length > 100) //if response is not the correct length (100 characters or less), display an error
                {
                    throw new Exception("Response must be 100 characters or less");
                }
                else if (!validResponse.IsMatch(text)) //if the response entered is not valid (special characters or numbers entered), display an error
                {
                    throw new Exception("Please enter words with no numbers or special characters.");
                }
                //select a question selection (response) where question_id = questionid and question_selection_id = responseid
                var result = (from x in context.QuestionSelections
                              where x.question_id == questionid && x.question_selection_id == ResponseId
                              select x).FirstOrDefault();

                //new response text and value is assigned
                result.question_selection_text  = text;
                result.question_selection_value = text;

                context.SaveChanges();

                return(message = "Successfully updated response for " + strQuestion);
            }
        }
Пример #14
0
        /// <summary>
        /// Method use to manually generate random survey word of the day for the selected Site.
        /// Perform validation and checks to ensure that the surveyword of the day doesn't repeat.
        /// </summary>
        /// <param name="siteId"></param>
        public void ManuallyGeneratedSurveyWord(int siteId)
        {
            using (var context = new FSOSSContext())
            {
                // Get the assigned word for the selected Site for the current day
                SurveyWord wordToRemove = (from x in context.SurveyWords
                                           where x.date_used.Day == DateTime.Now.Day && x.site_id == siteId
                                           select x).FirstOrDefault();

                // If there is already an assigned word to the selected Site
                if (wordToRemove != null)
                {
                    // Remove the existing word
                    context.SurveyWords.Remove(wordToRemove);
                    context.SaveChanges();
                }


                //Create an instance of Random Object
                Random random = new Random();
                //Create a variable to hold the potential survey word to be used
                PotentialSurveyWord surveyWordToAdd = null;
                //Get the list of potential survey word which is currently active
                List <PotentialSurveyWord> potentialSurveyWordList = (from x in context.PotentialSurveyWords
                                                                      where x.archived_yn == false
                                                                      select x).ToList();
                //Boolean use to check if the word exists;
                bool wordIsUsed = true;
                //Loop that will run until a random word is choosen that doesn't exists on the current Survey Word Table
                do
                {
                    // Get a fresh list of survey words
                    List <SurveyWord> newSurveyWordList = (from x in context.SurveyWords
                                                           select x).ToList();
                    //Generate Random Number
                    int randomIndex = random.Next(0, potentialSurveyWordList.Count());
                    //Get the PotentialSurveyWord to be added based on the index
                    surveyWordToAdd = potentialSurveyWordList.ElementAt(randomIndex);
                    //Loop through the List of current SurveyWord and check if the word has been used by the current site.
                    wordIsUsed = newSurveyWordList.Any(word => word.survey_word_id == surveyWordToAdd.survey_word_id);
                    //If the Word doesn't exists after the loop on Survey Word List. Exit on the loop else start the process all over again.
                } while (wordIsUsed == true);
                //Add SurveyWord after the validation
                SurveyWord newSurveyWord = new SurveyWord()
                {
                    date_used      = DateTime.Now,
                    site_id        = siteId,
                    survey_word_id = surveyWordToAdd.survey_word_id
                };
                // Load newSurveyWord to be saved
                context.SurveyWords.Add(newSurveyWord);
                // Save the new added Survey Word
                context.SaveChanges();
                // clear the survey word
                newSurveyWord = null;
            }
        }
Пример #15
0
 /// <summary>
 /// Method is used to validate access word
 /// </summary>
 /// <param name="enteredWord"></param>
 /// <returns>Returns a boolean value that denotes if the word is in use for the current day</returns>
 public bool ValidateAccessWord(string enteredWord)
 {
     // Start of Transaction
     using (var context = new FSOSSContext())
     {
         // Return true if entered word exists and is in use for the current day; else return false
         return(context.SurveyWords.Any(x => x.PotentialSurveyWord.survey_access_word.Equals(enteredWord) && x.date_used.Day == DateTime.Now.Day));
     }
 }
Пример #16
0
        public string AddAgeRange(string ageRangeDescription, int admin)
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    if (admin == 0)
                    {
                        throw new Exception("Can't let you do that. You're not logged in.");
                    }
                    if (ageRangeDescription == "" || ageRangeDescription == null)
                    {
                        throw new Exception("Please enter an Age Range Description");
                    }
                    //add check for pre-use
                    var ageList = from x in context.AgeRanges
                                  where x.age_range_description.ToLower().Equals(ageRangeDescription.ToLower()) && !x.archived_yn
                                  select new AgeRangePOCO()
                    {
                        ageRangeDescription = x.age_range_description
                    };


                    var GoneageList = from x in context.AgeRanges
                                      where x.age_range_description.ToLower().Equals(ageRangeDescription.ToLower()) && x.archived_yn
                                      select new AgeRangePOCO()
                    {
                        ageRangeDescription = x.age_range_description
                    };
                    if (ageList.Count() > 0) //if so, return an error message
                    {
                        throw new Exception("The age range \"" + ageRangeDescription.ToLower() + "\" already exists. Please enter a new age range.");
                    }
                    else if (GoneageList.Count() > 0) //if so, return an error message
                    {
                        throw new Exception("The age range \"" + ageRangeDescription.ToLower() + "\" already exists and is Archived. Please enter a new age range.");
                    }

                    else
                    {
                        AgeRange age = new AgeRange();
                        age.age_range_description    = ageRangeDescription;
                        age.administrator_account_id = admin;
                        age.date_modified            = DateTime.Now;
                        age.archived_yn = false;
                        context.AgeRanges.Add(age);
                        context.SaveChanges();
                        return("Age Range " + ageRangeDescription + " added.");
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
Пример #17
0
        public string AddParticipantType(string participantTypeDescription, int admin)
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    if (admin == 0)
                    {
                        throw new Exception("Can't let you do that. You're not logged in.");
                    }
                    if (participantTypeDescription == "" || participantTypeDescription == null)
                    {
                        throw new Exception("Please enter a Participant Type Description");
                    }
                    //add check for pre-use
                    var participantTypeList = from x in context.ParticipantTypes
                                              where x.participant_description.ToLower().Equals(participantTypeDescription.ToLower()) && !x.archived_yn
                                              select new ParticipantTypePOCO()
                    {
                        participantTypeDescription = x.participant_description
                    };


                    var GoneparticipantTypeList = from x in context.ParticipantTypes
                                                  where x.participant_description.ToLower().Equals(participantTypeDescription.ToLower()) && x.archived_yn
                                                  select new ParticipantTypePOCO()
                    {
                        participantTypeDescription = x.participant_description
                    };
                    if (participantTypeList.Count() > 0) //if so, return an error message
                    {
                        throw new Exception("The participant type \"" + participantTypeDescription.ToLower() + "\" already exists. Please enter a new participant type.");
                    }
                    else if (GoneparticipantTypeList.Count() > 0) //if so, return an error message
                    {
                        throw new Exception("The participant type \"" + participantTypeDescription.ToLower() + "\" already exists and is Archived. Please enter a new participant type.");
                    }

                    else
                    {
                        ParticipantType pt2 = new ParticipantType();
                        pt2.participant_description  = participantTypeDescription;
                        pt2.administrator_account_id = admin;
                        pt2.date_modified            = DateTime.Now;
                        pt2.archived_yn = false;
                        context.ParticipantTypes.Add(pt2);
                        context.SaveChanges();
                        return("Participant Type " + participantTypeDescription + " added.");
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
Пример #18
0
 public string AddGender(string genderDescriptionNew, int admin)
 {
     using (var context = new FSOSSContext())
     {
         try
         {
             //If the user was not logged in
             if (admin == 0)
             {
                 throw new Exception("Can't let you do that. You're not logged in.");
             }
             //If the user tries to enter a null or empty string, then display an error message.
             if (genderDescriptionNew == "" || genderDescriptionNew == null)
             {
                 throw new Exception("Please enter a gender.");
             }
             //Add check for pre-use by checking if the new gender already exists in the database. If it does, then display an error message.
             var genderList = from x in context.Genders
                              where x.gender_description.ToLower().Equals(genderDescriptionNew.ToLower()) && !x.archived_yn
                              select new GenderPOCO()
             {
                 genderDescription = x.gender_description
             };
             var GoneGenderList = from x in context.Genders
                                  where x.gender_description.ToLower().Equals(genderDescriptionNew.ToLower()) && x.archived_yn
                                  select new GenderPOCO()
             {
                 genderDescription = x.gender_description
             };
             if (genderList.Count() > 0)
             {
                 throw new Exception("The gender \"" + genderDescriptionNew.ToLower() + "\" already exists. Please enter a new gender.");
             }
             else if (GoneGenderList.Count() > 0)
             {
                 throw new Exception("The gender \"" + genderDescriptionNew.ToLower() + "\" already exists and is Archived. Please enter a new participant type.");
             }
             //Add the new Gender into the database
             else
             {
                 Gender gndr = new Gender();
                 gndr.gender_description       = genderDescriptionNew;
                 gndr.administrator_account_id = admin;
                 gndr.date_modified            = DateTime.Now;
                 gndr.archived_yn = false;
                 context.Genders.Add(gndr);
                 context.SaveChanges();
                 return("Gender " + genderDescriptionNew + " added.");
             }
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #19
0
        public string AddMeal(string mealName, int admin)
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    if (admin == 0)
                    {
                        throw new Exception("Can't let you do that. You're not logged in.");
                    }
                    if (mealName == "" || mealName == null)
                    {
                        throw new Exception("Please enter a Meal Name");
                    }
                    //add check for pre-use
                    var mealList = from x in context.Meals
                                   where x.meal_name.ToLower().Equals(mealName.ToLower()) && !x.archived_yn
                                   select new MealPOCO()
                    {
                        mealName = x.meal_name
                    };


                    var GonemealList = from x in context.Meals
                                       where x.meal_name.ToLower().Equals(mealName.ToLower()) && x.archived_yn
                                       select new MealPOCO()
                    {
                        mealName = x.meal_name
                    };
                    if (mealList.Count() > 0) //if so, return an error message
                    {
                        throw new Exception("The participant type \"" + mealName.ToLower() + "\" already exists. Please enter a new meal.");
                    }
                    else if (GonemealList.Count() > 0) //if so, return an error message
                    {
                        throw new Exception("The participant type \"" + mealName.ToLower() + "\" already exists and is Archived. Please enter a new meal.");
                    }

                    else
                    {
                        Meal meal = new Meal();
                        meal.meal_name = mealName;
                        meal.administrator_account_id = admin;
                        meal.date_modified            = DateTime.Now;
                        meal.archived_yn = false;
                        context.Meals.Add(meal);
                        context.SaveChanges();
                        return("Meal " + mealName + " added.");
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
Пример #20
0
 public string DisplaySiteName(int siteID)
 {
     using (var context = new FSOSSContext())
     {
         string siteName = (from x in context.Sites
                            where x.site_id == siteID
                            select x.site_name).FirstOrDefault();
         return(siteName);
     }
 }
Пример #21
0
 public string GetQuestion1D()
 {
     using (var context = new FSOSSContext())
     {
         var result = (from x in context.Questions
                       where x.question_id == 5
                       select x.question_text).FirstOrDefault();
         return(result);
     }
 }
Пример #22
0
 public string GetQuestionText(int question_id)
 {
     using (var context = new FSOSSContext())
     {
         var result = (from x in context.Questions
                       where x.question_id.Equals(question_id)
                       select x.question_text).FirstOrDefault();
         return(result);
     }
 }
Пример #23
0
        /// <summary>
        /// Method used to get a count of all survey words being used.
        /// </summary>
        /// <returns></returns>
        public int GetSurveyWordCount()
        {
            using (var context = new FSOSSContext())
            {
                var result = from x in context.SurveyWords
                             select x;

                return(result.ToList().Count());
            }
        }
Пример #24
0
        public string AddSite(string newSiteName, int admin)
        {
            using (var context = new FSOSSContext())
            {
                string message   = "";
                Regex  validWord = new Regex("^[a-zA-Z '.]+$");

                try
                {
                    //Checks to see if the newSiteName already exists in the database.
                    var siteList = from x in context.Sites
                                   where x.site_name.ToLower().Equals(newSiteName.ToLower())
                                   select new SitePOCO()
                    {
                        siteName = x.site_name
                    };
                    //If the new site name is more than 100 characters long, then display an error message.
                    if (newSiteName.Length > 100)
                    {
                        throw new Exception("The site name can only be 100 characters long.");
                    }
                    //If the newSiteName is an empty string or if the new site name is null, display an error.
                    if (newSiteName == "" || newSiteName == null)
                    {
                        throw new Exception("Please enter a site name. Field cannot be empty.");
                    }
                    //If characters not approved by the Regex (defined by validWord) are entered, then display an error message.
                    else if (!validWord.IsMatch(newSiteName))
                    {
                        throw new Exception("Please enter only alphabetical letters.");
                    }
                    //If the site already exists in the database, then display an error messsage.
                    else if (siteList.Count() > 0)
                    {
                        throw new Exception("The site \"" + newSiteName.ToLower() + "\" already exists. Please enter a new site.");
                    }
                    //If everything checks out, then proceed to add the new site name to the database.
                    else
                    {
                        Site newSite = new Site();
                        newSite.administrator_account_id = admin;
                        newSite.site_name     = newSiteName.Trim();
                        newSite.date_modified = DateTime.Now;
                        newSite.archived_yn   = false;
                        context.Sites.Add(newSite);
                        context.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
                return(message);
            } //end of using var context
        }     // end of Addsite
        public string ChangeAvailability(int surveyWordID, int adminID)
        {
            using (var context = new FSOSSContext())
            {
                string message = "";
                try
                {
                    // get the current date
                    DateTime dateTime = DateTime.Today;

                    // check if the current word is in use by matching the correct survey word ID and then checking todays day/month/year against the survey word in the database to see if it is in use today
                    var surveyWordAttachToHospital = (from x in context.SurveyWords
                                                      where x.PotentialSurveyWord.survey_word_id == surveyWordID && x.date_used.Day == dateTime.Day && x.date_used.Month == dateTime.Month && x.date_used.Year == dateTime.Year
                                                      select new SurveyWordPOCO()
                    {
                        siteID = x.site_id,
                        surveyWordID = x.survey_word_id,
                        dateUsed = x.date_used
                    }).FirstOrDefault();

                    if (surveyWordAttachToHospital == null)                                                        // if surveyWordAttachToHospital is null, it is not in use and can be disabled or enabled
                    {
                        PotentialSurveyWord potentialSurveyWord = context.PotentialSurveyWords.Find(surveyWordID); // find the survey word by matching it with the survey word ID
                        if (potentialSurveyWord.archived_yn == true)                                               // if the survey word is archived, toggle the archived boolean to false and display the success message that it has been enabled
                        {
                            potentialSurveyWord.archived_yn = false;
                            message = "Successfully enabled the survey word.";
                        }
                        else if (potentialSurveyWord.archived_yn == false) // if the survey word is active, toggle the archived boolean to true and display the success message that it has been disabled
                        {
                            potentialSurveyWord.archived_yn = true;
                            message = "Successfully disabled the survey word.";
                        }
                        // now update the survey word to either enabled or disabled, the modified date and admin ID from the admin that is logged in to the potential survey word table in the database
                        potentialSurveyWord.administrator_account_id = adminID;
                        potentialSurveyWord.date_modified            = DateTime.Now;
                        context.Entry(potentialSurveyWord).Property(y => y.administrator_account_id).IsModified = true;
                        context.Entry(potentialSurveyWord).Property(y => y.archived_yn).IsModified   = true;
                        context.Entry(potentialSurveyWord).Property(y => y.date_modified).IsModified = true;
                        context.SaveChanges();
                    }
                    else
                    {
                        throw new Exception("Unable to change availability of the selected word. Word is currently in use.");
                    }
                }
                catch (Exception e) // catch the error and display it on the page with MessageUserControl
                {
                    throw new Exception(e.Message);
                }
                return(message); // return the success message
            }
        }
Пример #26
0
 /// <summary>
 /// Method use to get the survey word text
 /// </summary>
 /// <param name="siteID">Site Id to identify what survey word to display</param>
 /// <returns>Return the survey word text</returns>
 public string GetSurveyWord(int siteID)
 {
     // Start of Transaction
     using (var context = new FSOSSContext())
     {
         string currentSurveyWord = (from x in context.SurveyWords
                                     where x.site_id == siteID && x.date_used.Day == DateTime.Now.Day
                                     orderby x.date_used descending
                                     select x.PotentialSurveyWord.survey_access_word).FirstOrDefault();
         return(currentSurveyWord);
     }
 }
        /// <summary>
        /// Method used to retrieve the Administrator Account ID
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public int GetAdministratorAccountID(string username)
        {
            using (var context = new FSOSSContext())
            {
                // Use Linq query to retrieve Administrator Account ID
                var result = (from x in context.AdministratorAccounts
                              where x.username.Equals(username.ToLower())
                              select x.administrator_account_id).FirstOrDefault();

                return(result);
            }
        }
        /// <summary>
        /// Method used to verify the Administrator Account is active prior to logging in
        /// </summary>
        /// <param name="username"></param>
        /// <returns>returns a boolean value of true or false</returns>
        public bool AdministratorAccountIsActive(string username)
        {
            using (var context = new FSOSSContext())
            {
                // Use Linq query to retrieve a count where user is active
                var result = (from x in context.AdministratorAccounts
                              where !x.archived_yn && username.Equals(x.username)
                              select x).Count();

                // Return false if the count equals 0; else return true
                return(result.Equals(0) ? false : true);
            }
        }
        public void AddWord(string newWord, int adminID)
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    Regex validWord = new Regex("^[a-zA-Z]+$");

                    // gets a list of survey words where the newWord is matching an existing word
                    var potentialSurveyWordList = from x in context.PotentialSurveyWords
                                                  where x.survey_access_word.ToLower().Equals(newWord.ToLower())
                                                  select new PotentialSurveyWordPOCO()
                    {
                        surveyWord = x.survey_access_word
                    };

                    if (potentialSurveyWordList.Count() > 0) // if a survey word was found display an error that the word already exists
                    {
                        throw new Exception("The word \"" + newWord.ToLower() + "\" already exists. Please choose another word.");
                    }
                    else
                    {
                        if (newWord == "" || newWord == null) // if no survey word was entered, display an error
                        {
                            throw new Exception("You must type in a word to add. Field cannot be empty.");
                        }
                        else if (!validWord.IsMatch(newWord)) // if the survey word entered is not valid (no special characters, spaces, or numbers), display an error
                        {
                            throw new Exception("Please enter only alphabetical letters and no spaces.");
                        }
                        else if (newWord.Length < 4 || newWord.Length > 8)  // if the survey word is not the correct length (between 4 and 8 characters), display an error
                        {
                            throw new Exception("New survey word must be between 4 to 8 characters characters in length.");
                        }
                        else // else, add the new survey word, the current date and admin ID from the admin that is logged in to the potential survey word table in the database
                        {
                            PotentialSurveyWord potentialSurveyWord = new PotentialSurveyWord();
                            potentialSurveyWord.administrator_account_id = adminID;
                            potentialSurveyWord.survey_access_word       = newWord.Trim();
                            potentialSurveyWord.date_modified            = DateTime.Now;
                            context.PotentialSurveyWords.Add(potentialSurveyWord);
                            context.SaveChanges();
                        }
                    }
                }
                catch (Exception e) // catch the error and display it on the page with MessageUserControl
                {
                    throw new Exception(e.Message);
                }
            }
        }
Пример #30
0
 public List <ResponsePOCO> GetQuestion1EReponse()
 {
     using (var context = new FSOSSContext())
     {
         var result = from x in context.QuestionSelections
                      where x.question_id == 6
                      select new ResponsePOCO
         {
             Text  = x.question_selection_text,
             Value = x.question_selection_value
         };
         return(result.ToList());
     }
 }