public void SerializeToXML(MemberList members)
 {            
     XmlSerializer serializer = new XmlSerializer(typeof(MemberList));
     TextWriter textWriter = new StreamWriter(path);
     serializer.Serialize(textWriter, members);
     textWriter.Close();
 }
 public void RemoveMember(MemberList members)
 {            
     Console.WriteLine("Skriv in det medlemsnummer som ska raderas:");
     var member = new Member();
     member.RemoveMember(members);
     Console.WriteLine("\nDu har raderat en medlem.");
     ContinueOnKeyPressed();
 }
 public MemberList SerializerXMLIsNullOrNot(MemberList member)
 {
     if (member == null)
     {
         SerializeToXML(member);
     }
     member = DeserializeFromXML();
     return member;
 }
        public void AddBoat(MemberList members)
        {
            Console.WriteLine("Skriv in det medlemsnumer som du ska registrera en ny båt på:");

            var boat = new Boat();
            boat.AddBoat(members);
            Console.WriteLine("\nDu har lagt till en båt.");
            ContinueOnKeyPressed();
        }
        public void run()
        {
            MemberList members = new MemberList();          
            
            var serializer = new SerializerXML();
           
            var listViews = new ListViews();
            var consoleView = new ConsoleView();
            var memberview = new MemberView();
            var boatview = new BoatView();

            members = serializer.SerializerXMLIsNullOrNot(members);            
            
            do
            {
                int choise = consoleView.GetMenuChoice();

                switch (choise)
                {
                    case 0:                        
                        Environment.Exit(0);
                        break;
                    case 1:
                        memberview.CreateMember(members);
                        break;
                    case 2:
                        memberview.ShowMember(members);                        
                        break;
                    case 3: 
                        memberview.UpDateMember(members);
                        break;
                    case 4:
                        memberview.RemoveMember(members);
                        break;
                    case 5:                     
                        boatview.AddBoat(members);
                        break;
                    case 6:
                        boatview.UpDateBoat(members);
                        break;
                    case 7:
                        boatview.RemoveBoat(members);
                        break;
                    case 8:
                        listViews.CompactList(members);
                        break;
                    case 9:
                        listViews.CompleteList(members);
                        break;
                }
                serializer.SerializeToXML(members);
                Console.Clear();

            } while (true);
            
        }        
 public void CreateMember(MemberList members, string Name, int SocialNr)
 {
     int MemberId = SetMemberId(members);
     Member currentMember = new Member();
     currentMember.MemberId = MemberId;
     currentMember.Name = Name;
     currentMember.SocialNr = SocialNr;
     
     members.Add(currentMember);
 }
        public void RemoveBoat(MemberList members)
        {
            Boat currentBoat = new Boat();
            
            Console.WriteLine("Skriv in det medlemsnummer som du ska radera en båt på:");

            currentBoat.RemoveBoat(members);
           
            Console.WriteLine("\nDu har readerat en båt.");
            ContinueOnKeyPressed();       
        }
 public void CompactList(MemberList members)
 {
     var boat = new Boat();
     foreach (Member mObject in members.Members)
     {
         int boatCount = boat.CountBoats(mObject);
         Console.WriteLine("\nName: {0} MedlemsNr: {1} Antal båtar: {2}"
               , mObject.Name, mObject.MemberId, boatCount);
     }
     ContinueOnKeyPressed();            
 }
        public void UpDateBoat(MemberList members)
        {            
            Boat currentBoat = new Boat();
            Member currentMember = new Member();

            Console.WriteLine("Skriv in det medlemsnummer som du vill redigera en båt på.");
            currentMember = currentMember.ObjectFinder1(members);
            Console.WriteLine("Skriv in nummret på den båt du vill ändra på:");

            currentBoat.UpDateBoat(currentMember, currentBoat);      

            Console.WriteLine("\nDu har redigerat en båt.");
            ContinueOnKeyPressed();
        }
        public void UpDateMember(MemberList members)
        {
            Member currentMember = new Member();
            Console.WriteLine("Skriv in det medlemsnummer som du vill redigera uppgifter på:");

            var member = new Member();
            currentMember = member.ObjectFinder1(members);

            Console.WriteLine("Skriv in nummret på det fält du vill ändra på:");
            Console.WriteLine("1: {0}", currentMember.Name);
            Console.WriteLine("2: {0}", currentMember.SocialNr);
            
            member.UpDateMember(currentMember);
            Console.WriteLine("\nDu har updaterat en medlem.");
            ContinueOnKeyPressed();
        }        
 public void CompleteList(MemberList members)
 {
     var boat = new Boat();
     foreach (Member mObject in members.Members)
     {
         int boatCount = boat.CountBoats(mObject);
         Console.WriteLine("\nName: {0} PersonNr: {1} Medlemsnummer: {2} Antal båtar: {3}"
              , mObject.Name, mObject.SocialNr, mObject.MemberId, boatCount);
         if (boatCount != 0)
         {
             var boatview = new BoatView();
             boatview.ShowBoats(mObject);                    
         }
     }
     ContinueOnKeyPressed();
 }
        public void ShowMember(MemberList members)
        {          

            Console.WriteLine("Skriv in det medlemsnummer som du vill titta på:");
            var member = new Member();

            Member currentMember = member.ShowMember(members);            

            Console.WriteLine("\nNamn: {0}", currentMember.Name);
            Console.WriteLine("MedlemsNr: {0}", currentMember.MemberId);
            Console.WriteLine("PersonNr: {0}", currentMember.SocialNr);

            var boatView = new BoatView();
            boatView.ShowBoats(currentMember);  
                  
            ContinueOnKeyPressed();           
        }
 public int SetMemberId(MemberList members)
 {
     int HighestNumber = 1;
     if (members.Members.Count == 0)
     {
         throw new InvalidOperationException("Empty list");
     }
     int maxNr = int.MinValue;
     foreach (Member type in members.Members)
     {
         if (type.MemberId > maxNr)
         {
             maxNr = type.MemberId;
             HighestNumber = maxNr;
             HighestNumber++;
         }
     }
     return HighestNumber;
 }
        public void AddBoat(MemberList members)
        {
            Boat myBoat = new Boat();
            Member currentMember = new Member();
            var boatview = new BoatView();

            currentMember = currentMember.ObjectFinder1(members);
            if (currentMember.BoatList == null)
            {
                currentMember.BoatList = new BoatList();
            }

            int index = members.Members.IndexOf(currentMember);
            boatview.ShowBoatTypeAndLength();

            AddBoatTypeAndLength(myBoat);
            currentMember.BoatList.Add(myBoat);
            members.Members.RemoveAt(index);
            members.Members.Insert(index, currentMember);
        }
        public void CreateMember(MemberList members)
        {
            string Name;
            int SocialNr;  
            
            while (true)
            {
                try
                {
                    Console.WriteLine("Skriv in ditt namn: ");
                    Name = Console.ReadLine();
                    break; 
                }
                catch
                {
                    Console.WriteLine("Fel inmatning! Försök igen");
                }
            }
            while (true)
            {
                try
                {
                    Console.WriteLine("Skriv in ditt personummer: ");
                    SocialNr = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("Fel inmatning! Försök igen");
                }
            }

            var member = new Member();
            member.CreateMember(members, Name, SocialNr);

            Console.WriteLine("\nDu har lagt in en medlem.");
            ContinueOnKeyPressed();  
        }
 public void RemoveMember(MemberList members)
 {
     Member currentObject = new Member();
     currentObject = ObjectFinder1(members);
     members.Members.Remove(currentObject);            
 }
 public Member ShowMember(MemberList members)
 {
     //Member currentMember = new Member();
     
     Member currentMember = ObjectFinder1(members);
     return currentMember;
 }        
        //Hämtar ett objekt
        public Member ObjectFinder1(MemberList members)
        {
            Member member = new Member();

            while (true)
            {
                try
                {

                    int IDtoFind = Convert.ToInt32(Console.ReadLine());
                    member = members.Members.Find(x => x.MemberId == IDtoFind);

                    if (member == null)
                    {
                        Console.WriteLine("\nHittade inte medlemen, försök igen.");
                    }
                    else
                    {
                        return member;
                    }
                }
                catch (Exception)
                {

                    Console.WriteLine("Fel vid inmatning, försök igen.");
                }

            }
        }
 public void RemoveBoat(MemberList members)
 {
     Member currrentMember = new Member();
     while (true)
     {
         try
         {
             currrentMember = currrentMember.ObjectFinder1(members);
             int counter = 1;
             Console.WriteLine("Välj nummer på den båt som ska raderas:");
             foreach (Boat bObj in currrentMember.BoatList.Boats)
             {
                 Console.WriteLine("{0}: {1} med längd {2}m", counter, bObj.BoatType, bObj.BoatLength);
                 counter++;
             }
             int choice = Convert.ToInt32(Console.ReadLine());
             choice--;
             currrentMember.BoatList.Boats.RemoveAt(choice);
             break;
         }
         catch (Exception)
         {
             Console.WriteLine("Ange ett giltigt nummer.");
         }
     }
 }