public void SaveDimension(string user, string dimension, string value, string misc)
        {
            StudentAccountClient sac     = new StudentAccountClient();
            StudentAccount       student = sac.GetByPartitionAndRowKey(StudentAccountClient.GetPartitionKeyForEmail(user), user);

            if (student != null)
            {
                AssessmentDimensionClient adc             = new AssessmentDimensionClient();
                AssessmentDimension       dimensionRating = adc.GetByPartitionAndRowKey(student.School, user + student.Year + student.Grade + dimension);
                if (dimensionRating == null)
                {
                    student.RatedDimensions++;
                    sac.Update(student);
                    adc.AddNewItem(new AssessmentDimension {
                        PartitionKey = student.School, RowKey = user + student.Year + student.Grade + dimension, Value = value, Misc = misc, Counselor = student.Counselor, Student = user, Grade = student.Grade, GroupName = student.GroupName, Dimension = dimension, Year = student.Year
                    });
                    //adrc.AddNewItem(new AssessmentDimensionsRating { PartitionKey = student.School, RowKey = user + dimension, Dimension = dimension, Value = value, Misc = misc, GradYear = student.GradYear, Student = student.RowKey, Teacher = student.Teacher, Group = student.Group });
                }
                else
                {
                    dimensionRating.Value = value;
                    dimensionRating.Misc  = misc;
                    adc.Update(dimensionRating);
                }
            }

            //StudentProfileClient spc = new StudentProfileClient();
            //StudentProfile student = spc.GetByPartitionAndRowKey(StudentProfileClient.GetPartitionKeyForEmail(user), user);
            //AssessmentDimensionsRatingClient adrc = new AssessmentDimensionsRatingClient();
            //AssessmentDimensionsRating dimensionRating = adrc.GetByPartitionAndRowKey(student.School, user + dimension);
        }
        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"));
        }