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 void deleteMember(Member m) { for(int i = 0; i<_memberDAL.members.Count; i++) { if(m.UniqueID == _memberDAL.members.ElementAt(i).UniqueID) { _memberDAL.members.RemoveAt(i); } } saveChange(); }
public Member getMemberInfo(int ID = 0) { Console.Write(AppStrings.addMemberName); string name = Console.ReadLine(); Console.Write(AppStrings.addMemberSSN); string ssn = Console.ReadLine(); var member = new Member(name, ssn, ID); return member; }
public List<Boat> getBoatsByMember(Member member) { var boats = member.getBoats(); if (boats.Count == 0) { Console.WriteLine(AppStrings.memberHasNoBoat); return null; } else { int numOfBoats = 1; foreach (var boat in boats) { Console.WriteLine(AppStrings.renderBoatInformation, numOfBoats, boat.Type, boat.Length); numOfBoats++; } return boats; } }
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 bool removeBoat(Member member, int boat) { try { XElement xElement = XElement.Load(XMLFileInfo.Path); xElement.Descendants(XMLFileInfo.Member) .Where(a => a.Element(XMLFileInfo.ID).Value == member.MemberID.ToString()) .SelectMany(a => a.Elements(XMLFileInfo.Boat)) .Skip(boat).Take(1) .Remove(); xElement.Save(XMLFileInfo.Path); return true; } catch (Exception) { return false; } }
public Member getMemberByID(int ID) { XElement xElement = XElement.Load(XMLFileInfo.Path); var memberInfo = from Member in xElement.Elements(XMLFileInfo.Member) where (string)Member.Element(XMLFileInfo.ID) == ID.ToString() select Member; var memberNames = memberInfo.Elements(XMLFileInfo.Name); XElement memberName = memberNames.First(); var memberSSNs = memberInfo.Elements(XMLFileInfo.SocialSecurityNumber); XElement memberSSN = memberSSNs.First(); var memberIDs = memberInfo.Elements(XMLFileInfo.ID); XElement memberID = memberIDs.First(); var member = new Member(memberName.Value, memberSSN.Value, int.Parse(memberID.Value)); return member; }
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; }
/* * Boat Handling. */ public void addBoat(Member m) { Console.Clear(); Console.WriteLine("[ADD BOAT]"); Console.Write("\nEnter the amount of boats: "); try { int v_numberOfBoats = int.Parse(Console.ReadLine()); for (int i = 0; i < v_numberOfBoats; i++) { string v_boatType = credentialBoatType(); float v_boatLength = credentialBoatLength(v_boatType); _mc.addBoat(v_boatType, v_boatLength, m); } } catch(Exception) { Console.WriteLine("Enter a valid number! Press Enter to go back."); Console.ReadLine(); } }
public void selectedMember(Member m) { while (true) { Console.Clear(); Console.WriteLine("[YOU HAVE SELECTED: {0}]", m.Name); Console.WriteLine("\nWhat do you want to do with your selected member?"); Console.WriteLine("1. Add Boat"); Console.WriteLine("2. Edit Boat"); Console.WriteLine("3. Delete Boat"); Console.WriteLine("4. Edit Member"); Console.WriteLine("5. Delete Member"); Console.WriteLine("\nB. Go back to menu"); bool editOrDelete; char choice = Console.ReadKey().KeyChar; switch (choice) { case '1': addBoat(m); break; case '2': editOrDelete = true; editBoat(m, editOrDelete); break; case '3': editOrDelete = false; editBoat(m, editOrDelete); break; case '4': editMember(m); break; case '5': deleteMember(m); break; case 'b': menu(); break; default: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("You need to enter a valid number! Press Enter to try again."); Console.ReadLine(); Console.ForegroundColor = ConsoleColor.White; break; }; } }
public void editMember(Member m) { Console.Clear(); Console.WriteLine("[EDIT MEMBER ({0})]", m.Name); string changedName = credentialsName(); string changedSSN = credentialsSSN(); _mc.updateMember(changedName, changedSSN, m); }
public void addBoat(string c_boatType, float c_length, Member m) { Model.Boat boat = new Model.Boat(c_boatType, c_length); m.Boats.Add(boat); saveChange(); }
public void renderCompactListElement(Member member, int numberOfBoats) { Console.WriteLine(AppStrings.renderCompactList, member.Name, member.MemberID, numberOfBoats); }
public void renderShortInformationAboutBoatsByMember(Member member) { var boats = member.getBoats(); Console.WriteLine(AppStrings.renderMembersNumberOfBoats, boats.Count); foreach (Boat boat in boats) { Console.WriteLine(AppStrings.renderBoat, boat.Type, boat.Length); } }
private bool addMember(Member member) { try { // Check if file exist or if the file length is shorter than 55 // 55 is the length of the xml version info in the file if (!File.Exists(XMLFileInfo.Path) || new FileInfo(XMLFileInfo.Path).Length < 55) { XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; xmlWriterSettings.NewLineOnAttributes = true; using (XmlWriter xmlWriter = XmlWriter.Create(XMLFileInfo.Path, xmlWriterSettings)) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement(XMLFileInfo.Members); xmlWriter.WriteStartElement(XMLFileInfo.Member); xmlWriter.WriteElementString(XMLFileInfo.ID, XMLFileInfo.FirstID); xmlWriter.WriteElementString(XMLFileInfo.Name, member.Name); xmlWriter.WriteElementString(XMLFileInfo.SocialSecurityNumber, member.SocialSecurityNumber); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); xmlWriter.Close(); } } else { XElement xElement = XElement.Load(XMLFileInfo.Path); int ID = int.Parse((string)xElement.Descendants(XMLFileInfo.ID).FirstOrDefault()); ID++; xElement.AddFirst(createMember(ID, member)); xElement.Save(XMLFileInfo.Path); } return true; } catch (Exception) { return false; } }
public bool saveMember(Member member) { if (member.MemberID != 0) { return updateMember(member); } else { return addMember(member); } }
private bool updateMember(Member memberToBeUpdated) { try { var ID = memberToBeUpdated.MemberID; var currentMember = getMemberByID(ID); if (String.IsNullOrWhiteSpace(memberToBeUpdated.Name)) memberToBeUpdated.Name = currentMember.Name; if (String.IsNullOrWhiteSpace(memberToBeUpdated.SocialSecurityNumber)) memberToBeUpdated.SocialSecurityNumber = currentMember.SocialSecurityNumber; var oldMember = createMember(currentMember); var updatedMember = createMember(memberToBeUpdated); XElement xElement = XElement.Load(XMLFileInfo.Path); XElement memberToBeReplaced = (from Member in xElement.Elements(XMLFileInfo.Member) where (string)Member.Element(XMLFileInfo.ID) == ID.ToString() select Member).First(); foreach (XElement element in memberToBeReplaced.Elements(XMLFileInfo.Boat)) updatedMember.Add(element); memberToBeReplaced.ReplaceWith(updatedMember); xElement.Save(XMLFileInfo.Path); return true; } catch (Exception) { return false; } }
private XElement createMember(int ID, Member member) { return new XElement(XMLFileInfo.Member, new XElement(XMLFileInfo.ID, ID), new XElement(XMLFileInfo.Name, member.Name), new XElement(XMLFileInfo.SocialSecurityNumber, member.SocialSecurityNumber)); }
private XElement createMember(Member member) { return createMember(member.MemberID, member); }
public void renderLongInformationAboutBoatsByMember(Member member) { var boats = member.getBoats(); if (boats.Count == 0) { Console.WriteLine(AppStrings.memberHasNoBoat); } else { int boatNumber = 1; foreach (var boat in boats) { Console.WriteLine(AppStrings.renderBoatInformation, boatNumber, boat.Type, boat.Length); boatNumber++; } } }
public void renderMemberByID(Member member) { Console.WriteLine(AppStrings.renderMembersName, member.Name); Console.WriteLine(AppStrings.renderMembersSSN, member.SocialSecurityNumber); }
public void deleteMember(Member m) { while (true) { Console.Clear(); Console.WriteLine("Do you really want to delete {0}? (y/n)", m.Name); char selection = Console.ReadKey().KeyChar; if (selection == 'y') { _mc.deleteMember(m); Console.Clear(); Console.WriteLine("You have deleted {0}. Press Enter to go back to mainmenu.", m.Name); Console.ReadLine(); menu(); } else if (selection == 'n') { break; } } }
public void editBoat(Member m, bool editOrDelete) { Console.Clear(); int pos = 0; foreach(Boat boat in m.Boats) { Console.WriteLine(pos+". "+" Type: {0,-10} Length: {1}m ",boat.BoatType, boat.BoatLength); pos++; } Console.Write("\nWhich boat do you want to edit?"); try { int choice = int.Parse(Console.ReadLine()); foreach(Boat boat in m.Boats) { if (m.Boats.IndexOf(boat) == choice) { if(editOrDelete) { editSelectedBoat(boat); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("You have successfully edited the boat!"); Console.ResetColor(); Thread.Sleep(2000); break; } else { deleteSelectedBoat(m.Boats, boat); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("You have successfully removed the boat from the Member!"); Console.ResetColor(); Thread.Sleep(2000); break; } } } } catch (Exception) { Console.WriteLine("Enter a valid number! Press Enter to go back."); Console.ReadLine(); } }
public void renderVerboseListElement(Member member) { Console.WriteLine(AppStrings.renderVerboseList, member.Name, member.SocialSecurityNumber, member.MemberID); }
public void updateMember(string name, string ssn, Member m) { m.Name = name; m.SSN = ssn; saveChange(); }