Beispiel #1
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);
                }
            }
        }
Beispiel #2
0
 public List <unit> ListAllUnits()
 {
     using (var context = new MSSContext())
     {
         return(context.units.ToList());
     }
 }
Beispiel #3
0
 /// <summary>
 /// Looks for the site whoose ID matches the ID provided.
 /// </summary>
 /// <param name="siteId">Contains the site ID of the site that the user is looking for</param>
 /// <returns>A Site object matching the siteId</returns>
 public Site Site_FindById(int siteId)
 {
     using (MSSContext context = new MSSContext())
     {
         return(context.Sites.Find(siteId));
     }
 }
Beispiel #4
0
        public List<ContactRequestDTO> ViewContactRequests(List<int> unitIds, List<string> genders, List<string> ages, DateTime dateOne, DateTime dateTwo, List<bool> statuses)
        {
            using (var context = new MSSContext())
            {
                var contactRequests = (from aSurvey in context.surveys
                                       where unitIds.Contains(aSurvey.unitid) && genders.Contains(aSurvey.gender)
                                       && ages.Contains(aSurvey.age) && (aSurvey.date >= dateOne) && (aSurvey.date <= dateTwo) && statuses.Contains(aSurvey.contactedyn.Value)
                                       select new ContactRequestDTO()
                                       {
                                           surveyid = aSurvey.surveyid,
                                           date = aSurvey.date,
                                           age = aSurvey.age,
                                           gender = aSurvey.gender,
                                           firstname = aSurvey.firstname,
                                           lastname = aSurvey.lastname,
                                           bednaumber = aSurvey.bednumber,
                                           phonenumber = aSurvey.phonenumber,
                                           preferredcontact = aSurvey.preferredcontact,
                                           contactedyn = aSurvey.contactedyn,
                                           respondenttypeid = aSurvey.respondenttypeid,
                                           unitid = aSurvey.unitid,

                                           unitname = aSurvey.unit.unitname,
                                           caresitename = aSurvey.unit.caresite.caresitename

                                       }).ToList();

                return contactRequests.ToList();
            }
        }
 public List <Question> GetQuestionParameterList()
 {
     using (MSSContext context = new MSSContext())
     {
         return(context.Questions.ToList());
     }
 }
        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();
                }
            }
        }
Beispiel #7
0
 public List <Site> Site_List(bool deactivated, string searchArg, string searchBy)
 {
     using (MSSContext context = new MSSContext())
     {
         IQueryable <Site> results = null;
         if (searchBy == "Site Name")
         {
             results =
                 (from item in context.Sites
                  where item.Disabled == deactivated && item.SiteName.Contains(searchArg)
                  orderby item.SiteName ascending
                  select item);
         }
         else if (searchBy == "Description")
         {
             results =
                 (from item in context.Sites
                  where item.Disabled == deactivated && item.Description.Contains(searchArg)
                  orderby item.SiteName ascending
                  select item);
         }
         else if (searchBy == "All")
         {
             results =
                 (from item in context.Sites
                  where item.Disabled == deactivated && (item.Description.Contains(searchArg) || item.SiteName.Contains(searchArg))
                  orderby item.SiteName ascending
                  select item);
         }
         return(results.ToList());
     }
 }
