Example #1
0
        public ActionResult RemoveAdmin(AdminModel m)
        {
            if (m.UserEmail == null)
            {
                ViewBag.EmptyFielsAdnminEntry = "Must not leave any Admin entry fields blank. Try again.";
                return(View("DeleteAdmin", m));
            }

            if (m.UserEmail == AbstractDatabase.AdminEmail)
            {
                ViewBag.InvalidEmail = "Cannot remove that admin. Try again.";
                return(View("DeleteAdmin", m));
            }

            if (m.UserEmail.Length > 100)
            {
                ViewBag.InvalidEmail = "Email too long. Try again.";
                return(View("DeleteAdmin", m));
            }

            grabFromDB DB = new grabFromDB();

            //check if valid user
            if (DB.getAdminByEmail(m.UserEmail).Count == 0)
            {
                ViewBag.InvalidEmail = "This email is not associated with a current admin. Try again.";
                return(View("DeleteAdmin", m));
            }
            else
            {
                DB.removeAdminByEmail(m.UserEmail);
                ViewBag.ReturnValue = "Admin successfully removed.";
                return(View("AdminPage"));
            }
        }
Example #2
0
        public ActionResult AdminEntry(AdminModel m)
        {
            //check for blank entries
            if (m.UserEmail == null || m.Role == null)
            {
                ViewBag.EmptyFielsAdnminEntry = "Must not leave any Admin entry fields blank. Try again.";
                return(View("AddAdmin", m));
            }

            if (m.UserEmail.Length > 100)
            {
                ViewBag.InvalidEmail = "Email too long. Try again.";
                return(View("AddAdmin", m));
            }

            if (m.Role.Length > 200)
            {
                ViewBag.InvalidRole = "Role too long. Try again.";
                return(View("AddAdmin", m));
            }

            grabFromDB DB = new grabFromDB();

            if (DB.getAdminByEmail(m.UserEmail).Count != 0)
            {
                ViewBag.InvalidEmail = "The user associated with this account is already an admin. Try again.";
                return(View("AddAdmin", m));
            }

            //check if valid user
            if (DB.getUserListByEmail(m.UserEmail).Count == 0)
            {
                ViewBag.InvalidEmail = "This email is not associated with a current account. Try again.";
                return(View("AddAdmin", m));
            }
            else
            {
                DB.insertAdmin(m.UserEmail, m.Role);
                ViewBag.ReturnValue = "Admin successfully added.";
                return(View("AdminPage"));
            }
        }