public HttpResponse CounselorStatus(string user)
        {
            string response;

            if (AuthTokens[0] != "demo")
            {
                CounselorAccountClient cac     = new CounselorAccountClient();
                CounselorAccount       account = cac.GetByPartitionAndRowKey("counselor", user);
                if (account != null)
                {
                    account.Active = !account.Active;
                    cac.Update(account);
                    response = "{\"result\": \"done\"}";
                }
                else
                {
                    response = "{\"result\": \"error\"}";
                }
            }
            else
            {
                response = "{\"result\": \"done\"}";
            }
            Response.ContentType = "application/json";
            Response.Write(response);
            Response.End();
            return(null);
        }
 public ActionResult Index(IEnumerable <string> year, IEnumerable <string> grade, IEnumerable <string> groupname)
 {
     if (AuthTokens[0] == "demo")
     {
         return(View());
     }
     if (year != null && grade != null && groupname != null)
     {
         if (year.Count() == grade.Count() && year.Count() == groupname.Count())
         {
             string counselor               = AuthTokens[1].ToLower();
             CounselorAccountClient cac     = new CounselorAccountClient();
             AccessCodeClient       acc     = new AccessCodeClient();
             CounselorAccount       account = cac.GetByPartitionAndRowKey("counselor", counselor);
             string school = account.School;
             for (var i = 0; i < year.Count(); i++)
             {
                 acc.AddNewItem(new AccessCode {
                     RowKey = ShortGuidGenerator.NewGuid(), Code = PinCodeGenerator.NewPin(), Year = year.ElementAt(i), Grade = grade.ElementAt(i), Counselor = counselor, GroupName = groupname.ElementAt(i), School = school
                 });
             }
             return(RedirectToAction("Index"));
         }
     }
     TempData["error"] = true;
     return(RedirectToAction("Index"));
 }
        public ActionResult ChangeRole(string counselor)
        {
            if (AuthTokens[0] == "demo")
            {
                return(RedirectToAction("Index", "AdminPortal"));;
            }
            string currentAdminEmail = AuthTokens[1];

            AdminAccountClient     aac = new AdminAccountClient();
            CounselorAccountClient cac = new CounselorAccountClient();
            UserAccountClient      uac = new UserAccountClient();
            SchoolAccountClient    sac = new SchoolAccountClient();

            AdminAccount     admin            = aac.GetByPartitionAndRowKey("admin", currentAdminEmail);
            CounselorAccount counselorAccount = cac.GetByPartitionAndRowKey("counselor", counselor);
            UserAccount      currentAdmin     = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(currentAdminEmail), currentAdminEmail);
            UserAccount      newAdmin         = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(counselor), counselor);
            SchoolAccount    school           = sac.GetByPartitionAndRowKey("school", admin.School);

            if (admin != null && counselorAccount != null && currentAdmin != null && newAdmin != null && school != null)
            {
                aac.AddNewItem(new AdminAccount {
                    RowKey = counselor, PhoneNumber = counselorAccount.PhoneNumber, PhoneExtension = counselorAccount.PhoneExtension, School = school.RowKey, SchoolSelected = true, ConnectionToSchoolConfirmed = true
                });
                cac.AddNewItem(new CounselorAccount {
                    RowKey = currentAdminEmail, PhoneNumber = admin.PhoneNumber, PhoneExtension = admin.PhoneExtension, School = school.RowKey
                });
                currentAdmin.ProfileType = "counselor";
                uac.Update(currentAdmin);
                newAdmin.ProfileType = "administrator";
                uac.Update(newAdmin);
                school.Admin = counselor;
                sac.Update(school);
                aac.Delete(admin);
                cac.Delete(counselorAccount);
            }
            return(RedirectToAction("LogOut", "Account"));
        }
        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"));
        }