//Returns one boat public Boat getBoatById(string selectedBoatId, string memberId) { List<Boat> boats = getBoatsByMemberId(memberId); foreach (Boat boat in boats) { if(boat.BoatId.ToString() == selectedBoatId){ Boat selectedBoat = new Boat(boat.BoatId, boat.BoatType, boat.BoatLength, memberId); return selectedBoat; } } return null; }
public Boat editBoat(string selectedBoatId) { Console.Clear(); helper.printDivider(); Console.WriteLine("REDIGERA BÅT MED ID " + selectedBoatId + "\n"); helper.printDivider(); helper.getBoatTypeMenu(); string newBoatType = helper.setBoatType(Console.ReadLine()); Console.Write("Båtlängd: \n"); string newBoatLength = Console.ReadLine(); if (newBoatLength == "") { newBoatLength = boatLength; } Boat editedBoat = new Boat(int.Parse(boatId), newBoatType, newBoatLength, memberId); return editedBoat; }
//Shows one boat to edit or delete public void showEditBoatMenu(string boatId, string memberId) { MemberDAL memberDAL = new MemberDAL(); boat = memberDAL.getBoatById(boatId, memberId); Console.Clear(); this.helper.printDivider(); Console.WriteLine("MEDLEM " + memberId + ":S BÅT " + boatId); this.helper.printDivider(); Console.WriteLine("\nAnge T för att ta bort båt."); Console.WriteLine("Ange R för att redigera båt.\n"); if (boat != null) { Console.WriteLine("{0}: {1}", helper.BoatId, boat.BoatId); Console.WriteLine("{0}: {1}", helper.BoatType, boat.BoatType); Console.WriteLine("{0}: {1}", helper.BoatLength, boat.BoatLength); } else { Console.Clear(); Console.WriteLine("Båten finns inte."); helper.getBackToStartMessage(); } }
public Boat addBoat(string selectedMember) { string boatType = ""; string boatLength = ""; Console.Clear(); helper.printDivider(); Console.WriteLine("LÄGG TILL EN BÅT"); helper.printDivider(); while (boatType == "") { helper.getBoatTypeMenu(); boatType = helper.setBoatType(Console.ReadLine()); } while(boatLength == ""){ Console.Write("Ange båtens längd: \n"); boatLength = Console.ReadLine(); } Boat newBoat = new Boat(0, boatType, boatLength, selectedMember); return newBoat; }
public void addBoatToMember(string boatId, string boatType, string boatLength) { boat = new Boat(boatId, boatType, boatLength, MemberID); memberDAL.saveBoat(MemberID, boat); }
public void updateBoatById(Boat editedBoat, string memberId) { XDocument doc = XDocument.Load(path); var member = doc.Descendants(XMLElementMember) .Where(arg => arg.Attribute(XMLAttributeMemberId).Value == memberId) .Single(); member.Element(XMLElementBoat).Attribute(XMLAttributeBoatType).Value = editedBoat.BoatType; member.Element(XMLElementBoat).Attribute(XMLAttributeBoatLength).Value = editedBoat.BoatLength; doc.Save(path); }
public void saveBoat(Boat newBoat, string memberId) { XDocument doc = XDocument.Load(path); doc.Element(XMLElementMembers).Elements(XMLElementMember) .First(c => (string)c.Attribute(XMLAttributeMemberId) == memberId) .Add( new XElement( XMLElementBoat, new XAttribute(XMLAttributeBoatId, newBoat.BoatId), new XAttribute(XMLAttributeBoatType, newBoat.BoatType), new XAttribute(XMLAttributeBoatLength, newBoat.BoatLength) ) ); doc.Save(path); }
//Returns a list of boats for one member public List<Boat> getBoatsByMemberId(string memberId) { List<Boat> boats = new List<Boat>(); Boat boat; using (XmlTextReader reader = new XmlTextReader(path)) { XDocument doc = XDocument.Load(path); foreach (var item in doc.Descendants(XMLElementMember).Elements(XMLElementBoat) .Where(e => e.Parent.Name == XMLElementMember && e.Parent.Attribute(XMLAttributeMemberId).Value == memberId)) { string boatId = item.Attribute(XMLAttributeBoatId).Value; string boatType = item.Attribute(XMLAttributeBoatType).Value; string boatLength = item.Attribute(XMLAttributeBoatLength).Value; boat = new Boat(boatId, boatType, boatLength, memberId); boats.Add(boat); } } return boats; }