예제 #1
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;
            }
        }
예제 #2
0
        /// <summary>
        /// Method use to assign a new survey word if a new Site is created
        /// </summary>
        /// <param name="siteName"> Site Name of the new site created</param>
        public void NewSite_NewWord(string siteName)
        {
            // Start of Transaction
            using (var context = new FSOSSContext())
            {
                //grab the new site id,
                int siteId = (from x in context.Sites
                              where x.site_name.Equals(siteName) && x.archived_yn == false
                              select x.site_id).FirstOrDefault();

                //get all the active words
                List <PotentialSurveyWord> potentialSurveyWordList = (from x in context.PotentialSurveyWords
                                                                      where x.archived_yn == false
                                                                      select x).ToList();
                //get all the surveywords
                List <SurveyWord> surveyWordList = (from x in context.SurveyWords
                                                    select x).ToList();
                // If the count of survey words being used
                if (surveyWordList.Count >= potentialSurveyWordList.Count)
                {
                    SurveyWord wordToBeRemoved = (from x in context.SurveyWords
                                                  orderby x.date_used
                                                  select x).FirstOrDefault();
                    context.SurveyWords.Remove(wordToBeRemoved);
                    context.SaveChanges();
                }
                Random random     = new Random();
                bool   wordIsUsed = true;
                PotentialSurveyWord surveyWordToAdd = null;

                do
                {
                    List <SurveyWord> newSurveyWordList = (from x in context.SurveyWords
                                                           select x).ToList();
                    int randomIndex = random.Next(0, potentialSurveyWordList.Count());
                    surveyWordToAdd = potentialSurveyWordList.ElementAt(randomIndex);
                    wordIsUsed      = newSurveyWordList.Any(word => word.survey_word_id == surveyWordToAdd.survey_word_id);
                } while (wordIsUsed == true);

                SurveyWord newSurveyWord = new SurveyWord()
                {
                    date_used      = DateTime.Now,
                    site_id        = siteId,
                    survey_word_id = surveyWordToAdd.survey_word_id
                };
                context.SurveyWords.Add(newSurveyWord);
                context.SaveChanges();
            }
        }
예제 #3
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
예제 #4
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);
            }
        }
예제 #5
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();
            }
        }
예제 #6
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);
         }
     }
 }
예제 #7
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);
                }
            }
        }
예제 #8
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);
                }
            }
        }
예제 #9
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);
                }
            }
        }
예제 #10
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
            }
        }
        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);
                }
            }
        }
예제 #13
0
        public void ContactSurvey(int submittedSurveyID)
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    SubmittedSurvey ss = context.SubmittedSurveys.Find(submittedSurveyID);
                    ss.contacted = true;

                    context.Entry(ss).Property(y => y.contacted).IsModified = true;
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    throw new Exception("Please contact the Administrator with the error message: " + e.Message);
                }
            }
        }
