Beispiel #1
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/5/14                                                     //
        //------------------------------------------------------------------//
        // Authors: Joshua Boone and Justine Dinh                           //
        // Date: 4/14/14                                                    //
        // Deprecated                                                       //
        //------------------------------------------------------------------//
        /// <summary>Load a list of students from XML to local.</summary>
        /// <param name="studentList">List of student objects to be populated.
        /// </param>
        /// <param name="mainDrillList">List of drill objects</param>
        /// <param name="fileName">XML file name.</param>
        //private void LoadStudentXML(List<Student> studentList, List<Drill> mainDrillList, string fileName)
        //{
        //    XMLStudentDriver.LoadStudentXML(studentList, mainDrillList, fileName);
        //}
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/1/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Load a list of admins from XML to local.</summary>
        /// <param name="adminList">List of admin objects to be populated.
        /// </param>
        /// <param name="fileName">XML file name.</param>
        public void LoadAdminXML(List<Admin> adminList, string fileName)
        {
            XDocument adminXML = XDocument.Load(fileName);

            foreach (XElement admin in adminXML.Root.Nodes())
            {
                Admin administrator = new Admin();
                administrator.ID = Convert.ToInt32(admin.Attribute("ID").Value);
                administrator.FirstName = admin.Element("firstName").Value;
                administrator.LastName = admin.Element("lastName").Value;
                administrator.LoginName = admin.Element("loginName").Value;
                administrator.Password = admin.Element("password").Value;
                administrator.LastLogin = admin.Element("lastLogin").Value;
                administrator.FilePath = admin.Element("studentPath").Value;
                adminList.Add(administrator);
            }
        }
Beispiel #2
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/5/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Creating Admin XML for addition of first Admin.</summary>
        /// <param name="newAdminEntry">Admin object to be added.</param>
        /// <param name="adminXMLPath">Admin XML file path.</param>
        /// <param name="adminList">List of admin objects.</param>
        /// <returns>Boolean confirmation.</returns>
        public bool InitialCreateAdminXml(Admin newAdminEntry, string adminXMLPath, List<Admin> adminList)
        {
            XElement newAdmin = CreateAdminNode(newAdminEntry);

            newAdmin.SetAttributeValue("ID", "1");
            newAdminEntry.ID = Convert.ToInt32(newAdmin.Attribute("ID").Value);

            XDocument newAdminDoc =
                new XDocument(
                    new XElement("RaptorMathAdmin", newAdmin));

            newAdminDoc.Save(adminXMLPath);
            adminList.Add(newAdminEntry);
            return true;
        }
Beispiel #3
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/5/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Default creation of Admin XML file.</summary>
        /// <param name="AdminXMLPath">Admin XML file path.</param>
        /// <returns>Boolean confirmation.</returns>
        public bool InitialCreateAdminXml(string AdminXMLPath)
        {
            Admin DefaultAdmin = new Admin("Default", "Admin", "admin", DateTime.Now.ToString("M/d/yyyy"), "RaptopMathStudents.xml");
            DefaultAdmin.LoginName = DefaultAdmin.FirstName + " " + DefaultAdmin.LastName;
            DefaultAdmin.ID = 1;

            XElement newAdmin = CreateAdminNode(DefaultAdmin);
            newAdmin.SetAttributeValue("ID", DefaultAdmin.ID);

            XDocument newAdminDoc =
                new XDocument(
                    new XElement("RaptorMathAdmin", newAdmin));

            newAdminDoc.Save(AdminXMLPath);
            return true;
        }
Beispiel #4
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/5/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Delete an admin from Admin XML.</summary>
        /// <param name="admin">Admin object to be removed.</param>
        /// <param name="adminList">List of admin object.</param>
        /// <returns>Boolean confirmation.</returns>
        public bool Delete(Admin admin, List<Admin> adminList)
        {
            XDocument data = XDocument.Load(adminXMLPath);

            XElement adminElement = data.Descendants("admin").Where(s => s.Attribute("ID").Value.Equals(admin.ID.ToString())).FirstOrDefault();
            if (adminElement != null)
            {
                adminElement.Remove();
                data.Save(adminXMLPath);
                adminList.Remove(admin);
                return true;
            }
            return false;
        }
