Esempio n. 1
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();
                }
            }
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
0
        public int Unit_Add(Unit item, int userSiteId)
        {
            using (MSSContext context = new MSSContext())
            {
                if (userSiteId == item.SiteId || userSiteId == 0)
                {
                    Site site = (from x in context.Sites
                                 where x.SiteId == item.SiteId
                                 select x).FirstOrDefault();

                    if (site != null)
                    {
                        if (site.Disabled != true)
                        {
                            item = context.Units.Add(item);
                            context.SaveChanges();
                            return(item.UnitId);
                        }
                        else
                        {
                            throw new Exception("The Site you are trying to add this Unit to is Disabled. Someone may have disabled the Site since you started adding the unit. Site Name: " + site.SiteName +
                                                ".\rPlease exit and re-enter the page to fix your list of Sites.");
                        }
                    }
                    else
                    {
                        throw new Exception("The Unit's Site is coming up null, please contact an Administrator to check the database for siteId:" + item.SiteId + ".");
                    }
                }
                else
                {
                    throw new Exception("Can not add a unit to a site you do not work at. \r Please ask a SuperUser or another Administrator from the correct site.");
                }
            }
        }
        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();
                }
            }
        }
Esempio n. 5
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();
            }
        }
Esempio n. 6
0
        public void AddManagementAccount(managementaccount tempManagementAccount)
        {
            using (var context = new MSSContext())
            {
                managementaccount newManagementAccount = new managementaccount();
                newManagementAccount.firstname = tempManagementAccount.firstname;
                newManagementAccount.lastname  = tempManagementAccount.lastname;
                newManagementAccount.email     = tempManagementAccount.email;

                //Need to check if a name already exists by counting how many of the same names are in the database
                int numOfNames = 0;
                numOfNames = (from ma in context.managementaccounts
                              where ma.firstname == tempManagementAccount.firstname &&
                              ma.lastname == tempManagementAccount.lastname
                              select ma).Count();

                if (numOfNames == 0)
                {
                    newManagementAccount.username = (tempManagementAccount.firstname + tempManagementAccount.lastname).ToLower();
                }
                else
                {
                    // if there is a least one other person with the same name, the UserName is set with the value of numOfNames for the UserName to be Unique
                    newManagementAccount.username = (tempManagementAccount.firstname + tempManagementAccount.lastname + numOfNames).ToLower();
                }
                newManagementAccount.userpassword         = "******"; // unsure how the password is going to be generated
                newManagementAccount.activeyn             = true;
                newManagementAccount.authorizationlevelid = tempManagementAccount.authorizationlevelid;

                context.managementaccounts.Add(newManagementAccount);
                context.SaveChanges();
            }
        }
 public void Add_NewResponse(Response response)
 {
     using (var context = new MSSContext())
     {
         context.Responses.Add(response);
         context.SaveChanges();
     }
 }
Esempio n. 8
0
 public void Unit_Update(Unit item)
 {
     using (MSSContext context = new MSSContext())
     {
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Esempio n. 9
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();
            }
        }
Esempio n. 10
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();
     }
 }
Esempio n. 11
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();
     }
 }
Esempio n. 12
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);
     }
 }
Esempio n. 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();
     }
 }
Esempio n. 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();
     }
 }
Esempio n. 15
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();
     }
 }
Esempio n. 16
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();
     }
 }
 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();
     }
 }
Esempio n. 18
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();
     }
 }
Esempio n. 19
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();
     }
 }
Esempio n. 20
0
 public void AddAccessCode(AccessCodeDTO tempCode)
 {
     using (var context = new MSSContext())
     {
         accesscode newAccessCode = new accesscode();
         newAccessCode.accesscodeword = tempCode.accesscodeword.ToLower();
         newAccessCode.activeyn       = true;
         context.accesscodes.Add(newAccessCode);
         context.SaveChanges();
     }
 }
Esempio n. 21
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();
     }
 }
Esempio n. 22
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();
     }
 }
Esempio n. 23
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();
     }
 }
Esempio n. 24
0
 public void AddUnit(UnitDTO tempUnit)
 {
     using (var context = new MSSContext())
     {
         unit newUnit = new unit();
         newUnit.unitname   = tempUnit.unitname;
         newUnit.caresiteid = tempUnit.caresiteid;
         newUnit.activeyn   = true;
         context.units.Add(newUnit);
         context.SaveChanges();
     }
 }
Esempio n. 25
0
 public void AddRespondentType(RespondentDTO tempRespondentType)
 {
     using (var context = new MSSContext())
     {
         respondenttype newRespondentType = new respondenttype();
         newRespondentType.respondenttypeid   = tempRespondentType.respondenttypeid;
         newRespondentType.respondenttypename = tempRespondentType.respondenttypename;
         newRespondentType.activeyn           = true;
         context.respondenttypes.Add(newRespondentType);
         context.SaveChanges();
     }
 }
Esempio n. 26
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();
            }
        }
Esempio n. 27
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();
     }
 }
Esempio n. 28
0
 public void AddGender(GenderDTO tempGender)
 {
     using (var context = new MSSContext())
     {
         gender newGender = new gender();
         newGender.genderid   = tempGender.genderid;
         newGender.gendername = tempGender.gendername;
         newGender.activeyn   = true;
         context.genders.Add(newGender);
         context.SaveChanges();
     }
 }
Esempio n. 29
0
 public void AddAgeGroup(AgeGroupDTO tempAgeGroup)
 {
     using (var context = new MSSContext())
     {
         agegroup newAgeGroup = new agegroup();
         newAgeGroup.agegroupid   = tempAgeGroup.agegroupid;
         newAgeGroup.agegroupname = tempAgeGroup.agegroupname;
         newAgeGroup.activeyn     = true;
         context.agegroups.Add(newAgeGroup);
         context.SaveChanges();
     }
 }
Esempio n. 30
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();
            }
        }