Exemple #1
0
        public ActionResult LoginAuthentication(string userName, string password, bool RememberBox)
        {
            Security           active      = new Security();
            var                UController = new UsersController();
            SecurityController SController = new SecurityController(active);
            IVM                model       = new LoginVM(active.IsLoggedIn, active);

            var user = UController.GetU(userName);

            if (user != null)
            {
                var saltHash        = user.PassSalt;
                var encodedPassword = UController.HashPassword(password, saltHash);
                if (user.PassHash.Trim() == encodedPassword.Trim())
                {
                    SController.Login(userName);
                    SController.SetRemember(RememberBox);
                    Login(SController);
                    model = new InventoryVM(userName.Trim(), SController.GetActive());
                    return(View("Inventory", model));
                }
                else
                {
                    ViewBag.ErrorMessage = "Invalid Password";
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Invalid User Name";
            }

            return(View("Index", model));
        }
Exemple #2
0
        public ActionResult ChartAnalysis(string actives, string activeLog, string activeRem, string numOfSystems)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            if (!(IsLoggedIn(Active).CheckLogin()))
            {
                return(RedirectToAction("Index"));
            }

            // check that numOfSystems is a valid number
            int num;

            if (numOfSystems == null || !int.TryParse(numOfSystems, out num))
            {
                num = 6;
            }

            string uId = Active.GetID();

            Inventory inventory = new Inventory(uId);

            inventory.SortByTotalScore();
            inventory = inventory.GetTop(num);
            InventoryVM model = new InventoryVM(inventory, active);

            return(View(model));
        }
Exemple #3
0
        public ActionResult ForgotPassword(string userName = null)
        {
            Security active;

            if (userName == null)
            {
                active = session("", "False", "False");
            }
            active = session(userName, "False", "False");
            SecurityController Active = new SecurityController(active);
            IVM model = new SecurityVM(active);

            if (userName == null)
            {
                return(View("ForgotPassword", model));
            }

            string          randomPass = genPass().Trim();
            UsersController u          = new UsersController();
            User            user       = u.GetU(userName);

            user.PassHash = u.HashPassword(randomPass, user.PassSalt);
            u.PutUser(user);
            sendEmail(randomPass, userName, user.FName);
            model = new LoginVM(false, active);
            return(View("Index", model));
        }
Exemple #4
0
        public ActionResult StartSurvey(string actives, string activeLog, string activeRem, QuestionVM model)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            if (!(IsLoggedIn(Active).CheckLogin() || !ModelState.IsValid))
            {
                return(RedirectToAction("Index", "Home"));
            }

            SurveyQuestionVM      surveyQuestionVM = new SurveyQuestionVM(active);
            AnswersController     aController      = new AnswersController();
            EnvironmentController eController      = new EnvironmentController();
            string userId = Active.GetID();

            if (Request.Form["btnEditSurvey"] != null)
            {
                Answer a = aController.GetAnswer(userId, int.Parse(Request.Form["btnEditSurvey"]));

                surveyQuestionVM.QuestionText = eController.GetQuestionText(1);
                surveyQuestionVM.AId          = a.AId;
                surveyQuestionVM.QId          = 1;

                surveyQuestionVM.ProgramName = a.programName;
            }
            else
            {
                surveyQuestionVM.QuestionText      = eController.GetQuestionText(1);
                surveyQuestionVM.AId               = aController.GetNextAId(userId);
                surveyQuestionVM.QId               = 1;
                surveyQuestionVM.NumberofQuestions = eController.GetQuestionCount();
                surveyQuestionVM.ProgramName       = model.Name;
            }

            using (var context = new DBAContext())
            {
                Answer CheckAnswer = (from t in context.Answers where ((userId == t.UId) & (1 == t.QId) & (surveyQuestionVM.AId == t.AId)) select t).FirstOrDefault();

                if (CheckAnswer != null)
                {
                    surveyQuestionVM.Value = CheckAnswer.Value;
                }
            }
            //sets up the state of the buttons
            surveyQuestionVM.NumberofQuestions = eController.GetQuestionCount();
            surveyQuestionVM.AnsweredQuestions = GetAnsweredList(userId, surveyQuestionVM.AId);
            surveyQuestionVM.DisableQuestion   = GetDisable(userId, surveyQuestionVM.AId, surveyQuestionVM.AnsweredQuestions);
            if (surveyQuestionVM.DisableQuestion != null)
            {
                DeleteAnswer(userId, surveyQuestionVM.AId, surveyQuestionVM.DisableQuestion);
            }

            ModelState.Clear();

            return(View("SurveyQuestions", surveyQuestionVM));
        }
