//Returns all boats of the specific member public List <Boat> getMemberBoats(string personalNumber) { XDocument doc = XDocument.Load("..\\..\\Model\\storage.xml"); IEnumerable <XElement> elements = (from x in doc.Root.Elements() where x.Attribute("personal_id").Value == personalNumber select x); XElement xEle = elements.First(); IEnumerable <XElement> boats = (from x in xEle.Elements() select x); List <Boat> memberBoats = new List <Boat>(); if (boats.Any()) { foreach (XElement boatElement in boats) { string length = boatElement.Attribute("length").Value; string temp1 = boatElement.Attribute("type").Value; Boat.boats_type type = (Boat.boats_type)Enum.Parse(typeof(Boat.boats_type), temp1); String temp2 = boatElement.Attribute("boatID").Value; Guid boat_id = Guid.Parse(temp2); Boat boat = new Boat(boatElement.Attribute("name").Value, Int32.Parse(length), type, boat_id); memberBoats.Add(boat); } } return(memberBoats); }
//Returns a boat of a specific member public Boat getBoat(string personalNumber, string boatName) { XDocument doc = XDocument.Load("..\\..\\Model\\storage.xml"); IEnumerable <XElement> elements = (from x in doc.Root.Elements() where x.Attribute("personal_id").Value == personalNumber select x); XElement xEle = elements.First(); IEnumerable <XElement> boats = (from x in xEle.Elements() where x.Attribute("name").Value == boatName select x); if (boats.Any()) { XElement boatElement = boats.First(); String length = boatElement.Attribute("length").Value; String type = boatElement.Attribute("type").Value; Boat.boats_type t = (Boat.boats_type)Enum.Parse(typeof(Boat.boats_type), type); Boat b = new Boat(boatElement.Attribute("name").Value, Int32.Parse(length), t); } else { throw new Exception("There is no boat for this member in the system"); } return(null); }