public bool updateBoat(Member member, int boatsToBeSkipped, Boat boatToAdd) { try { XElement xElement = XElement.Load(XMLFileInfo.Path); XElement memberToUpdate = (from Member in xElement.Elements(XMLFileInfo.Member) where (string)Member.Element(XMLFileInfo.ID) == member.MemberID.ToString() select Member).First(); XElement boat = memberToUpdate.Elements(XMLFileInfo.Boat) .Skip(boatsToBeSkipped) .Take(1) .First(); boat.ReplaceWith(createBoat(boatToAdd)); xElement.Save(XMLFileInfo.Path); return true; } catch (Exception) { return false; } }
public bool add(Member member, Boat boat) { try { XDocument xElement = XDocument.Load(XMLFileInfo.Path); XElement particularMember = xElement.Element(XMLFileInfo.Members).Elements(XMLFileInfo.Member) .Where(a => a.Element(XMLFileInfo.ID).Value == member.MemberID.ToString()) .Last(); if (particularMember != null) particularMember.Add(createBoat(boat)); xElement.Save(XMLFileInfo.Path); return true; } catch (Exception) { return false; } }
public List<Boat> getBoatsByMember(Member member) { List<Boat> boats = new List<Boat>(); XElement xElement = XElement.Load(XMLFileInfo.Path); var memberInfo = from Member in xElement.Elements(XMLFileInfo.Member) where (string)Member.Element(XMLFileInfo.ID) == member.MemberID.ToString() select Member; XElement memberToGetBoatsFrom = memberInfo.First(); foreach (XElement boat in memberToGetBoatsFrom.Elements(XMLFileInfo.Boat)) { BoatType type = (BoatType)Enum.Parse(typeof(BoatType), boat.Attribute(XMLFileInfo.Type).Value); var boatToBeAdded = new Boat(type, int.Parse(boat.Value)); boats.Add(boatToBeAdded); } boats.TrimExcess(); return boats; }
private XElement createBoat(Boat boat) { return new XElement(XMLFileInfo.Boat, boat.Length, new XAttribute(XMLFileInfo.Type, boat.Type)); }
public void editSelectedBoat(Boat b) { string editedBoatType = credentialBoatType(); float edtiedBoatLength = credentialBoatLength(editedBoatType); _mc.editBoat(editedBoatType, edtiedBoatLength, b); }
public void deleteSelectedBoat(List<Boat> boats,Boat b) { _mc.deleteBoat(boats,b); }
public void editBoat(string boatType, float boatLength, Boat b) { b.BoatType = boatType; b.BoatLength = boatLength; saveChange(); }
public void deleteBoat(List<Boat> boats, Boat b) { boats.Remove(b); saveChange(); }