Beispiel #8
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 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 List <AccessCodeDTO> GetAccessCodesByExactMatch(string matchString, bool?activeStatus)
        {
            using (var context = new MSSContext())
            {
                IQueryable <accesscode> accessCodes = null;
                if (!activeStatus.HasValue) // return all regardless of status
                {
                    accessCodes = from item in context.accesscodes
                                  where item.accesscodeword.Equals(matchString)
                                  orderby item.accesscodeword ascending
                                  select item;
                }
                else // filter by status
                {
                    accessCodes = from item in context.accesscodes
                                  where item.activeyn == activeStatus && item.accesscodeword.Equals(matchString)
                                  orderby item.accesscodeword ascending
                                  select item;
                }

                List <AccessCodeDTO> accessCodeDTOs = new List <AccessCodeDTO>();
                foreach (accesscode code in accessCodes)
                {
                    AccessCodeDTO temp = new AccessCodeDTO();
                    temp.accesscodeid   = code.accesscodeid;
                    temp.accesscodeword = code.accesscodeword;
                    temp.activeyn       = code.activeyn;
                    accessCodeDTOs.Add(temp);
                }
                return(accessCodeDTOs);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Adds a default user with Superuser privileges to the database
        /// </summary>
        public void AddWebMaster()
        {
            // Checks to see if a user with the same username exists
            if (!Users.Any(u => u.UserName.Equals(STR_WEBMASTER_USERNAME)))
            {
                using (MSSContext context = new MSSContext())
                {
                    // create a new instance of an AspNetUser that will be used as the data to
                    //   add a new record to the AspNetUsers table
                    // dynamically fill two attributes of the instance while the user is being constructed
                    var webmasterAccount = new ApplicationUser()
                    {
                        UserName = STR_WEBMASTER_USERNAME,
                        // Gets the site Id of the TST site and assigns the webmaster to it
                        SiteId    = context.Sites.Where(x => x.SiteName == "Administrator Site").FirstOrDefault().SiteId,
                        FirstName = "Web",
                        LastName  = "Master",
                        Active    = true
                    };

                    // place the webmaster account on the AspNetUsers table
                    this.Create(webmasterAccount, STR_DEFAULT_PASSWORD);

                    // Assign the webmaster account to the Superuser role
                    this.AddToRole(webmasterAccount.Id, SecurityRoles.SuperUser);
                }
            }
        }
Beispiel #12
0
 public List <ContactRequestDTO> ViewContactRequests(List <int> unitIds, List <int> genders, List <int> ages, List <bool> statuses, List <int> respodentIds)
 {
     using (var context = new MSSContext())
     {
         var contactRequests = (from aSurvey in context.surveys
                                where unitIds.Contains(aSurvey.unitid) && genders.Contains(aSurvey.genderid) &&
                                ages.Contains(aSurvey.agegroupid) && statuses.Contains(aSurvey.contactedyn.Value) && respodentIds.Contains(aSurvey.respondenttypeid)
                                select new ContactRequestDTO()
         {
             surveyid = aSurvey.surveyid,
             date = aSurvey.date,
             agegroupid = aSurvey.agegroupid,
             genderid = aSurvey.genderid,
             firstname = aSurvey.firstname,
             bednaumber = aSurvey.bednumber,
             phonenumber = aSurvey.phonenumber,
             preferredcontact = aSurvey.preferredcontact,
             contactedyn = aSurvey.contactedyn,
             respondenttypeid = aSurvey.respondenttypeid,
             unitid = aSurvey.unitid,
             gendername = aSurvey.gender.gendername,
             agegroupname = aSurvey.agegroup.agegroupname,
             unitname = aSurvey.unit.unitname,
             caresitename = aSurvey.unit.caresite.caresitename
         }).ToList();
         return(contactRequests.ToList());
     }
 }
        /// <summary>
        /// Overloaded grabData() for filtering based on date.
        /// </summary>
        /// <param name="siteId">Id of site to query</param>
        /// <param name="fromDate">From date to query</param>
        /// <param name="toDate">To date to query</param>
        /// <returns></returns>
        public List <ChartingHomeResponse> grabData(int siteId, DateTime fromDate, DateTime toDate)
        {
            using (var context = new MSSContext())
            {
                var result = from x in context.QuestionResponses
                             where x.Response.Unit.SiteId == siteId &&
                             x.Response.Date >= fromDate &&
                             x.Response.Date <= toDate

                             select new ChartingHomeResponse
                {
                    questions     = x.Question.QuestionText,
                    subQuestions  = x.Question.SubQuestionText,
                    answers       = x.Answer.Description,
                    answerID      = x.AnswerId,
                    value         = x.Answer.Value,
                    unitID        = x.Response.UnitId,
                    questionID    = x.QuestionId,
                    questionParam = x.Question.QuestionParameter,
                    maxValue      = x.Answer.MaxValue,
                    colour        = x.Answer.Colour,
                    removed       = x.Response.Unit.Disabled,
                    unitName      = x.Response.Unit.UnitName
                };
                return(result.ToList());
            }
        }
        /// <summary>
        /// Queries and returns all QuestionResponses and thier associated values that are dated within the current quarter.
        /// </summary>
        /// <param name="siteId">This is the site ID that the current user is affiliated with.</param>
        /// <returns>A list of QuestionResponses and thier relevatn associated data.</returns>
        public List <ChartingHomeResponse> grabData(int siteId)
        {
            using (var context = new MSSContext())
            {
                var result = from x in context.QuestionResponses
                             where (x.Response.Unit.SiteId == siteId && Math.Floor(1 + (((double)x.Response.Date.Month - 1) / 3)) == Math.Floor(1 + (double)(DateTime.Now.Month - 1) / 3) && DateTime.Now.Year == x.Response.Date.Year)

                             select new ChartingHomeResponse
                {
                    questions     = x.Question.QuestionText,
                    subQuestions  = x.Question.SubQuestionText,
                    answers       = x.Answer.Description,
                    answerID      = x.AnswerId,
                    value         = x.Answer.Value,
                    unitID        = x.Response.UnitId,
                    questionID    = x.QuestionId,
                    questionParam = x.Question.QuestionParameter,
                    maxValue      = x.Answer.MaxValue,
                    colour        = x.Answer.Colour,
                    removed       = x.Response.Unit.Disabled,
                    unitName      = x.Response.Unit.UnitName
                };
                return(result.ToList());
            }
        }
Beispiel #15
0
        public ExtendedSurveyDTO GetSurveyDetails(int surveyId)
        {
            using (var context = new MSSContext())
            {
                var surveyDetails = context.surveys.Find(surveyId);

                ExtendedSurveyDTO tempSurvey = new ExtendedSurveyDTO();
                if (surveyDetails == null)
                {
                    tempSurvey.surveyid = -1;
                }
                else
                {
                    tempSurvey.surveyid           = surveyDetails.surveyid;
                    tempSurvey.date               = surveyDetails.date;
                    tempSurvey.agegroupid         = surveyDetails.agegroupid;
                    tempSurvey.genderid           = surveyDetails.genderid;
                    tempSurvey.firstname          = surveyDetails.firstname;
                    tempSurvey.bednaumber         = surveyDetails.bednumber;
                    tempSurvey.phonenumber        = surveyDetails.phonenumber;
                    tempSurvey.preferredcontact   = surveyDetails.preferredcontact;
                    tempSurvey.contactedyn        = surveyDetails.contactedyn;
                    tempSurvey.respondenttypeid   = surveyDetails.respondenttypeid;
                    tempSurvey.unitid             = surveyDetails.unitid;
                    tempSurvey.gendername         = surveyDetails.gender.gendername;
                    tempSurvey.agegroupname       = surveyDetails.agegroup.agegroupname;
                    tempSurvey.unitname           = surveyDetails.unit.unitname;
                    tempSurvey.caresitename       = surveyDetails.unit.caresite.caresitename;
                    tempSurvey.respondenttypename = surveyDetails.respondenttype.respondenttypename;
                }
                return(tempSurvey);
            }
        }
Beispiel #16
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();
                }
            }
        }
