示例#1
0
        //public EmployeesModel GetStudentByID(int id)
        //{
        //    return allStudents.Find(item => item.ID == id);
        //}

        public void InsertEmployeesModel(EmployeesModel employee)
        {
            employee.ID = (int)(from S in EmployeesData.Descendants("employee") orderby(int) S.Element("ID") descending select(int) S.Element("ID")).FirstOrDefault() + 1;

            EmployeesData.Root.Add(new XElement("employee", new XElement("ID", employee.ID),
                                                new XElement("first_name", employee.First_Name),
                                                new XElement("last_name", employee.Last_Name),
                                                new XElement("email", employee.Email),
                                                new XElement("dob", employee.Dob.Date.ToShortDateString()),
                                                new XElement("gender", employee.Gender),
                                                new XElement("address", employee.Address),
                                                new XElement("city", employee.City),
                                                new XElement("state", employee.State),
                                                new XElement("pin", employee.Pin)));

            EmployeesData.Save(HttpContext.Current.Server.MapPath("~/App_Data/employeedata.xml"));
        }
示例#2
0
        public void EditEmployeesModel(EmployeesModel employee)
        {
            try
            {
                XElement node = EmployeesData.Root.Elements("employee").Where(i => (int)i.Element("ID") == employee.ID).FirstOrDefault();

                node.SetElementValue("first_name", employee.First_Name);
                node.SetElementValue("last_name", employee.Last_Name);
                node.SetElementValue("email", employee.Email);
                node.SetElementValue("dob", employee.Dob.ToShortDateString());
                node.SetElementValue("gender", employee.Gender);

                node.SetElementValue("address", employee.Address);
                node.SetElementValue("city", employee.City);
                node.SetElementValue("state", employee.State);
                node.SetElementValue("pin", employee.Pin);
                EmployeesData.Save(HttpContext.Current.Server.MapPath("~/App_Data/employeedata.xml"));
            }
            catch (Exception)
            {
                throw new NotImplementedException();
            }
        }