コード例 #1
0
        /// <summary>
        /// remove staff member
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public bool removeStaffMember(string userName, string password, string role)
        {
            StaffMember stfmem          = new StaffMember(userName, password, role);
            XDocument   xmlDoc          = XDocument.Load(staffXmlpath + @"\StaffMembers.xml");
            var         elementToDelete = from elem in xmlDoc.Elements("StaffMembers").Elements("StaffMember")
                                          where elem != null &&
                                          elem.Element("username").Value.Equals(stfmem.StaffUserName) &&
                                          elem.Element("password").Value.Equals(stfmem.StaffPassword) &&
                                          elem.Element("role").Value.Equals(stfmem.StaffRole)
                                          select elem;

            foreach (var e in elementToDelete)
            {
                e.Remove();
            }
            xmlDoc.Save(staffXmlpath + @"\StaffMembers.xml");
            return(true);
        }
コード例 #2
0
        // string staffXmlpath = HttpRuntime.AppDomainAppPath + "/DataAccessLayer/Database/";

        /// <summary>
        /// Setup the initial staff db
        /// </summary>
        public void setupStaffDB()
        {
            StaffMember[] staffMembers = new StaffMember[] {
                new StaffMember("managerTest1", "password", "manager"),
                new StaffMember("managerTest2", "password", "manager"),
                new StaffMember("clerkTest1", "password", "clerk"),
                new StaffMember("clerkTest2", "password", "clerk"),
                new StaffMember("clerkTest3", "password", "clerk")
            };

            IEnumerable <XElement> xml = from staffMember in staffMembers
                                         select new XElement(
                "StaffMember", new XAttribute("role", staffMember.StaffRole),
                new XElement("username", staffMember.StaffUserName),
                new XElement("password", staffMember.StaffPassword)
                );

            //create new xml doument
            XElement xmldoc = new XElement("StaffMembers", xml);

            xmldoc.Save(staffXmlpath + @"\StaffMembers.xml");
        }