Beispiel #17
0
        public List <ExtendedSurveyDTO> GetSurveys(List <int> unitIds, List <int> genders, List <int> ages, DateTime dateOne, DateTime dateTwo, List <int> respodentIds)
        {
            using (var context = new MSSContext())
            {
                var surveyList = (from aSurvey in context.surveys
                                  where unitIds.Contains(aSurvey.unitid) && genders.Contains(aSurvey.genderid) && respodentIds.Contains(aSurvey.respondenttypeid) && ages.Contains(aSurvey.agegroupid) && aSurvey.date >= dateOne && aSurvey.date <= dateTwo
                                  select new ExtendedSurveyDTO()
                {
                    surveyid = aSurvey.surveyid,
                    date = aSurvey.date,
                    agegroupid = aSurvey.agegroupid,
                    genderid = aSurvey.genderid,
                    firstname = aSurvey.firstname,
                    bednaumber = aSurvey.bednumber,
                    phonenumber = aSurvey.phonenumber,
                    preferredcontact = aSurvey.preferredcontact,
                    contactedyn = aSurvey.contactedyn,
                    respondenttypeid = aSurvey.respondenttypeid,
                    unitid = aSurvey.unitid,
                    unitname = aSurvey.unit.unitname,
                    caresitename = aSurvey.unit.caresite.caresitename,
                    gendername = aSurvey.gender.gendername,
                    agegroupname = aSurvey.agegroup.agegroupname
                }).ToList();

                return(surveyList.ToList());
            }
        }
