public ActionResult Administrator(FormCollection collection)
        {
            UserAccountClient uac     = new UserAccountClient();
            UserAccount       account = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(collection["email"].ToLower()), collection["email"].ToLower());

            if (account == null)
            {
                uac.AddNewItem(new UserAccount {
                    PartitionKey = UserAccountClient.GetPartitionKeyForEmail(collection["email"].ToLower()), RowKey = collection["email"].ToLower(), FirstName = collection["firstname"], LastName = collection["lastname"], Email = collection["email"], Password = collection["password"], ProfileType = "administrator"
                });

                //AdminProfileClient apc = new AdminProfileClient();
                //apc.AddNewItem(new AdminProfile { RowKey = collection["email"].ToLower(), PhoneNumber = collection["phonenumber"] });

                AdminAccountClient aac = new AdminAccountClient();
                aac.AddNewItem(new AdminAccount {
                    RowKey = collection["email"].ToLower(), PhoneNumber = collection["phonenumber"], PhoneExtension = collection["extension"]
                });
            }
            else
            {
                ViewBag.ErrorMessage = "There is an account already associated with this email. Please log in instead.";
                return(View());
            }

            SendVerificationEmail(collection["email"].ToLower(), collection["firstname"]);

            EmailManager emailManager = new EmailManager();
            string       str          = "<p>Full name: " + collection["firstname"] + " " + collection["lastname"] + "</p><p>Email: " + collection["email"] + "</p><p>Phone Number: " + collection["phonenumber"] + "</p><p>" + collection["extension"] + "</p>";

            emailManager.SendMail("*****@*****.**", "Admin", "*****@*****.**", "HS Admin", str);
            return(RedirectToAction("ThankYou"));
        }
        public ActionResult Student(FormCollection collection)
        {
            UserAccountClient uac     = new UserAccountClient();
            UserAccount       account = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(collection["email"].ToLower()), collection["email"]);

            if (account == null)
            {
                AccessCodeClient aac  = new AccessCodeClient();
                AccessCode       code = aac.GetBySchoolPinCodeCounselorGrade(collection["school"], collection["accesscode"], collection["counselor"], collection["grade"]);

                if (code == null || code.School == "7181234567")
                {
                    ViewBag.ErrorMessage = "Invalid fields";
                    return(RedirectToAction("Index"));
                }

                uac.AddNewItem(new UserAccount {
                    PartitionKey = UserAccountClient.GetPartitionKeyForEmail(collection["email"].ToLower()), RowKey = collection["email"].ToLower(), FirstName = collection["firstname"], LastName = collection["lastname"], Email = collection["email"], Password = collection["password"], ProfileType = "student"
                });

                StudentAccountClient sac = new StudentAccountClient();
                sac.AddNewItem(new StudentAccount {
                    PartitionKey = StudentAccountClient.GetPartitionKeyForEmail(collection["email"].ToLower()), RowKey = collection["email"].ToLower(), Gender = collection["gender"], StudentID = collection["studentid"], School = collection["school"], Counselor = collection["counselor"], Year = code.Year, Grade = collection["grade"], GroupName = code.GroupName
                });

                //StudentProfileClient spc = new StudentProfileClient();
                //spc.AddNewItem(new StudentProfile { PartitionKey = StudentProfileClient.GetPartitionKeyForEmail(collection["email"]), RowKey = collection["email"].ToLower(), Gender = collection["gender"], GradYear = collection["gradyear"], School = school, SchoolZip = collection["zipcode"], Teacher = teacher, Group = group });
            }
            else
            {
                ViewBag.ErrorMessage = "There is an account already associated with this email. Please log in instead.";
                return(View());
            }

            SendVerificationEmail(collection["email"].ToLower(), collection["firstname"]);

            SchoolAccountClient saclient      = new SchoolAccountClient();
            SchoolAccount       schoolAccount = saclient.GetByPartitionAndRowKey("school", collection["school"]);
            UserAccount         adminAccount  = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(collection["counselor"]), collection["counselor"]);
            EmailManager        emailManager  = new EmailManager();
            string str = "<p>Full name: " + collection["firstname"] + " " + collection["lastname"] + "</p><p>Email: " + collection["email"].ToLower() + "</p><p>School: " + (schoolAccount != null ? schoolAccount.SchoolName : "") + "</p><p>Counselor: " + (adminAccount != null ? adminAccount.FirstName + " " + adminAccount.LastName : "") + "</p><p>Grade: " + collection["grade"] + "</p><p>Year: " + collection["year"] + "</p>";

            emailManager.SendMail("*****@*****.**", "Admin", "*****@*****.**", "HS Student", str);
            return(RedirectToAction("Complete"));
        }
        public ActionResult Counselor(FormCollection collection)
        {
            string                adminEmail = "";
            UserAccountClient     uac        = new UserAccountClient();
            CounselorInviteClient cic        = new CounselorInviteClient();
            SchoolAccountClient   sac        = new SchoolAccountClient();
            UserAccount           account    = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(collection["email"].ToLower()), collection["email"].ToLower());
            CounselorInvite       invite     = cic.GetByPartitionAndRowKey("invite", collection["invite"]);
            SchoolAccount         school     = sac.GetByPartitionAndRowKey("school", collection["school"]);

            if (invite != null)
            {
                if (invite.Email == collection["email"].ToLower())
                {
                    if (account == null)
                    {
                        uac.AddNewItem(new UserAccount {
                            PartitionKey = UserAccountClient.GetPartitionKeyForEmail(collection["email"].ToLower()), RowKey = collection["email"].ToLower(), FirstName = collection["firstname"], LastName = collection["lastname"], Email = collection["email"], Password = collection["password"], ProfileType = "counselor", EmailConfirmed = true
                        });
                        CounselorAccountClient сac   = new CounselorAccountClient();
                        AdminAccountClient     aac   = new AdminAccountClient();
                        AdminAccount           admin = aac.GetBySchool(collection["school"]);
                        if (admin != null)
                        {
                            adminEmail = admin.RowKey;
                        }
                        сac.AddNewItem(new CounselorAccount {
                            RowKey = collection["email"].ToLower(), PhoneNumber = collection["phonenumber"], PhoneExtension = collection["extension"], School = collection["school"]
                        });
                        cic.Delete(invite);
                    }
                    else
                    {
                        ViewBag.Invite       = invite;
                        ViewBag.ErrorMessage = "There is an account already associated with this email. Please log in instead.";
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Invite     = invite;
                    ViewBag.EmailMatch = "Email has to match";
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }

            string sessionkey = ClientSession.GetClientSessionKey("user", collection["email"].ToLower(), collection["firstname"] + " " + collection["lastname"], "counselor");

            Response.Cookies["sessionkey"].Value        = sessionkey;
            Response.Cookies["sessionkey"].Expires      = DateTime.UtcNow.AddDays(7);
            Response.Cookies["sessionusername"].Value   = collection["email"].ToLower();
            Response.Cookies["sessionusername"].Expires = DateTime.UtcNow.AddDays(7);
            Response.Cookies["cbnvm"].Value             = "1";
            Response.Cookies["cbnvm"].Expires           = DateTime.UtcNow.AddDays(7);
            SendCongratulationsEmailToCounselor(collection["email"], collection["firstname"] + " " + collection["lastname"]);
            SendUpdateEmailToAdmin(adminEmail, collection["firstname"] + " " + collection["lastname"]);

            EmailManager emailManager = new EmailManager();
            string       schooStr     = "";

            if (school != null)
            {
                schooStr = "<p>School name: " + school.SchoolName + "</p>";
            }
            string str = "<p>Full name: " + collection["firstname"] + " " + collection["lastname"] + "</p><p>Email: " + collection["email"] + "</p><p>Phone Number: " + collection["phonenumber"] + "</p><p>" + collection["extension"] + "</p>" + schooStr;

            emailManager.SendMail("*****@*****.**", "Admin", "*****@*****.**", "HS Counselor", str);
            TempData["counselor"] = true;
            return(RedirectToAction("Index", "CounselorPortal"));
        }