Beispiel #5
0
 //------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                //
 // Date: 4/5/14                                                     //
 //------------------------------------------------------------------//
 /// <summary>Edit admin data.</summary>
 /// <param name="newPassword">New password.</param>
 /// <param name="admin">Admin object.</param>
 /// <param name="adminList">List of admin objects.</param>
 /// <returns>Boolean success confirmation.</returns>
 public bool editAdmin(string newPassword, Admin admin, List<Admin> adminList)
 {
     if (admin != null)
     {
         if (newPassword.All(char.IsLetterOrDigit))
         {
             admin.Password = newPassword;
             UpdateAdmin(admin, adminXMLPath);
             return true;
         }
         else
             return false;
     }
     return false;
 }
Beispiel #6
0
 //------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                //
 // Date: 4/5/14                                                     //
 //------------------------------------------------------------------//
 /// <summary>Add an admin to admin XML.</summary>
 /// <param name="newAdmin">Admin object to be added.</param>
 /// <param name="adminList">List of admin objects.</param>
 /// <returns>Boolean confirmation.</returns>
 public bool AddUserToXML(Admin newAdmin, List<Admin> adminList)
 {
     return AddNewAdmin(newAdmin, adminXMLPath, adminList);
 }
Beispiel #7
0
 //------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                //
 // Date: 4/5/14                                                     //
 //------------------------------------------------------------------//
 /// <summary>Add an admin node to Admin XML.</summary>
 /// <param name="newAdmin">Admin object to be added.</param>
 /// <returns>XElement</returns>
 public XElement CreateAdminNode(Admin newAdmin)
 {
     XElement admin =
         new XElement("admin",
             new XElement("firstName", newAdmin.FirstName),
             new XElement("lastName", newAdmin.LastName),
             new XElement("loginName", newAdmin.LoginName),
             new XElement("password", newAdmin.Password),
             new XElement("studentPath", newAdmin.FilePath),
             new XElement("lastLogin", newAdmin.LastLogin));
     return admin;
 }
Beispiel #8
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/5/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Update admin XML.</summary>
        /// <param name="admin">Admin object.</param>
        /// <param name="adminXMLPath">Admin XML file path.</param>
        private void UpdateAdmin(Admin admin, string adminXMLPath)
        {
            XDocument data = XDocument.Load(adminXMLPath);

            XElement adminIDElement = data.Descendants("admin").Where(adm => adm.Attribute("ID").Value.Equals(admin.ID.ToString())).FirstOrDefault();

            if (adminIDElement != null)
            {
                adminIDElement.SetElementValue("password", admin.Password);
                data.Save(adminXMLPath);
            }
        }
Beispiel #9
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/5/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Adding a new admin to Admin XML.</summary>
        /// <param name="admin">Admin object to be added.</param>
        /// <param name="fileName">Admin XML file name.</param>
        /// <param name="adminList">List of admin objects.</param>
        /// <returns>Boolean confirmation.</returns>
        public bool AddNewAdmin(Admin admin, string fileName, List<Admin> adminList)
        {
            XDocument data = XDocument.Load(fileName);

            XElement AdminElement =
                data.Descendants("admin").Where(s => s.Element("loginName").Value == admin.LoginName).FirstOrDefault();
            if (AdminElement != null)
            {
                return false;
            }
            else
            {
                XElement newAdmin = CreateAdminNode(admin);

                newAdmin.SetAttributeValue("ID", GetNextAvailableID(fileName, "admin"));
                admin.ID = Convert.ToInt32(newAdmin.Attribute("ID").Value);

                data.Element("RaptorMathAdmin").Add(newAdmin);
                adminList.Add(admin);
                data.Save(fileName);
                return true;
            }
        }