Exemple #5
0
        public ActionResult About(string actives, string activeLog, string activeRem)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            Active.CheckLogin();
            IVM model = new SecurityVM(active);

            return(View(model));
        }
Exemple #6
0
        public ActionResult SurveyQuestions(string actives, string activeLog, string activeRem, SurveyQuestionVM model)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            if (!(IsLoggedIn(Active).CheckLogin()))
            {
                return(RedirectToAction("Index", "Home"));
            }
            ModelState.Clear();
            return(View(model));
        }
Exemple #7
0
        public ActionResult Registration(string actives, string activeLog, string activeRem)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);
            IVM model = new SecurityVM(active);

            if (IsLoggedIn(Active).CheckLogin())
            {
                model = new InventoryVM(Active.GetID(), Active.GetActive());
                return(View("Inventory", model));
            }

            return(View(model));
        }
Exemple #8
0
        private void Login(SecurityController active)
        {
            HttpCookie cookie = Request.Cookies["UserInfo"];

            if (cookie == null || cookie.Values["LoggedIn"] != "True")
            {
                cookie = new HttpCookie("UserInfo");
            }

            cookie.Values["LoggedIn"] = "True";
            cookie.Values["ID"]       = active.GetID();
            cookie.Values["Remember"] = active.GetRemember().ToString();
            cookie.Expires            = active.GetEX();
            Response.Cookies.Add(cookie);
        }
Exemple #9
0
        public ActionResult Justification(string actives, string activeLog, string activeRem, string aId)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            if (!(IsLoggedIn(Active).CheckLogin()))
            {
                return(RedirectToAction("Index"));
            }

            string          uId   = Active.GetID();
            JustificationVM model = new JustificationVM(uId, aId, active);

            return(View(model));
        }
Exemple #10
0
        public ActionResult DeleteSurvey(string actives, string activeLog, string activeRem, int aId)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);
            AnswersController  a      = new AnswersController();

            if (!(IsLoggedIn(Active).CheckLogin()))
            {
                return(RedirectToAction("Index"));
            }

            string uId = Active.GetID();

            a.DeleteWholeAnswer(uId, aId);

            InventoryVM model = new InventoryVM(uId, active);

            return(RedirectToAction("Inventory", model));
        }
Exemple #11
0
        public ActionResult TextAnalysis(string actives, string activeLog, string activeRem)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            if (!(IsLoggedIn(Active).CheckLogin()))
            {
                return(RedirectToAction("Index"));
            }

            string    uId       = Active.GetID();
            Inventory inventory = new Inventory(uId);

            inventory.SortByTotalScore();
            inventory = inventory.GetTop(6);
            InventoryVM model = new InventoryVM(inventory, active);

            return(View(model));
        }
Exemple #12
0
        public ActionResult PutUser(string FirstName, string LastName, string Organization, string PassHash, string actives, string activeLog, string activeRem, string CurrentPassword, string NewPassword)
        {
            Security           active      = session(actives, activeLog, activeRem);
            UsersController    u           = new UsersController();
            SecurityController SController = new SecurityController(active);
            IVM model;

            var getUser = u.GetU(SController.GetID().Trim());

            if (getUser.PassHash.Trim() == u.HashPassword(CurrentPassword, getUser.PassSalt).Trim())
            {
                if (FirstName == null)
                {
                    FirstName = "";
                }
                if (LastName == null)
                {
                    LastName = "";
                }
                if (Organization == null)
                {
                    Organization = "";
                }
                getUser.FName        = FirstName;
                getUser.LName        = LastName;
                getUser.Organization = Organization;

                getUser.PassHash = u.HashPassword(NewPassword, getUser.PassSalt);
                UController.PutUser(getUser.ID, getUser);

                ViewBag.ErrorMessage = "Account Info Updated";

                //return View("Account", model);
            }
            else
            {
                ViewBag.ErrorMessage = "Invalid Password";
            }

            model = new AccountVM(SController.GetID(), SController.GetActive());

            return(View("Account", model));
        }
Exemple #13
0
        public SecurityController IsLoggedIn(SecurityController active)
        {
            bool       value       = false;
            string     decodedUser = "";
            bool       remember    = false;
            HttpCookie cookie      = Request.Cookies["UserInfo"];

            if (cookie != null)
            {
                decodedUser = HttpUtility.HtmlDecode(cookie.Values["ID"]);
                value       = HttpUtility.HtmlDecode(cookie.Values["LoggedIn"]).Equals("True");
                remember    = HttpUtility.HtmlDecode(cookie.Values["Remember"]).Equals("True");
            }
            if (value)
            {
                active.Login(decodedUser);
                active.SetRemember(remember);
            }
            return(active);
        }
Exemple #14
0
        public ActionResult Inventory(string sort, string actives, string activeLog, string activeRem)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            if (!(IsLoggedIn(Active).CheckLogin()))
            {
                return(RedirectToAction("Index"));
            }

            Inventory inventory = new Inventory(Active.GetID());

            inventory.SortByLastUsed();
            int section;

            if (sort == "name")
            {
                inventory.SortByName();
            }
            else if (sort == "lastUsed")
            {
                inventory.SortByLastUsed();
            }
            else if (sort == "totalScore")
            {
                inventory.SortByTotalScore();
            }
            else if (int.TryParse(sort, out section))
            {
                inventory.SortBySectionScore(section);
            }

            InventoryVM model = new InventoryVM(inventory, active);

            return(View(model));
        }
Exemple #15
0
        public ActionResult PostUser(User user)
        {
            Security           active = session(user.ID, "False", "False");
            UsersController    u      = new UsersController();
            SecurityController SC     = new SecurityController(active);
            IVM model = new LoginVM(active.IsLoggedIn, active);

            var getUser = u.GetU(user.ID);

            if (getUser == null)
            {
                if (user.FName == null)
                {
                    user.FName = "";
                }
                if (user.LName == null)
                {
                    user.LName = "";
                }
                if (user.Organization == null)
                {
                    user.Organization = "";
                }
                SC.Login(user.ID);
                Login(SC);
                UController.PostUser(user);
                model = new InventoryVM(SC.GetID(), active);
                return(View("Inventory", model));
            }
            else
            {
                ViewBag.ErrorMessage = "Email already registered";
            }
            model = new SecurityVM(active);
            return(View("Registration", model));
        }
Exemple #16
0
        public ActionResult NextQuestion(string actives, string activeLog, string activeRem, SurveyQuestionVM model)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            if (!(IsLoggedIn(Active).CheckLogin() || !ModelState.IsValid))
            {
                return(RedirectToAction("Index", "Home"));
            }

            SurveyQuestionVM      surveyQuestionVM = new SurveyQuestionVM(active);
            EnvironmentController eController      = new EnvironmentController();
            AnswersController     aController      = new AnswersController();
            string userId = Active.GetID();

            surveyQuestionVM.AId         = model.AId;
            surveyQuestionVM.ProgramName = model.ProgramName;

            using (var context = new DBAContext())
            {
                //checking to see if the Program name was changed and if it was to change the rest of them
                Answer CheckName = (from t in context.Answers where ((userId == t.UId) & (model.AId == t.AId)) select t).FirstOrDefault();
                if (CheckName != null && CheckName.programName != surveyQuestionVM.ProgramName)
                {
                    RenameProgram(userId, model.AId, surveyQuestionVM.ProgramName);
                }

                //Answer to question will not be saved if it wasnt answered
                if (model.Value != null)
                {
                    //Save the Answer to the question just answered.
                    Answer previousAnswer = new Answer();
                    previousAnswer.QId         = model.QId;
                    previousAnswer.Value       = model.Value;
                    previousAnswer.programName = model.ProgramName;
                    previousAnswer.UId         = userId;
                    previousAnswer.AId         = model.AId;

                    //checks to see if the answer exists
                    Answer CheckAnswer = (from t in context.Answers where ((userId == t.UId) & (model.QId == t.QId) & (model.AId == t.AId)) select t).FirstOrDefault();
                    //if the answer exists use Put, otherwise use Post
                    if (CheckAnswer != null)
                    {
                        previousAnswer.Created = CheckAnswer.Created;
                        aController.PutAnswer(previousAnswer.UId, previousAnswer);
                    }
                    else
                    {
                        aController.PostAnswer(previousAnswer);
                    }
                }
            }

            //sets up the state of the buttons
            surveyQuestionVM.AnsweredQuestions = GetAnsweredList(userId, surveyQuestionVM.AId);
            surveyQuestionVM.DisableQuestion   = GetDisable(userId, surveyQuestionVM.AId, surveyQuestionVM.AnsweredQuestions);
            if (surveyQuestionVM.DisableQuestion != null)
            {
                DeleteAnswer(userId, surveyQuestionVM.AId, surveyQuestionVM.DisableQuestion);
            }
            surveyQuestionVM.QId = model.QId;
            int i = model.QId;

            i++;
            //Skips if the next question should not be answered
            if (surveyQuestionVM.DisableQuestion.Exists(x => x == i))
            {
                i += 1;
            }

            //redirects to the summary when it reachs the end
            int End = eController.GetQuestionCount();

            if (i > End)
            {
                return(RedirectToAction("Inventory", "Home"));
            }

            //sets tje question text and ID
            surveyQuestionVM.QuestionText = eController.GetQuestionText(i);
            surveyQuestionVM.QId          = i;

            //checks to see if the next question has an answer already
            using (var context = new DBAContext())
            {
                Answer CheckAnswer = (from t in context.Answers where ((userId == t.UId) & (i == t.QId) & (model.AId == t.AId)) select t).FirstOrDefault();

                surveyQuestionVM.NumberofQuestions = eController.GetQuestionCount();

                //sets the value for the next answer to the answer that exists
                if (CheckAnswer != null)
                {
                    surveyQuestionVM.Value = CheckAnswer.Value;
                }
            }
            ModelState.Clear();
            return(View("SurveyQuestions", surveyQuestionVM));
        }
Exemple #17
0
        public ActionResult PreviousQuestion(string actives, string activeLog, string activeRem, SurveyQuestionVM model)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            if (!(IsLoggedIn(Active).CheckLogin() || !ModelState.IsValid))
            {
                return(RedirectToAction("Index", "Home"));
            }

            SurveyQuestionVM      surveyQuestionVM = new SurveyQuestionVM(active);
            AnswersController     aController      = new AnswersController();
            EnvironmentController eController      = new EnvironmentController();
            string userId = Active.GetID();

            surveyQuestionVM.AId         = model.AId;
            surveyQuestionVM.ProgramName = model.ProgramName;

            using (var context = new DBAContext())
            {
                //Checks to see if the Program Name was changed and if it was changes all of them
                Answer CheckName = (from t in context.Answers where ((userId == t.UId) & (model.AId == t.AId)) select t).FirstOrDefault();
                if ((CheckName != null) && (CheckName.programName != surveyQuestionVM.ProgramName))
                {
                    RenameProgram(userId, model.AId, surveyQuestionVM.ProgramName);
                }

                //Answer to question will not be saved if it wasnt answered
                if (model.Value != null)
                {
                    Answer previousAnswer = new Answer();
                    previousAnswer.AId         = model.AId;
                    previousAnswer.QId         = model.QId;
                    previousAnswer.UId         = userId;
                    previousAnswer.programName = model.ProgramName;
                    previousAnswer.Value       = model.Value;

                    Answer CheckAnswer = (from t in context.Answers where ((userId == t.UId) & (model.QId == t.QId) & (model.AId == t.AId)) select t).FirstOrDefault();
                    //if the answer exists use Put, otherwise use Post
                    if (CheckAnswer != null)
                    {
                        previousAnswer.Created = CheckAnswer.Created;
                        aController.PutAnswer(previousAnswer.UId, previousAnswer);
                    }
                    else
                    {
                        aController.PostAnswer(previousAnswer);
                    }
                }
            }

            surveyQuestionVM.NumberofQuestions = eController.GetQuestionCount();
            surveyQuestionVM.AnsweredQuestions = GetAnsweredList(userId, surveyQuestionVM.AId);
            surveyQuestionVM.DisableQuestion   = GetDisable(userId, surveyQuestionVM.AId, surveyQuestionVM.AnsweredQuestions);
            if (surveyQuestionVM.DisableQuestion != null)
            {
                DeleteAnswer(userId, surveyQuestionVM.AId, surveyQuestionVM.DisableQuestion);
            }
            surveyQuestionVM.QId = model.QId;
            int i = model.QId;

            i--;
            //checks to see if the question should be skiped or not
            if (surveyQuestionVM.DisableQuestion.Exists(x => x == i))
            {
                i -= 1;
            }

            if (i <= 0)
            {
                return(RedirectToAction("Inventory", "Home"));
            }

            //setting the next question text and id
            surveyQuestionVM.QuestionText = eController.GetQuestionText(i);
            surveyQuestionVM.QId          = i;

            using (var context = new DBAContext())
            {
                //Checks to see if the Answer exists
                Answer CheckAnswer = (from t in context.Answers where ((userId == t.UId) & (i == t.QId) & (model.AId == t.AId)) select t).FirstOrDefault();

                //if it exists set the value for the question then load it in
                if (CheckAnswer != null)
                {
                    surveyQuestionVM.Value = CheckAnswer.Value;
                }
            }

            ModelState.Clear();

            return(View("SurveyQuestions", surveyQuestionVM));
        }