Beispiel #18
0
 public List <managementaccount> GetManagementAccounts()
 {
     using (var context = new MSSContext())
     {
         return(context.managementaccounts.ToList());
     }
 }
        public List <int> GetAccessCodes(List <int> alreadyAssignedCodes, DateTime assignDate, int careSiteId)
        {
            using (var context = new MSSContext())
            {
                List <string> dateWords = new List <string>();
                dateWords = (from aCareSiteCode in context.caresiteaccesses
                             where aCareSiteCode.dateused == assignDate
                             select aCareSiteCode.accesscode.accesscodeword).ToList();

                DateTime yesterDay = assignDate.AddDays(-1);

                List <string> yesterWords = new List <string>();
                yesterWords = (from aCareSiteCode in context.caresiteaccesses
                               where aCareSiteCode.dateused == yesterDay && aCareSiteCode.caresiteid == careSiteId
                               select aCareSiteCode.accesscode.accesscodeword).ToList();

                var accessCodes = (from aAccessCode in context.accesscodes
                                   where !alreadyAssignedCodes.Contains(aAccessCode.accesscodeid) && (!dateWords.Contains(aAccessCode.accesscodeword)) && (!yesterWords.Contains(aAccessCode.accesscodeword)) && aAccessCode.activeyn == true
                                   select aAccessCode).ToList();

                List <int> accessCodeIds = new List <int>();

                foreach (accesscode code in accessCodes)
                {
                    int temp = new int();
                    temp = code.accesscodeid;
                    accessCodeIds.Add(temp);
                }

                return(accessCodeIds);
            }
        }
        public AccessCodeDTO GetCareSiteAccessCodeByDate(int careSiteID, DateTime date)
        {
            using (var context = new MSSContext())
            {
                // Note: unfortunately, because of Linq, the only way to compare dates without times is to compare each piece of the date (year, month, day) individually. Linq does not allow the .Date function in its queries and therefore cannot be used.
                var accessCode = from aCareSiteAccess in context.caresiteaccesses
                                 where aCareSiteAccess.caresiteid == careSiteID && aCareSiteAccess.dateused.Year == date.Year && aCareSiteAccess.dateused.Month == date.Month && aCareSiteAccess.dateused.Day == date.Day
                                 select aCareSiteAccess;

                // using .First() here because this search should only return ONE CareSiteAccess item
                AccessCodeDTO selectedCode = new AccessCodeDTO();
                if (accessCode.Count() == 0)
                {
                    selectedCode.accesscodeid = -3;
                }
                else
                {
                    selectedCode.accesscodeid   = accessCode.First().accesscodeid;
                    selectedCode.accesscodeword = accessCode.First().accesscode.accesscodeword;
                    selectedCode.activeyn       = accessCode.First().accesscode.activeyn;
                }

                return(selectedCode);
            }
        }
Beispiel #21
0
        public List<SurveyDTO> GetSurveys(List<int> unitIds, List<string> genders, List<string> ages, DateTime dateOne, DateTime dateTwo)
        {
            using (var context = new MSSContext())
            {
                var surveyList = (from aSurvey in context.surveys
                                 where unitIds.Contains(aSurvey.unitid) && genders.Contains(aSurvey.gender) && ages.Contains(aSurvey.age) && aSurvey.date >= dateOne && aSurvey.date <= dateTwo
                                 select new SurveyDTO()
                                 {
                                     surveyid = aSurvey.surveyid,
                                     date = aSurvey.date,
                                     age = aSurvey.age,
                                     gender = aSurvey.gender,
                                     firstname = aSurvey.firstname,
                                     lastname = aSurvey.lastname,
                                     bednaumber = aSurvey.bednumber,
                                     phonenumber = aSurvey.phonenumber,
                                     preferredcontact = aSurvey.preferredcontact,
                                     contactedyn = aSurvey.contactedyn,
                                     respondenttypeid = aSurvey.respondenttypeid,
                                     unitid = aSurvey.unitid

                                 }).ToList();

                return surveyList.ToList();
            }
        }
Beispiel #22
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();
            }
        }
 public List <authorizationlevel> GetAuthorizationLevels()
 {
     using (var context = new MSSContext())
     {
         return(context.authorizationlevels.ToList());
     }
 }
Beispiel #24
0
 public managementaccount GetManagementAccountDetails(int managementAccountID)
 {
     using (var context = new MSSContext())
     {
         var managementaccount = context.managementaccounts.Find(managementAccountID);
         return(managementaccount);
     }
 }
Beispiel #25
0
 public AccessCodeDTO CheckSurveyAccessCode() // CCC: delete this if not being used
 {
     using (var context = new MSSContext())
     {
         //TODO: add text - sorry, not sure what this method does?
         return(null);
     }
 }
 public void Unit_Update(Unit item)
 {
     using (MSSContext context = new MSSContext())
     {
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void Add_NewResponse(Response response)
 {
     using (var context = new MSSContext())
     {
         context.Responses.Add(response);
         context.SaveChanges();
     }
 }
 /// <summary>
 /// Counts number of questions
 /// </summary>
 /// <returns>An integer representing the total number of questions</returns>
 public int Question_Count()
 {
     using (MSSContext context = new MSSContext())
     {
         var questionList = from x in context.Questions select x;
         return(questionList.Count());
     }
 }
Beispiel #29
0
 public CareSiteDTO GetViewableCareSites() // Just a thought, shouldn't this return a list? - CCC   yes
 {
     using (var context = new MSSContext())
     {
         //TODO: finish this method (will need a username passed in)
         return(null);
     }
 }
Beispiel #30
0
 /// <summary>
 /// Gets the role of the user with the provided username
 /// </summary>
 /// <param name="username">Username of the user whose role to look for</param>
 /// <returns></returns>
 public string getUserRole(string username)
 {
     using (MSSContext context = new MSSContext())
     {
         var user = context.Users.Where(u => u.UserName == username).Select(u => u).FirstOrDefault();
         return(context.Roles.Find(user.Roles.FirstOrDefault().RoleId).Name);
     }
 }