public ActionResult Report(string id)
        {
            if (id != null && id != "")
            {
                StudentAccountClient sac     = new StudentAccountClient();
                StudentAccount       student = sac.GetByPartitionAndRowKey(StudentAccountClient.GetPartitionKeyForEmail(id), id);

                //StudentProfileClient spc = new StudentProfileClient();
                //StudentProfile student = spc.GetByPartitionAndRowKey(StudentProfileClient.GetPartitionKeyForEmail(id), id);
                if (student != null && AuthTokens[3] == "administrator" && student.Counselor == AuthTokens[1])
                {
                    UserAccountClient uac     = new UserAccountClient();
                    UserAccount       account = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(id), id);
                    // ViewBag.StudentName = account.FirstName + " " + account.LastName;
                    ViewBag.StudentFirstName = account.FirstName;
                    ViewBag.StudentLastName  = account.LastName;
                    ViewBag.StudentToShow    = id;
                }
            }
            else if (AuthTokens[3] == "administrator")
            {
                return(RedirectToAction("Assessment", "Index"));
            }
            return(View());
        }
        public ActionResult ConfirmEmail(string id)
        {
            if (id != null)
            {
                SimpleAES         aes     = new SimpleAES();
                string            email   = aes.DecryptString(id);
                UserAccountClient uac     = new UserAccountClient();
                UserAccount       account = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(email), email);
                if (account != null)
                {
                    account.EmailConfirmed = true;
                    uac.Update(account);
                    if (account.ProfileType == "student")
                    {
                        StudentAccountClient sac     = new StudentAccountClient();
                        StudentAccount       student = sac.GetByPartitionAndRowKey(StudentAccountClient.GetPartitionKeyForEmail(account.Email), account.Email);

                        //StudentProfileClient spc = new StudentProfileClient();
                        //StudentProfile student = spc.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(account.Email), account.Email);
                        string sessionkey = ClientSession.GetClientSessionKey("user", account.Email, account.FirstName + " " + account.LastName, "student");
                        Response.Cookies["sessionkey"].Value        = sessionkey;
                        Response.Cookies["sessionkey"].Expires      = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["sessionusername"].Value   = account.Email;
                        Response.Cookies["sessionusername"].Expires = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["firstname"].Value         = account.FirstName;
                        Response.Cookies["firstname"].Expires       = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["lastname"].Value          = account.LastName;
                        Response.Cookies["lastname"].Expires        = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["email"].Value             = account.Email;
                        Response.Cookies["email"].Expires           = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["gender"].Value            = student.Gender;
                        Response.Cookies["gender"].Expires          = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["cbnvm"].Value             = "1";
                        Response.Cookies["cbnvm"].Expires           = DateTime.UtcNow.AddDays(7);
                        SendCongratulationsEmailToStudent(account.Email, account.FirstName);
                        return(RedirectToAction("Index", "StudentPortal"));
                    }
                    else if (account.ProfileType == "administrator")
                    {
                        string sessionkey = ClientSession.GetClientSessionKey("user", account.Email, account.FirstName + " " + account.LastName, "administrator");
                        Response.Cookies["sessionkey"].Value        = sessionkey;
                        Response.Cookies["sessionkey"].Expires      = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["sessionusername"].Value   = account.Email;
                        Response.Cookies["sessionusername"].Expires = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["cbnvm"].Value             = "1";
                        Response.Cookies["cbnvm"].Expires           = DateTime.UtcNow.AddDays(7);
                        SendCongratulationsEmailToAdmin(account.Email, account.FirstName + " " + account.LastName);
                        return(RedirectToAction("AddSchool", "AdminPortal"));
                    }
                    return(View());
                }
                else
                {
                    ViewBag.ErrorMessage = "No account found";
                }
            }
            return(RedirectToAction("LogIn"));
        }
        public ActionResult RateInterests()
        {
            string user = AuthTokens[1];
            StudentAccountClient sac     = new StudentAccountClient();
            StudentAccount       student = sac.GetByPartitionAndRowKey(StudentAccountClient.GetPartitionKeyForEmail(user), user);

            //StudentProfileClient spc = new StudentProfileClient();
            //StudentProfile student = spc.GetByPartitionAndRowKey(StudentProfileClient.GetPartitionKeyForEmail(user), user);
            ViewBag.School          = student.School;
            ViewBag.Year            = student.Year;
            ViewBag.Grade           = student.Grade;
            ViewBag.importantThings = importantThings;
            return(View());
        }
        public ActionResult Index(string grade, string accesscode, string zipcode)
        {
            string user = AuthTokens[1];

            StudentAccountClient sac        = new StudentAccountClient();
            StudentAccount       student    = sac.GetByPartitionAndRowKey(StudentAccountClient.GetPartitionKeyForEmail(user), user);
            AccessCodeClient     acc        = new AccessCodeClient();
            AccessCode           accessCode = acc.GetByPinCodeAndGradeCurrent(accesscode, grade);

            if (accessCode != null)
            {
                if (student.Active)
                {
                    if (student.School != accessCode.School)
                    {
                        TempData["message"] = "You still have an active status in another school";
                    }
                    else if (student.Year == accessCode.Year)
                    {
                        TempData["message"] = "You already updated your information with new access code this year";
                    }
                    else
                    {
                        student.Year               = accessCode.Year;
                        student.Grade              = accessCode.Grade;
                        student.Counselor          = accessCode.Counselor;
                        student.GroupName          = accessCode.GroupName;
                        student.AssessmentComplete = false;
                        student.RatedCareers       = 0;
                        student.RatedDimensions    = 0;
                        student.RatedInterests     = 0;
                        sac.Update(student);
                        TempData["successmessage"] = "Your information was updated for this year";
                    }
                }
                else
                {
                    if (student.School != accessCode.School)
                    {
                        student.School             = accessCode.School;
                        student.Year               = accessCode.Year;
                        student.Grade              = accessCode.Grade;
                        student.Counselor          = accessCode.Counselor;
                        student.GroupName          = accessCode.GroupName;
                        student.AssessmentComplete = false;
                        student.RatedCareers       = 0;
                        student.RatedDimensions    = 0;
                        student.RatedInterests     = 0;
                        sac.Update(student);
                        TempData["successmessage"] = "Your information and school was updated for this year";
                    }
                    else
                    {
                        TempData["message"] = "Your account was marked as inactive";
                    }
                }
            }
            else
            {
                TempData["message"] = "Access link you used is invalid or expired";
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult LogIn(FormCollection collection)
        {
            string            accessurl = collection["accessurl"];
            UserAccountClient uac       = new UserAccountClient();
            UserAccount       account   = uac.Logon(collection["email"].ToLower(), collection["password"]);

            if (account == null)
            {
                if (accessurl != null)
                {
                    ViewBag.AccessCode = accessurl;
                }
                ViewBag.InvalidEmail = collection["email"].ToLower();
                return(View());
            }
            else if (account.EmailConfirmed == false)
            {
                ViewBag.VerifyEmail             = collection["email"].ToLower();
                ViewBag.ResendConfirmationEmail = true;
                return(View());
            }
            if (account.ProfileType == "su")
            {
                SaveSessionCookie(collection["email"].ToLower(), account.FirstName + " " + account.LastName, account.ProfileType);
            }
            else if (account.ProfileType == "administrator")
            {
                AdminAccountClient aac   = new AdminAccountClient();
                AdminAccount       admin = aac.GetByPartitionAndRowKey("admin", account.RowKey);
                SaveSessionCookie(collection["email"].ToLower(), account.FirstName + " " + account.LastName, account.ProfileType);
                if (admin.SchoolSelected)
                {
                    return(RedirectToAction("Index", "AdminPortal"));
                }
                else
                {
                    return(RedirectToAction("AddSchool", "AdminPortal"));
                }
            }
            else if (account.ProfileType == "counselor")
            {
                CounselorAccountClient cac       = new CounselorAccountClient();
                CounselorAccount       counselor = cac.GetByPartitionAndRowKey("counselor", account.RowKey);
                if (counselor.Active)
                {
                    SaveSessionCookie(collection["email"].ToLower(), account.FirstName + " " + account.LastName, account.ProfileType);
                    return(RedirectToAction("Index", "CounselorPortal"));
                }
                else
                {
                    ViewBag.ErrorMessage = "Not Active";
                    return(View());
                }
            }
            else if (account.ProfileType == "student")
            {
                StudentAccountClient sac        = new StudentAccountClient();
                StudentAccount       student    = sac.GetByPartitionAndRowKey(StudentAccountClient.GetPartitionKeyForEmail(account.Email), account.Email);
                AccessCodeClient     acc        = new AccessCodeClient();
                AccessCode           accessCode = acc.GetByPartitionAndRowKey("accesscode", accessurl);
                if (accessCode != null && accessCode.Year == AccessCodeClient.CurrentGradYear())
                {
                    if (student.Active)
                    {
                        if (student.School != accessCode.School)
                        {
                            TempData["activeschool"] = true;
                        }
                        else if (student.Year == accessCode.Year)
                        {
                            TempData["sameyear"] = true;
                        }
                        else
                        {
                            student.Year               = accessCode.Year;
                            student.Grade              = accessCode.Grade;
                            student.Counselor          = accessCode.Counselor;
                            student.GroupName          = accessCode.GroupName;
                            student.AssessmentComplete = false;
                            sac.Update(student);
                        }
                    }
                    else
                    {
                        if (student.School != accessCode.School)
                        {
                            student.School             = accessCode.School;
                            student.Year               = accessCode.Year;
                            student.Grade              = accessCode.Grade;
                            student.Counselor          = accessCode.Counselor;
                            student.GroupName          = accessCode.GroupName;
                            student.AssessmentComplete = false;
                            sac.Update(student);
                        }
                        else
                        {
                            TempData["inactive"] = true;
                        }
                    }
                }
                else
                {
                    TempData["invalid"] = true;
                }
                SaveSessionCookie(collection["email"].ToLower(), account.FirstName + " " + account.LastName, account.ProfileType);
                //StudentProfileClient spc = new StudentProfileClient();
                //StudentProfile student = spc.GetByPartitionAndRowKey(StudentProfileClient.GetPartitionKeyForEmail(account.Email), account.Email);
                Response.Cookies["firstname"].Value   = account.FirstName;
                Response.Cookies["firstname"].Expires = DateTime.UtcNow.AddDays(7);
                Response.Cookies["lastname"].Value    = account.LastName;
                Response.Cookies["lastname"].Expires  = DateTime.UtcNow.AddDays(7);
                Response.Cookies["email"].Value       = account.Email;
                Response.Cookies["email"].Expires     = DateTime.UtcNow.AddDays(7);
                Response.Cookies["gender"].Value      = student.Gender;
                Response.Cookies["gender"].Expires    = DateTime.UtcNow.AddDays(7);
                Response.Cookies["clr"].Value         = "1";
                Response.Cookies["clr"].Expires       = DateTime.UtcNow.AddDays(7);
                Response.Cookies["cbnvm"].Value       = "1";
                Response.Cookies["cbnvm"].Expires     = DateTime.UtcNow.AddDays(7);

                AssessmentDimensionClient adc = new AssessmentDimensionClient();
                AssessmentInterestClient  aic = new AssessmentInterestClient();

                //AssessmentDimensionsRatingClient adrc = new AssessmentDimensionsRatingClient();
                //AssessmentInterestRatingClient airc = new AssessmentInterestRatingClient();
                JavaScriptSerializer      jss = new JavaScriptSerializer();
                List <AssessmentInterest> importantThingRatings = new List <AssessmentInterest>(aic.GetAllCurrentByStudent(student.School, account.RowKey, student.Year, student.Grade));
                //List<AssessmentInterestRating> importantThingRatings = new List<AssessmentInterestRating>(airc.GetAllBySchoolAndStudent(student.School, account.RowKey));
                Response.Cookies["interests"].Value   = jss.Serialize(importantThingRatings.Where(x => x.Value == "1").Select(x => x.Interest).ToList());
                Response.Cookies["interests"].Expires = DateTime.UtcNow.AddDays(7);
                for (var i = 0; i < dimensions.Length; i++)
                {
                    //AssessmentDimensionsRating dimensionsRating = adrc.GetByPartitionAndRowKey(student.School, account.Email + dimensions[i]);
                    AssessmentDimension dimensionsRating = adc.GetByPartitionAndRowKey(student.School, account.Email + student.Year + student.Grade + dimensions[i]);
                    if (dimensionsRating != null)
                    {
                        Response.Cookies[dimensions[i]].Value   = dimensionsRating.Value;
                        Response.Cookies[dimensions[i]].Expires = DateTime.UtcNow.AddDays(7);
                        if (i == 0)
                        {
                            Response.Cookies["question1"].Value   = (dimensionsRating.Misc != null ? dimensionsRating.Misc : dimensionsRating.Value);
                            Response.Cookies["question1"].Expires = DateTime.UtcNow.AddDays(7);
                        }
                    }
                }
                return(RedirectToAction("Index", "StudentPortal"));
            }
            return(RedirectToAction("Index", "Home"));
        }