Exemple #18
0
        public ActionResult SkipQuestion(string actives, string activeLog, string activeRem, SurveyQuestionVM model)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            if (!(IsLoggedIn(Active).CheckLogin() || !ModelState.IsValid))
            {
                return(RedirectToAction("Index", "Home"));
            }

            HttpCookie cookie = Request.Cookies["UserInfo"];
            string     userId = cookie.Values["ID"];

            SurveyQuestionVM surveyQuestionVM = new SurveyQuestionVM(active);
            var eController = new EnvironmentController();
            var aController = new AnswersController();

            surveyQuestionVM.AId         = model.AId;
            surveyQuestionVM.ProgramName = model.ProgramName;

            using (var context = new DBAContext())
            {
                //Checks if the program name changed
                Answer CheckName = (from t in context.Answers where ((userId == t.UId) & (model.AId == t.AId)) select t).FirstOrDefault();
                if (CheckName != null && CheckName.programName != surveyQuestionVM.ProgramName)
                {
                    RenameProgram(userId, model.AId, surveyQuestionVM.ProgramName);
                }

                //if the question was not answered it doesnt get saved
                if (model.Value != null)
                {
                    //Save the Answer to the question just answered.
                    Answer previousAnswer = new Answer();
                    previousAnswer.QId         = model.QId;
                    previousAnswer.Value       = model.Value;
                    previousAnswer.programName = model.ProgramName;
                    previousAnswer.UId         = userId;
                    previousAnswer.AId         = model.AId;

                    //checks to see if the answer exists
                    Answer CheckAnswer = (from t in context.Answers where ((userId == t.UId) & (model.QId == t.QId) & (model.AId == t.AId)) select t).FirstOrDefault();
                    //if the answer exists use Put, otherwise use Post
                    if (CheckAnswer != null)
                    {
                        previousAnswer.Created = CheckAnswer.Created;
                        aController.PutAnswer(previousAnswer.UId, previousAnswer);
                    }
                    else
                    {
                        aController.PostAnswer(previousAnswer);
                    }
                }
            }
            //set up for the state of the buttons
            surveyQuestionVM.AnsweredQuestions = GetAnsweredList(userId, surveyQuestionVM.AId);
            surveyQuestionVM.DisableQuestion   = GetDisable(userId, surveyQuestionVM.AId, surveyQuestionVM.AnsweredQuestions);
            if (surveyQuestionVM.DisableQuestion != null)
            {
                DeleteAnswer(userId, surveyQuestionVM.AId, surveyQuestionVM.DisableQuestion);
            }
            surveyQuestionVM.QuestionText = eController.GetQuestionText(model.SkipTo);
            surveyQuestionVM.QId          = model.SkipTo;

            //checks to see if the next question has an answer already
            using (var context = new DBAContext())
            {
                Answer CheckAnswer = (from t in context.Answers where ((userId == t.UId) & (model.SkipTo == t.QId) & (model.AId == t.AId)) select t).FirstOrDefault();

                surveyQuestionVM.NumberofQuestions = eController.GetQuestionCount();

                //sets the value for the next answer to the answer that exists
                if (CheckAnswer != null)
                {
                    surveyQuestionVM.Value = CheckAnswer.Value;
                }
            }

            ModelState.Clear();

            return(View("SurveyQuestions", surveyQuestionVM));
        }