예제 #14
0
        public string ArchiveGender(int genderID, int admin)
        {
            string result = "";

            using (var context = new FSOSSContext())
            {
                try
                {
                    if (admin == 0)
                    {
                        throw new Exception("Can't let you do that. You're not logged in.");
                    }

                    //If the gender is disabled, enable it; otherwise, disable the gender.
                    Gender gndr = context.Genders.Find(genderID);
                    if (gndr.archived_yn)
                    {
                        gndr.archived_yn = false;
                        result           = "enabled.";
                    }
                    else
                    {
                        gndr.archived_yn = true;
                        result           = "disabled";
                    }
                    gndr.administrator_account_id = admin;
                    gndr.date_modified            = DateTime.Now;
                    context.Entry(gndr).Property(y => y.archived_yn).IsModified = true;
                    context.Entry(gndr).Property(y => y.administrator_account_id).IsModified = true;
                    context.Entry(gndr).Property(y => y.date_modified).IsModified            = true;
                    context.SaveChanges();

                    return("Gender succesfully " + result);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
예제 #15
0
        public string SwitchUnitSatus(int unitID, int admin)
        {
            using (var context = new FSOSSContext())
            {
                string message = "";
                try
                {
                    if (admin == 0)
                    {
                        throw new Exception("Can't let you do that. You're not logged in.");
                    }
                    // Check if the unit exists

                    Unit unit = context.Units.Find(unitID);

                    if (unit.archived_yn == false)
                    {
                        unit.archived_yn = true;
                        message          = "disabled.";
                    }
                    else
                    {
                        unit.archived_yn = false;
                        message          = "enabled";
                    }
                    unit.administrator_account_id = admin;
                    unit.date_modified            = DateTime.Now;
                    context.Entry(unit).Property(y => y.archived_yn).IsModified = true;
                    context.Entry(unit).Property(y => y.administrator_account_id).IsModified = true;
                    context.Entry(unit).Property(y => y.date_modified).IsModified            = true;
                    context.SaveChanges();

                    return("Unit successfully " + message);
                }
                catch (Exception e)
                {
                    throw new Exception("Something went wrong. See " + e.Message);
                }
            }
        } //end of SwitchUnitSatus(disbaling/enabling) unit
예제 #16
0
        public string ArchiveParticipantType(int participantTypeID, int admin)
        {
            string result = "";

            using (var context = new FSOSSContext())
            {
                try
                {
                    if (admin == 0)
                    {
                        throw new Exception("Can't let you do that. You're not logged in.");
                    }

                    //throw new Exception("tried to delete ptid="+ participantTypeID);
                    ParticipantType pt2 = context.ParticipantTypes.Find(participantTypeID);
                    if (pt2.archived_yn)
                    {
                        pt2.archived_yn = false;
                        result          = "enabled.";
                    }
                    else
                    {
                        pt2.archived_yn = true;
                        result          = "disabled";
                    }
                    pt2.administrator_account_id = admin;
                    pt2.date_modified            = DateTime.Now;
                    context.Entry(pt2).Property(y => y.archived_yn).IsModified = true;
                    context.Entry(pt2).Property(y => y.administrator_account_id).IsModified = true;
                    context.Entry(pt2).Property(y => y.date_modified).IsModified            = true;
                    context.SaveChanges();

                    return("Participant Type succesfully " + result);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
예제 #17
0
        public string ArchiveMeal(int mealID, int admin)
        {
            string result = "";

            using (var context = new FSOSSContext())
            {
                try
                {
                    if (admin == 0)
                    {
                        throw new Exception("Can't let you do that. You're not logged in.");
                    }

                    Meal meal = context.Meals.Find(mealID);
                    if (meal.archived_yn)
                    {
                        meal.archived_yn = false;
                        result           = "enabled.";
                    }
                    else
                    {
                        meal.archived_yn = true;
                        result           = "disabled";
                    }
                    meal.administrator_account_id = admin;
                    meal.date_modified            = DateTime.Now;
                    context.Entry(meal).Property(y => y.archived_yn).IsModified = true;
                    context.Entry(meal).Property(y => y.administrator_account_id).IsModified = true;
                    context.Entry(meal).Property(y => y.date_modified).IsModified            = true;
                    context.SaveChanges();

                    return("Meal succesfully " + result);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
예제 #18
0
        public string UpdateParticipantType(int participantTypeID, 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 duplicate check
                    var participantTypeList = from x in context.ParticipantTypes
                                              where x.participant_description.ToLower().Equals(participantTypeDescription.ToLower()) &&
                                              x.participant_type_id != participantTypeID &&
                                              !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.participant_type_id != participantTypeID &&
                                                  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 = context.ParticipantTypes.Find(participantTypeID);
                        pt2.participant_description  = participantTypeDescription;
                        pt2.date_modified            = DateTime.Now;
                        pt2.administrator_account_id = admin;

                        context.Entry(pt2).Property(y => y.participant_description).IsModified  = true;
                        context.Entry(pt2).Property(y => y.date_modified).IsModified            = true;
                        context.Entry(pt2).Property(y => y.administrator_account_id).IsModified = true;

                        context.SaveChanges();

                        return("Participant Type successfully updated.");
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
예제 #19
0
        public string UpdateParticipantType(int mealID, 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 duplicate check
                    var mealList = from x in context.Meals
                                   where x.meal_name.ToLower().Equals(mealName.ToLower()) &&
                                   x.meal_id != mealID && !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.meal_id != mealID && x.archived_yn
                                       select new MealPOCO()
                    {
                        mealName = x.meal_name
                    };
                    if (mealList.Count() > 0) //if so, return an error message
                    {
                        throw new Exception("The meal \"" + mealName.ToLower() + "\" already exists. Please enter a new meal.");
                    }
                    else if (GoneMealList.Count() > 0) //if so, return an error message
                    {
                        throw new Exception("The meal \"" + mealName.ToLower() + "\" already exists and is Archived. Please enter a new meal.");
                    }

                    else
                    {
                        Meal meal = context.Meals.Find(mealID);
                        meal.meal_name                = mealName;
                        meal.date_modified            = DateTime.Now;
                        meal.administrator_account_id = admin;

                        context.Entry(meal).Property(y => y.meal_name).IsModified                = true;
                        context.Entry(meal).Property(y => y.date_modified).IsModified            = true;
                        context.Entry(meal).Property(y => y.administrator_account_id).IsModified = true;

                        context.SaveChanges();

                        return("Meal successfully updated.");
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
예제 #20
0
        public string UpdateUnit(int unitID, string unitNumber, int admin)
        {
            using (var context = new FSOSSContext())
            {
                Regex  validUnit = new Regex("^[0-9]{1,3}[a-zA-Z/s]{1,47}|[a-zA-Z/s]{1,50}$");
                string message   = "";

                try
                {
                    if (admin == 0) //check to see if admin is logged in
                    {
                        throw new Exception("Can't let you do that. You're not logged in.");
                    }
                    if (unitNumber == "" || unitNumber == null) // check to see if unit number text box is empty
                    {
                        throw new Exception("Please enter a Unit Number");
                    }

                    if (unitNumber.Length < 2 || unitNumber.Length > 50) // check to see the minimum and maximum length of inserted characters.
                    {
                        throw new Exception("Input must be between 2 charaters to 50 chatecters long.");
                    }

                    if (!validUnit.IsMatch(unitNumber))// check to see if the updated number is entered is consistent with the valid pattern set.
                    {
                        throw new Exception("Invalid input pattern. Correct pattern (up to 3 digits followed by upto 47 alphabets) OR (up to 50 alphabets long only)without special characters.");
                    }



                    //check active units
                    var unitExist = from x in context.Units
                                    where x.unit_number.ToUpper() == unitNumber.ToUpper() &&
                                    x.archived_yn == false
                                    select new UnitsPOCO()
                    {
                        unitNumber = x.unit_number,
                    };
                    //check Archived units
                    var unitExistsInArchived = from x in context.Units
                                               where x.unit_number.ToUpper() == unitNumber.ToUpper() &&
                                               x.archived_yn == true
                                               select new UnitsPOCO()
                    {
                        unitNumber = x.unit_number,
                    };
                    if (unitExist.Count() > 0) //if new unit exists in active so, return an error message
                    {
                        throw new Exception("The unit \"" + unitNumber.ToUpper() + "\" already exists. Please enter a new Unit.");
                    }

                    if (unitExistsInArchived.Count() > 0)//if new unit exists in archived so, return an error message

                    {
                        throw new Exception("The unit \"" + unitNumber.ToUpper() + "\" exists in archived. Check in archived in order to activate unit. ");
                    }


                    else
                    {
                        Unit unitToUpdate = context.Units.Find(unitID);
                        unitToUpdate.administrator_account_id = admin;
                        unitToUpdate.unit_number          = unitNumber;
                        unitToUpdate.date_modified        = DateTime.Now;
                        context.Entry(unitToUpdate).State = EntityState.Modified;

                        context.SaveChanges();
                        message = " Unit " + unitNumber + " updated.";
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
                return(message);
            }
        }//end of update Unit
예제 #21
0
        /// <summary>
        /// Method use to generate random survey word of the day from the list of potential survey words.
        /// Perform validation and checks to ensure that the surveyword of the day doesn't repeat.
        /// Remove few old survey words once all the words are being used.
        /// </summary>
        public void GenerateSurveyWordOfTheDay()
        {
            // Start of Transaction
            using (var context = new FSOSSContext())
            {
                //Get the list of survey word in the database
                List <SurveyWord> surveyWordList = (from x in context.SurveyWords
                                                    select x).ToList();
                //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();
                //Get the list of all site to be added
                List <Site> siteList = (from x in context.Sites
                                        select x).ToList();
                // Check if theres enough active Potential Survey Word on the list
                if (siteList.Count > potentialSurveyWordList.Count())
                {
                    // Throw an exception if there are not enough survey word on the pool to be use on the list
                    throw new Exception("Please add more potential survey word. Not enough potential survey word available to be assign on the hospitals.");
                }
                else
                {
                    //Check if all potential survey word is used
                    if (surveyWordList.Count >= potentialSurveyWordList.Count)
                    {
                        List <SurveyWord> newSurveyListForCheck = null;
                        do
                        {
                            // Get the fresh list of survey words
                            newSurveyListForCheck = (from x in context.SurveyWords
                                                     select x).ToList();

                            //Get the last Survey Word by date
                            SurveyWord surveyWord = (from x in context.SurveyWords
                                                     orderby x.date_used
                                                     select x).FirstOrDefault();
                            //Remove the last Survey Word
                            context.SurveyWords.Remove(surveyWord);
                            context.SaveChanges();
                            surveyWord = null;

                            //Check if the there are enough Potential Survey word available from the List in the database to be used for all the hospital
                            //Repeat the step above until theres enough potentail word to lookupon
                        } while (newSurveyListForCheck.Count() < potentialSurveyWordList.Count() - siteList.Count());
                    }
                    //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;
                    foreach (Site site in siteList)
                    {
                        //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        = site.site_id,
                            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;
                    }
                }
                // Initialze current Date and Time
                DateTime currentDateTime = DateTime.Now;
                // Set timeOffset to be use to setup date and time for the next scheduled job.
                // Current setup will be set to fire at 12:00 midnight after one day
                DateTime timeOffset = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day + 1, 0, 0, 0);
                // Setup new job schedule that will fire GenerateSurveyWordOfTheDay after the given offset
                BackgroundJob.Schedule(() => GenerateSurveyWordOfTheDay(), timeOffset);
            }
        }
예제 #22
0
        public string UpdateSite(int siteID, string siteName, int admin)
        {
            using (var context = new FSOSSContext())
            {
                Regex  valid   = new Regex("^[a-zA-Z '.]+$");
                string message = "";
                try
                {
                    //If this new site name is an empty string or null, then display an error message.
                    if (siteName == "" || siteName == null)
                    {
                        throw new Exception("Please enter a site name. Field cannot be empty.");
                    }
                    //If the new site name is more than 100 characters long, then display an error message.
                    if (siteName.Length > 100)
                    {
                        throw new Exception("The site name can only be 100 characters long.");
                    }
                    //Check if the name already exists in the database.
                    var siteList = from x in context.Sites
                                   where x.site_name.ToLower().Equals(siteName.ToLower()) &&
                                   !x.archived_yn
                                   select new SitePOCO()
                    {
                        siteName = x.site_name
                    };
                    var GoneSiteList = from x in context.Sites
                                       where x.site_name.ToLower().Equals(siteName.ToLower()) &&
                                       x.archived_yn
                                       select new SitePOCO()
                    {
                        siteName = x.site_name
                    };
                    if (siteList.Count() > 0) //if so, return an error message
                    {
                        throw new Exception("The site \"" + siteName.ToLower() + "\" already exists. Please enter a new site.");
                    }
                    else if (GoneSiteList.Count() > 0) //if so, return an error message
                    {
                        throw new Exception("The site \"" + siteName.ToLower() + "\" already exists and is Archived. Please enter a new site.");
                    }
                    //Select all the information about a site, where the siteID matches the siteID passed in from the POCO.
                    var exists = (from x in context.Sites
                                  where x.site_id == siteID
                                  select x);
                    //If exists does not return anything, throw an exception.
                    if (exists == null)
                    {
                        throw new Exception("This site does not exist.");
                    }
                    //If characters not approved by the Regex (defined by valid) are entered, then display an error message.
                    if (!(valid.IsMatch(siteName)))
                    {
                        throw new Exception("Please enter only alphabetical letters.");
                    }
                    else
                    {
                        Site updateSite = context.Sites.Find(siteID);
                        updateSite.site_name                = siteName.Trim();
                        updateSite.date_modified            = DateTime.Now;
                        updateSite.administrator_account_id = admin;

                        context.Entry(updateSite).State = EntityState.Modified;
                        context.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
                return(message);
            } //context
        }     //update site
예제 #23
0
        public string UpdateGender(int genderID, string genderDescription, 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 the gender description is an empty string or is null, then display an error message.
                    if (genderDescription == "" || genderDescription == null)
                    {
                        throw new Exception("Please enter a Participant Type Description");
                    }
                    //Check for duplicates
                    var genderList = from x in context.Genders
                                     where x.gender_description.ToLower().Equals(genderDescription.ToLower()) &&
                                     x.gender_id != genderID &&
                                     !x.archived_yn
                                     select new GenderPOCO()
                    {
                        genderDescription = x.gender_description
                    };


                    var GoneGenderList = from x in context.Genders
                                         where x.gender_description.ToLower().Equals(genderDescription.ToLower()) &&
                                         x.gender_id != genderID && x.archived_yn
                                         select new GenderPOCO()
                    {
                        genderDescription = x.gender_description
                    };
                    if (genderList.Count() > 0) //If duplicates exist, return an error message.
                    {
                        throw new Exception("The participant type \"" + genderDescription.ToLower() + "\" already exists. Please enter a new participant type.");
                    }
                    else if (GoneGenderList.Count() > 0) //If duplicates exist, return an error message.
                    {
                        throw new Exception("The participant type \"" + genderDescription.ToLower() + "\" already exists and is Archived. Please enter a new  gender.");
                    }
                    //Update the gender description, date modified, and administrator account id
                    else
                    {
                        Gender gndr = context.Genders.Find(genderID);
                        gndr.gender_description       = genderDescription;
                        gndr.date_modified            = DateTime.Now;
                        gndr.administrator_account_id = admin;

                        context.Entry(gndr).Property(y => y.gender_description).IsModified       = true;
                        context.Entry(gndr).Property(y => y.date_modified).IsModified            = true;
                        context.Entry(gndr).Property(y => y.administrator_account_id).IsModified = true;

                        context.SaveChanges();

                        return("Gender successfully updated.");
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
예제 #24
0
        public string ArchiveSite(int siteID, int admin)
        {
            using (var context = new FSOSSContext())
            {
                try
                {
                    //If the admin is 0, then display an error message.
                    if (admin == 0)
                    {
                        throw new Exception("Can't let you do that. You're not logged in.");
                    }

                    // Check if the site exists
                    var searchSite = (from x in context.Sites
                                      where x.site_id == siteID
                                      select new SitePOCO()
                    {
                        siteID = x.site_id,
                        siteName = x.site_name,
                        archived_yn = x.archived_yn,
                        dateModified = DateTime.Now
                    }).FirstOrDefault();
                    //Select all the active sites
                    List <Site> lastSite = (from x in context.Sites
                                            where x.archived_yn == false
                                            select x).ToList();
                    if (searchSite == null)
                    {
                        throw new Exception("This site does not exist.");
                    }

                    //If the site is archived, activate it and update the date modified. If the site is not archived, archive it and update the date modified.
                    Site site = context.Sites.Find(siteID);
                    if (site.archived_yn == false)
                    {
                        //If the admin is attempting to disable the last active site in the system, throw an error.
                        if (lastSite.Count() == 1)
                        {
                            throw new Exception("Cannot disable site. There needs to be at least one active site.");
                        }
                        else
                        {
                            site.archived_yn   = true;
                            site.date_modified = DateTime.Now;
                        }
                    }
                    else
                    {
                        site.archived_yn   = false;
                        site.date_modified = DateTime.Now;
                    };
                    context.Entry(site).State = EntityState.Modified;
                    context.SaveChanges();
                    return("Site successfully updated.");
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
        public string UpdateWord(string surveyWord, int surveyWordID, int adminID)
        {
            using (var context = new FSOSSContext())
            {
                string message = "";
                try
                {
                    surveyWord = surveyWord.ToLower().Trim(); // trim the spaces and covert the updated survey word to lowercase
                    Regex validWord = new Regex("^[a-zA-Z]+$");

                    // gets a list of survey words where the surveyWord is matching an existing word
                    var potentialSurveyWordList = from x in context.PotentialSurveyWords
                                                  where x.survey_access_word.ToLower().Equals(surveyWord)
                                                  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 \"" + surveyWord + "\" already exists. Please update to a different word.");
                    }
                    else
                    {
                        if (surveyWord == "" || surveyWord == null) // if no survey word was entered, display an error
                        {
                            throw new Exception("Edit field cannot be blank. You must enter a word between 4 to 8 characters in length.");
                        }
                        else if (!validWord.IsMatch(surveyWord)) // 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 (surveyWord.Length < 4 || surveyWord.Length > 8) // if the survey word is not the correct length (between 4 and 8 characters), display an error
                        {
                            throw new Exception("Updated survey word must be between 4 to 8 characters in length.");
                        }
                        else
                        {
                            bool inUse = false;

                            // gets a list of survey word IDs and the date that the words are in use
                            var surveyWordList = (from x in context.SurveyWords
                                                  select new SurveyWordPOCO
                            {
                                dateUsed = x.date_used,
                                surveyWordID = x.survey_word_id
                            }).ToList();


                            foreach (SurveyWordPOCO item in surveyWordList) // loop through the survey word list and match the survey word ID and the date used to todays date
                            {
                                if (item.surveyWordID == surveyWordID && item.dateUsed.Day == DateTime.Today.Day)
                                {
                                    inUse = true; // toggle inUse to true if the survey word is in use today
                                    break;
                                }
                            }

                            if (validWord.IsMatch(surveyWord) && inUse == false) // if the survey word is not in use today, then update the survey word, the modified date and user ID from the user that is logged in to the potential survey word table in the database
                            {
                                var wordToUpdate = context.PotentialSurveyWords.Find(surveyWordID);
                                wordToUpdate.administrator_account_id = adminID;
                                wordToUpdate.survey_access_word       = surveyWord.Trim();
                                wordToUpdate.date_modified            = DateTime.Now;
                                context.Entry(wordToUpdate).Property(y => y.administrator_account_id).IsModified = true;
                                context.Entry(wordToUpdate).Property(y => y.survey_access_word).IsModified       = true;
                                context.Entry(wordToUpdate).Property(y => y.date_modified).IsModified            = true;
                                context.SaveChanges();

                                message = "The survey word has been updated to \"" + surveyWord + "\"."; // update message to display a success message
                            }
                            else
                            {
                                throw new Exception("Unable to update 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>
        /// This is the method used when submitting a survey into the database in both the SubmittedSurvey and ParticipantResponse tables
        /// </summary>
        /// <param name="survey_version_id_param"></param>
        /// <param name="unit_id_param"></param>
        /// <param name="meal_id_param"></param>
        /// <param name="participant_type_id_param"></param>
        /// <param name="age_range_id_param"></param>
        /// <param name="gender_id_param"></param>
        /// <param name="contact_request_param"></param>
        /// <param name="contact_room_number_param"></param>
        /// <param name="contact_phone_number_param"></param>
        /// <param name="Q1AResponse_param"></param>
        /// <param name="Q1BResponse_param"></param>
        /// <param name="Q1CResponse_param"></param>
        /// <param name="Q1DResponse_param"></param>
        /// <param name="Q1EResponse_param"></param>
        /// <param name="Q2Response_param"></param>
        /// <param name="Q3Response_param"></param>
        /// <param name="Q4Response_param"></param>
        /// <param name="Q5Response_param"></param>
        public void SubmitSurvey(int survey_version_id_param, int unit_id_param, int meal_id_param, int participant_type_id_param, int age_range_id_param,
                                 int gender_id_param, bool contact_request_param, string contact_room_number_param, string contact_phone_number_param, string Q1AResponse_param,
                                 string Q1BResponse_param, string Q1CResponse_param, string Q1DResponse_param, string Q1EResponse_param, string Q2Response_param, string Q3Response_param,
                                 string Q4Response_param, string Q5Response_param)
        {
            using (var context = new FSOSSContext())
            {
                SubmittedSurvey newSurvey = new SubmittedSurvey();
                newSurvey.survey_version_id    = survey_version_id_param;
                newSurvey.date_entered         = DateTime.Now;
                newSurvey.unit_id              = unit_id_param;
                newSurvey.meal_id              = meal_id_param;
                newSurvey.participant_type_id  = participant_type_id_param;
                newSurvey.age_range_id         = age_range_id_param;
                newSurvey.gender_id            = gender_id_param;
                newSurvey.contact_request      = contact_request_param;
                newSurvey.contact_room_number  = contact_room_number_param;
                newSurvey.contact_phone_number = contact_phone_number_param;
                context.SubmittedSurveys.Add(newSurvey);
                context.SaveChanges();

                var newSurveyId = (from x in context.SubmittedSurveys
                                   select x.submitted_survey_id).Max();

                ParticipantResponse q1AResponse = new ParticipantResponse();
                q1AResponse.submitted_survey_id = newSurveyId;
                q1AResponse.question_id         = 2;
                q1AResponse.participant_answer  = Q1AResponse_param;
                context.ParticipantResponses.Add(q1AResponse);
                context.SaveChanges();

                ParticipantResponse q1BResponse = new ParticipantResponse();
                q1BResponse.submitted_survey_id = newSurveyId;
                q1BResponse.question_id         = 3;
                q1BResponse.participant_answer  = Q1BResponse_param;
                context.ParticipantResponses.Add(q1BResponse);
                context.SaveChanges();

                ParticipantResponse q1CResponse = new ParticipantResponse();
                q1CResponse.submitted_survey_id = newSurveyId;
                q1CResponse.question_id         = 4;
                q1CResponse.participant_answer  = Q1CResponse_param;
                context.ParticipantResponses.Add(q1CResponse);
                context.SaveChanges();

                ParticipantResponse q1DResponse = new ParticipantResponse();
                q1DResponse.submitted_survey_id = newSurveyId;
                q1DResponse.question_id         = 5;
                q1DResponse.participant_answer  = Q1DResponse_param;
                context.ParticipantResponses.Add(q1DResponse);
                context.SaveChanges();

                ParticipantResponse q1EResponse = new ParticipantResponse();
                q1EResponse.submitted_survey_id = newSurveyId;
                q1EResponse.question_id         = 6;
                q1EResponse.participant_answer  = Q1EResponse_param;
                context.ParticipantResponses.Add(q1EResponse);
                context.SaveChanges();

                ParticipantResponse q2Response = new ParticipantResponse();
                q2Response.submitted_survey_id = newSurveyId;
                q2Response.question_id         = 8;
                q2Response.participant_answer  = Q2Response_param;
                context.ParticipantResponses.Add(q2Response);
                context.SaveChanges();

                ParticipantResponse q3Response = new ParticipantResponse();
                q3Response.submitted_survey_id = newSurveyId;
                q3Response.question_id         = 9;
                q3Response.participant_answer  = Q3Response_param;
                context.ParticipantResponses.Add(q3Response);
                context.SaveChanges();

                ParticipantResponse q4Response = new ParticipantResponse();
                q4Response.submitted_survey_id = newSurveyId;
                q4Response.question_id         = 10;
                q4Response.participant_answer  = Q4Response_param;
                context.ParticipantResponses.Add(q4Response);
                context.SaveChanges();

                ParticipantResponse q5Response = new ParticipantResponse();
                q5Response.submitted_survey_id = newSurveyId;
                q5Response.question_id         = 11;
                q5Response.participant_answer  = Q5Response_param;
                context.ParticipantResponses.Add(q5Response);
                context.SaveChanges();
            }
        }
예제 #27
0
        public string UpdateAgeRange(int ageRangeID, 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 duplicate check
                    var ageList = from x in context.AgeRanges
                                  where x.age_range_description.ToLower().Equals(ageRangeDescription.ToLower()) &&
                                  x.age_range_id != ageRangeID && !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.age_range_id != ageRangeID && 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 = context.AgeRanges.Find(ageRangeID);
                        age.age_range_description    = ageRangeDescription;
                        age.date_modified            = DateTime.Now;
                        age.administrator_account_id = admin;

                        context.Entry(age).Property(y => y.age_range_description).IsModified    = true;
                        context.Entry(age).Property(y => y.date_modified).IsModified            = true;
                        context.Entry(age).Property(y => y.administrator_account_id).IsModified = true;

                        context.SaveChanges();

                        return("Age Range successfully updated.");
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }