public void SaveInterest(string user, string interest, string rating)
        {
            StudentAccountClient sac     = new StudentAccountClient();
            StudentAccount       student = sac.GetByPartitionAndRowKey(StudentAccountClient.GetPartitionKeyForEmail(user), user);

            if (student != null)
            {
                AssessmentInterestClient aic            = new AssessmentInterestClient();
                AssessmentInterest       interestRating = aic.GetByPartitionAndRowKey(student.School, user + student.Year + student.Grade + interest);
                if (interestRating == null)
                {
                    aic.AddNewItem(new AssessmentInterest {
                        PartitionKey = student.School, RowKey = user + student.Year + student.Grade + interest, Value = rating, Counselor = student.Counselor, Student = user, Grade = student.Grade, GroupName = student.GroupName, Interest = interest, Year = student.Year
                    });
                    //airc.AddNewItem(new AssessmentInterestRating { PartitionKey = student.School, RowKey = user + interest, Rating = rating, GradYear = student.GradYear, Student = user, Teacher = student.Teacher, Group = student.Group });
                }
                else
                {
                    interestRating.Value = rating;
                    aic.Update(interestRating);
                }
            }

            //StudentProfileClient spc = new StudentProfileClient();
            //StudentProfile student = spc.GetByPartitionAndRowKey(StudentProfileClient.GetPartitionKeyForEmail(user), user);
            //AssessmentInterestRatingClient airc = new AssessmentInterestRatingClient();
            //AssessmentInterestRating interestRating = airc.GetByPartitionAndRowKey(student.School, user + interest);
        }
        public ActionResult Index()
        {
            string user = AuthTokens[1];

            StudentAccountClient      sac     = new StudentAccountClient();
            StudentAccount            student = sac.GetByPartitionAndRowKey(StudentAccountClient.GetPartitionKeyForEmail(user), user);
            AssessmentInterestClient  aic     = new AssessmentInterestClient();
            List <AssessmentInterest> importantThingRatings = new List <AssessmentInterest>(aic.GetAllCurrentByStudent(student.School, user, student.Year, student.Grade));
            AssessmentCareerClient    acc           = new AssessmentCareerClient();
            List <AssessmentCareer>   careerRatings = new List <AssessmentCareer>(acc.GetAllCurrentByStudent(student.School, user, student.Year, student.Grade));

            //StudentProfileClient spc = new StudentProfileClient();
            //StudentProfile student = spc.GetByPartitionAndRowKey(StudentProfileClient.GetPartitionKeyForEmail(user), user);
            //AssessmentInterestRatingClient airc = new AssessmentInterestRatingClient();
            //List<AssessmentInterestRating> importantThingRatings = new List<AssessmentInterestRating>(airc.GetAllBySchoolAndStudent(student.School, user));
            //AssessmentCareerRatingClient acrc = new AssessmentCareerRatingClient();
            //List<AssessmentCareerRating> careerRatings = new List<AssessmentCareerRating>(acrc.GetAllBySchoolAndStudent(student.School, user));
            ViewBag.CareersRated = careerRatings.Count == 0 ? "no" : "yes";
            ViewBag.School       = student.School;
            JavaScriptSerializer jss = new JavaScriptSerializer();

            ViewBag.interestsRated = jss.Serialize(importantThingRatings.Where(x => x.Value == "1").Select(x => x.Interest).ToList());
            if (importantThingRatings.Where(x => x.Value == "1").ToList().Count == 3)
            {
                ViewBag.ImportantThings = "yes";
            }
            else
            {
                ViewBag.ImportantThings = "no";
            }
            if (TempData["message"] != null)
            {
                ViewBag.Message = TempData["message"];
            }
            if (TempData["successmessage"] != null)
            {
                ViewBag.Successmessage = TempData["successmessage"];
            }
            ViewBag.UpdateAccessCode = student.Year != AccessCodeClient.CurrentGradYear();
            return(View());
        }
        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"));
        }