예제 #1
0
        public void SubQuestion_Update(int questionId, string subQuestionText)
        {
            using (MSSContext context = new MSSContext())
            {
                var question = (from x in context.Questions
                                where x.QuestionId == questionId
                                select x).FirstOrDefault();

                // If the user makes no changes, show error message.
                if (question.SubQuestionText == subQuestionText)
                {
                    throw new Exception("No changes were made to the subquestion text before the \"Update\" button was clicked.");
                }
                //else, do the following actions:
                else
                {
                    //capture the new subquestion text that has been entered by the user
                    question.SubQuestionText = subQuestionText;

                    //save the changes to the database
                    context.Entry(question).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }
예제 #2
0
        public void Answer_Update(string description, int answerId)
        {
            using (MSSContext context = new MSSContext())
            {
                var answer = (from x in context.Answers
                              where x.AnswerId == answerId
                              select x).FirstOrDefault();

                // If the user makes no changes, show error message.
                if (answer.Description == description)
                {
                    throw new Exception("No changes were made to the answer text before the \"Update\" button was clicked.");
                }
                //else, do the following actions:
                else
                {
                    //capture the new answer text / description that has been entered by the user
                    answer.Description = description;

                    //save the changes to the database
                    context.Entry(answer).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }
예제 #3
0
        public void UpdateUser(UserProfile userinfo)
        {
            ApplicationUser user = new ApplicationUser();

            using (MSSContext context = new MSSContext())
            {
                user = context.Users.Where(x => x.UserName == userinfo.UserName).FirstOrDefault();
                // Hashes the password and adds it to the Password hash field in the database
                if (!string.IsNullOrEmpty(userinfo.RequestedPassword))
                {
                    user.PasswordHash = PasswordHasher.HashPassword(userinfo.RequestedPassword);
                }
                user.FirstName            = userinfo.FirstName;
                user.LastName             = userinfo.LastName;
                user.Site                 = context.Sites.Find(userinfo.SiteId);
                user.Active               = userinfo.Active;
                context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                if (userinfo.UserName != "Webmaster")
                {
                    user.Roles.Clear();
                }
                context.SaveChanges();
            }
            if (userinfo.UserName != "Webmaster")
            {
                foreach (var role in userinfo.RoleMemberships)
                {
                    this.AddToRole(user.Id, role);
                }
            }
        }
예제 #4
0
        public void Site_Deactivate(int siteId)
        {
            using (MSSContext context = new MSSContext())
            {
                Site site = context.Sites.Find(siteId);
                //Prevent the admin site from being deactivated.
                if (site.SiteName == "Administrator Site")
                {
                    throw new Exception("Administrator Site name cannot be deactivated.");
                }
                // Grabs a list of units attached to the site being decativated.
                var units = (from x in context.Units
                             where x.SiteId == siteId
                             select x).ToList();

                // Instantiates the UnitController and calls its deactivate method for each unit attached to the deactivated site.
                UnitController sysmgr = new UnitController();
                foreach (var item in units)
                {
                    sysmgr.Unit_Deactivate(item.UnitId);
                }
                // Grabs the site to be deactivated and changes its Disabled field value to true then saves it to the database.

                site.Disabled             = true;
                context.Entry(site).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }
예제 #5
0
 public void Unit_Update(Unit item)
 {
     using (MSSContext context = new MSSContext())
     {
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #6
0
        public void Site_Update(int siteId, string siteName, string description, string passcode)
        {
            using (MSSContext context = new MSSContext())
            {
                // Grabs the current site object the user wishes to update.
                var site = (from x in context.Sites
                            where x.SiteId == siteId
                            select x).FirstOrDefault();

                // Grabs objects from the database, other than the above site object,
                // that match the user's newly submitted site name and passcode for uniqueness validation.
                var nameExists = (from x in context.Sites
                                  where x.SiteName.Equals(siteName) && x.SiteId != siteId && x.Disabled == false
                                  select x).FirstOrDefault();
                var codeExists = (from x in context.Sites
                                  where x.Passcode.Equals(passcode) && x.SiteId != siteId && x.Disabled == false
                                  select x).FirstOrDefault();

                //Administrator Site name must not be changed or the system will begin adding new admin sites.
                if (site.SiteName == "Administrator Site" && siteName != "Administrator Site")
                {
                    throw new Exception("Administrator Site name cannot be changed.");
                }
                // If the above "Exists" objects exist throws an error for violating the uniqueness business rule.
                if (nameExists != null && codeExists != null)
                {
                    throw new Exception("SiteName and Passcode must be unique across all active sites.");
                }
                if (nameExists != null)
                {
                    throw new Exception("SiteName must be unique across all active sites.");
                }
                if (codeExists != null)
                {
                    throw new Exception("Passcode must be unique across all active sites.");
                }
                // If the site has been disabled since the last databind throws an error.
                if (site.Disabled)
                {
                    throw new Exception("Site has been deactivated, it can no longer be changed.");
                }
                // If the user makes no changes throws and error.
                if (site.SiteName == siteName && site.Description == description && site.Passcode == passcode)
                {
                    throw new Exception("Update failed, no properties were changed.");
                }

                // Modifies the existing sites to the user's new changes and saves them to the database.
                site.SiteName             = siteName;
                site.Description          = description;
                site.Passcode             = passcode;
                context.Entry(site).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }
예제 #7
0
 public void DeactivateSurveyQuestion(surveyquestion deactivatedSurveyQuestion)
 {
     using (var context = new MSSContext())
     {
         var surveyQuestion = context.respondenttypes.Find(deactivatedSurveyQuestion.surveyquestionid);
         surveyQuestion.activeyn = false;
         var existingRespondentType = context.Entry(surveyQuestion);
         existingRespondentType.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #8
0
 public void UpdateAccessCode(AccessCodeDTO tempCode)
 {
     using (var context = new MSSContext())
     {
         var accessCode = context.accesscodes.Find(tempCode.accesscodeid);
         accessCode.accesscodeword = tempCode.accesscodeword;
         var existingCode = context.Entry(accessCode);
         existingCode.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #9
0
 public void DeactivateGender(GenderDTO deactivatedGender)
 {
     using (var context = new MSSContext())
     {
         var gender = context.agegroups.Find(deactivatedGender.genderid);
         gender.activeyn = false;
         var existingGender = context.Entry(gender);
         existingGender.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #10
0
 public void UpdateGender(GenderDTO updatedgender)
 {
     using (var context = new MSSContext())
     {
         var gender = context.genders.Find(updatedgender.genderid);
         gender.gendername = updatedgender.gendername;
         var existingGender = context.Entry(gender);
         existingGender.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #11
0
 public int Unit_Deactivate(Unit item)
 {
     using (MSSContext context = new MSSContext())
     {
         item                      = context.Units.Find(item.UnitId);
         item.Disabled             = true;
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
         return(item.UnitId);
     }
 }
예제 #12
0
 public void DeleteManagementAccount(managementaccount tempManagementAccount)
 {
     using (var context = new MSSContext())
     {
         var managementaccount = context.managementaccounts.Find(tempManagementAccount.managementaccountid);
         managementaccount.activeyn = false;
         var existingManagementAccount = context.Entry(managementaccount);
         existingManagementAccount.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #13
0
 public void DeactivateRespondentType(RespondentDTO deactivatedRespondentType)
 {
     using (var context = new MSSContext())
     {
         var respondentType = context.respondenttypes.Find(deactivatedRespondentType.respondenttypeid);
         respondentType.activeyn = false;
         var existingRespondentType = context.Entry(respondentType);
         existingRespondentType.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #14
0
 public void UpdateRespondentType(RespondentDTO updatedRespondentType)
 {
     using (var context = new MSSContext())
     {
         var respondentType = context.respondenttypes.Find(updatedRespondentType.respondenttypeid);
         respondentType.respondenttypename = updatedRespondentType.respondenttypename;
         var existingRespondenType = context.Entry(respondentType);
         existingRespondenType.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #15
0
 public void UpdateUnit(UnitDTO updatedUnit)
 {
     using (var context = new MSSContext())
     {
         var unit = context.units.Find(updatedUnit.unitid);
         unit.unitname = updatedUnit.unitname;
         var existingUnit = context.Entry(unit);
         existingUnit.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #16
0
 public void DeactivateUnit(UnitDTO deactivateUnitUnit)
 {
     using (var context = new MSSContext())
     {
         var unit = context.units.Find(deactivateUnitUnit.unitid);
         unit.activeyn = false;
         var existingUnit = context.Entry(unit);
         existingUnit.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #17
0
 /*
  * CREATED:	H. Conant		MAR 20 2018
  *
  * DeactivatePossibleAnswer()
  * This method deactivates a PossibleAnswer in the MSS databse.
  *
  * PARAMETERS:
  * PossibleAnswerDTO deactivatedPossibleAnswer - the PossibleAnswer that is to be deactivated in the database
  *
  * RETURNS:
  * void
  *
  * ODEV METHOD CALLS:
  * None
  */
 public void DeactivatePossibleAnswer(PossibleAnswerDTO deactivatedPossibleAnswer)
 {
     using (var context = new MSSContext())
     {
         var possibleAnswer = context.units.Find(deactivatedPossibleAnswer.possibleanswerid);
         possibleAnswer.activeyn = false;
         var existingPossibleAnswer = context.Entry(possibleAnswer);
         existingPossibleAnswer.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #18
0
 public void DeactivateAgeGroup(AgeGroupDTO deactivatedAgeGroup)
 {
     using (var context = new MSSContext())
     {
         var ageGroup = context.agegroups.Find(deactivatedAgeGroup.agegroupid);
         ageGroup.activeyn = false;
         var existingAgeGroup = context.Entry(ageGroup);
         existingAgeGroup.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #19
0
 public void UpdateAgeGroup(AgeGroupDTO updatedAgeGroup)
 {
     using (var context = new MSSContext())
     {
         var ageGroup = context.agegroups.Find(updatedAgeGroup.agegroupid);
         ageGroup.agegroupname = updatedAgeGroup.agegroupname;
         var existingAgeGroup = context.Entry(ageGroup);
         existingAgeGroup.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #20
0
        public void ProcessContactRequest(int surveyId)
        {
            using (var context = new MSSContext())
            {
                var aSurvey = context.surveys.Find(surveyId);
                aSurvey.contactedyn = true;

                var existingSurvey = context.Entry(aSurvey);
                existingSurvey.State = EntityState.Modified;
                context.SaveChanges();
            }
        }
예제 #21
0
 public void UpdatePossibleAnswer(PossibleAnswerDTO updatedPossibleAnswer)
 {
     using (var context = new MSSContext())
     {
         var possibleAnswer = context.possibleanswers.Find(updatedPossibleAnswer.possibleanswerid);
         possibleAnswer.possibleanswertext = updatedPossibleAnswer.possibleanswertext;
         possibleAnswer.surveyquestionid   = updatedPossibleAnswer.surveyquestionid;
         var existingPossibleAnswer = context.Entry(possibleAnswer);
         existingPossibleAnswer.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #22
0
        public void DeactivateCareSite(CareSiteDTO deactivateCareSite)
        {
            using (var context = new MSSContext())
            {
                var caresite = context.caresites.Find(deactivateCareSite.caresiteid);
                caresite.activeyn = false;

                var existingCareSite = context.Entry(caresite);
                existingCareSite.State = EntityState.Modified;
                context.SaveChanges();
            }
        }
예제 #23
0
 public void UpdateSurveyQuestion(surveyquestion updatedSurveyQuestion)
 {
     using (var context = new MSSContext())
     {
         var surveyQuestion = context.surveyquestions.Find(updatedSurveyQuestion.surveyquestionid);
         surveyQuestion.question     = updatedSurveyQuestion.question;
         surveyQuestion.questiontype = updatedSurveyQuestion.questiontype;
         var existingSurveyQuestion = context.Entry(surveyQuestion);
         existingSurveyQuestion.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #24
0
 public void UpdateManagementAccount(managementaccount updatedManagementAccount)
 {
     using (var context = new MSSContext())
     {
         var managementaccount = context.managementaccounts.Find(updatedManagementAccount.managementaccountid);
         managementaccount.userpassword         = updatedManagementAccount.userpassword;
         managementaccount.authorizationlevelid = updatedManagementAccount.authorizationlevelid;
         managementaccount.caresites            = updatedManagementAccount.caresites;
         var existingManagementAccount = context.Entry(managementaccount);
         existingManagementAccount.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #25
0
 public void UpdateCareSite(CareSiteDTO updatedCareSite)
 {
     using (var context = new MSSContext())
     {
         var caresite = context.caresites.Find(updatedCareSite.caresiteid);
         caresite.caresitename = updatedCareSite.caresitename;
         caresite.address      = updatedCareSite.address;
         caresite.city         = updatedCareSite.city;
         caresite.province     = updatedCareSite.province;
         var existingCareSite = context.Entry(caresite);
         existingCareSite.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #26
0
        /// <summary>
        /// Updates a single site in the DB with a new passcode, checks for unique
        /// </summary>
        public void Site_ChangeSinglePasscode(int siteID, string passcode)
        {
            using (MSSContext context = new MSSContext())
            {
                // Grabs the site where the passcode is being changed.
                Site site = (from x in context.Sites
                             where x.SiteId == siteID
                             select x).FirstOrDefault();

                // Changes that sites passcode to the new passcode.
                site.Passcode             = passcode;
                context.Entry(site).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }
예제 #27
0
        /// <summary>
        /// Unit_Update will update a unit in the database
        /// </summary>
        /// <param name="unitId">The UnitId of the unit you wish to update</param>
        /// <param name="siteId">The new or old SiteId</param>
        /// <param name="unitName">The new or old Unit Name</param>
        /// <param name="description">The new or old Description</param>
        public void Unit_Update(int unitId, int siteId, string unitName, string description)
        {
            using (MSSContext context = new MSSContext())
            {
                var unit = (from x in context.Units
                            where x.UnitId == unitId
                            select x).FirstOrDefault();

                // Checks to see if there is a Unit at the same site with the same name they are trying to update to.
                var sameNameAndSite = (from x in context.Units
                                       where x.UnitName == unitName && x.SiteId == siteId && x.UnitId != unitId
                                       select x).FirstOrDefault();

                // Check if the unitName is unique for the site it is located at.
                if (sameNameAndSite != null)
                {
                    throw new Exception("Units with the same Site must have unique names. Please choose a new name for the unit.");
                }

                // Ensure the site hasn't been disabled.
                if (unit.Disabled == true)
                {
                    throw new Exception("Unit has been archived. It can no longer be changed.");
                }
                // If the user makes no changes throws and error.
                if (unit.SiteId == siteId && unit.UnitName == unitName && unit.Description == description)
                {
                    throw new Exception("Update failed, no properties were changed.");
                }

                // Process the update.
                unit.SiteId               = siteId;
                unit.UnitName             = unitName;
                unit.Description          = description;
                context.Entry(unit).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }
예제 #28
0
        /// <summary>
        /// Changes the passcode at every enabled site.
        /// This method is run automatically at midngiht by HangFire.
        /// (See startup.cs in MSS.Website/App_code)
        /// </summary>
        public void Site_ChangePasscode()
        {
            string passcode;
            bool   unique = false;

            using (MSSContext context = new MSSContext())
            {
                List <Site> siteList = Site_List(false);

                // Increments through the list of active sites and gives them a new, unique passcode.
                foreach (Site site in siteList)
                {
                    passcode = getPasscode();
                    // Checks each site to ensure the new passcode does not match any other site's passcode.
                    while (!unique)
                    {
                        var exists = (from x in context.Sites
                                      where x.Passcode == passcode && x.Disabled == false
                                      select x).FirstOrDefault();

                        if (exists != null)
                        {
                            passcode = getPasscode();
                        }
                        else
                        {
                            unique                    = true;
                            site.Passcode             = passcode;
                            context.Entry(site).State = System.Data.Entity.EntityState.Modified;
                            context.SaveChanges();
                        }
                    }
                    unique = false;
                }
            }
        }