Beispiel #10
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date:                                                   //
        //------------------------------------------------------------------//
        /// <summary>Load Admin XML file for access.</summary>
        /// <param name="adminList">List of admin objects.</param>
        /// <param name="fileName">Admin XML file path.</param>
        public void LoadAdminXML(List<Admin> adminList, string fileName )
        {
            XDocument adminXML = XDocument.Load(fileName);

            foreach (XElement admin in adminXML.Root.Nodes())
            {
                Admin administrator = new Admin();
                administrator.LoginName = admin.Element("loginName").Value;
                administrator.Password = admin.Element("password").Value;
                administrator.LastLogin = admin.Element("lastLogin").Value;
                administrator.FilePath = admin.Element("path").Value;
                adminList.Add(administrator);
            }
        }
Beispiel #11
0
        //----------------------------------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                                            //
        // Date: 4/3/14                                                                                 //
        //----------------------------------------------------------------------------------------------//
        /// <summary>Validate the administrator's info and then add the administrator to the admin XML
        /// </summary>
        /// <param name="adminFName">Admin's first name.</param>
        /// <param name="adminLName">Admin's last mame.</param>
        /// <param name="password">Admin's password.</param>
        /// <param name="LastLogin">Admin's last login date.</param>
        /// <param name="filePath">Admin XML filepath.</param>
        /// <returns>Boolean confirming creation success.</returns>
        public bool CreateUser(string adminFName, string adminLName, string password, string LastLogin, string filePath)
        {
            bool isCreatedUser = false;
            Admin newAdmin = new Admin(adminFName, adminLName, password, LastLogin, filePath);

            bool isUserInfoValid = isAdminInfoValid(newAdmin);
            if(isUserInfoValid)
                isCreatedUser = XMLDriver.AddUserToXML(newAdmin, adminList);

            return isCreatedUser;
        }
Beispiel #12
0
 //------------------------------------------------------------------//
 // Kyle Bridges                                                     //
 // Date: 2/27/2014                                                  //
 //------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                //
 // Date: 4/3/14                                                     //
 //------------------------------------------------------------------//
 /// <summary>Clears local data current admin object.</summary>
 public void ClearAdminUser()
 {
     if (currentAdmin != null)
     {
         currentAdmin.LastLogin = currentUserLogin;
         adminList.Add(currentAdmin);
         currentAdmin = new Admin(); // Clear admin
     }
 }
Beispiel #13
0
        //----------------------------------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                                            //
        // Date: 4/3/14                                                                                 //
        //----------------------------------------------------------------------------------------------//
        /// <summary>Establish current Admin.</summary>
        /// <param name="currentUser">Name of current user.</param>
        /// <returns>Boolean confirming success.</returns>
        private bool SetCurrentAdmin(string currentUser)
        {
            if (currentUser.Length > 8)
            {
                currentUser = currentUser.Remove(0, 8);
                currentAdmin = FindAdmin(currentUser);
            }
            if (currentAdmin != null)
            {
                currentUser = String.Concat("<Admin> ", currentUser);
                return true;
            }

            return false;
        }
Beispiel #14
0
 //----------------------------------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                                            //
 // Date: 4/3/14                                                                                 //
 //----------------------------------------------------------------------------------------------//
 /// <summary>Validation of admin data input.</summary>
 /// <param name="adminToValidate">Admin object to validate.</param>
 /// <returns>Boolean confirming validity.</returns>
 public bool isAdminInfoValid(Admin adminToValidate)
 {
     if (!(adminToValidate.FirstName.Equals(string.Empty))
         && (adminToValidate.FirstName.All(char.IsLetter))
         && !(adminToValidate.LastName.Equals(string.Empty))
         && (adminToValidate.LastName.All(char.IsLetter))
         && (adminToValidate.Password.All(char.IsLetterOrDigit))
         && (!studentList.Any(student => student.LoginName.Equals(adminToValidate.LoginName))))
     {
         return true;
     }
     return false;
 }