Пример #1
0
        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 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"));
        }