public void DeleteTrainee(string id) { Trainee trainee_t = new Trainee(); if (Trainee_by_id(id) == false) { throw new Exception("Trainee " + id + " not exist"); } XElement trainee_XElement; try { trainee_XElement = (from stu in XMLDS.Trainees.Elements() where stu.Element("id").Value == id select stu).FirstOrDefault(); trainee_XElement.Remove(); XMLDS.SaveTrainees(); } catch { } }
public void AddTrainee(Trainee t) { bool flag = true; flag = Tester_by_id(t.Id); if (flag == true) { throw new Exception("Tester " + t.Id + " is Already exist!!"); } flag = Trainee_by_id(t.Id); if (flag == true) { throw new Exception("There is a trinee with id: " + t.Id + " is Already exist!!"); } try { //Create a new trinee path XElement id = new XElement("id", t.Id); XElement firstName = new XElement("firstName", t.Name); XElement lastName = new XElement("lastName", t.FamilyName); XElement name = new XElement("name", firstName, lastName); XElement BIRTH_DAY = new XElement("BIRTH_DAY", t.BrithDate); XElement City = new XElement("City", t.MyAddress.city); XElement Street = new XElement("Street", t.MyAddress.streetName); XElement Number = new XElement("Number", t.MyAddress.houseNumber); XElement Address = new XElement("Address", City, Street, Number); XElement Gear = new XElement("Gear", t.MyGear); XElement Gender = new XElement("Gender", t.MyGender); XElement Type_car = new XElement("Type_car", t.MyGear); XElement Teacher = new XElement("Teacher", t.TeacherName); XElement LESSONS = new XElement("LESSONS", t.NumberOfLessons); XElement SCHOOL = new XElement("SCHOOL", t.School); // XElement PhonePrefix = new XElement("phone_number", t.PhonePrefix); XElement phone_number = new XElement("phone_number", t.PhoneNumber); XElement Password = new XElement("Password", t.Password); XMLDS.Trainees.Add(new XElement("student", id, name, BIRTH_DAY, Address, Gear, Gender, Type_car, Teacher, LESSONS, SCHOOL, phone_number, Password)); XMLDS.SaveTrainees(); } catch { throw new Exception("Can't open trinees file"); } }
public void UpdateTrainee(Trainee t) { try { //Trainess_Root = XMLDS.Trainees; } catch (Exception) { } Trainee trainee_t = new Trainee(); try { XElement traineeElement = (from stu in XMLDS.Trainees.Elements() where (stu.Element("id").Value) == t.Id select stu).FirstOrDefault(); traineeElement.Element("BIRTH_DAY").Value = t.BrithDate.ToString(); traineeElement.Element("Gender").Value = t.MyGender.ToString(); traineeElement.Element("Type_car").Value = t.Car.ToString(); traineeElement.Element("Teacher").Value = t.TeacherName.ToString(); traineeElement.Element("LESSONS").Value = t.NumberOfLessons.ToString(); traineeElement.Element("SCHOOL").Value = t.School; traineeElement.Element("phone_number").Value = t.PhoneNumber; traineeElement.Element("Gear").Value = t.MyGear.ToString(); traineeElement.Element("Password").Value = t.Password; traineeElement.Element("name").Element("firstName").Value = t.Name; traineeElement.Element("name").Element("lastName").Value = t.FamilyName; traineeElement.Element("Address").Element("City").Value = t.MyAddress.city; traineeElement.Element("Address").Element("Street").Value = t.MyAddress.streetName; traineeElement.Element("Address").Element("Number").Value = t.MyAddress.houseNumber.ToString(); XMLDS.SaveTrainees(); } catch (Exception Ex) { throw new Exception(Ex.ToString()); } }