Esempio n. 1
0
        // Method to save members
        private static void SaveMembers(List<Member> members)
        {
            MemberView mView = new MemberView();

            // Check if there's any members otherwise display a warning message.
            if (members != null && members.Any())
            {
                // Try to save it otherwise display an error.
                try
                {
                    MemberDirectory repo = new MemberDirectory("members.txt");
                    repo.Save(members);

                    // Display a header from the RenderHeader method.
                    Console.Clear();
                    mView.RenderHeader("      Medlemmarna har sparats     ", bgcolor: ConsoleColor.DarkGreen);
                }
                catch (Exception)
                {
                    // Display a header from the RenderHeader method.
                    Console.Clear();
                    mView.RenderHeader(" FEL! Ett fel inträffade då medlemmarna skulle sparas.", bgcolor: ConsoleColor.Red);
                }
            }
            else
            {
                // Display a header from the RenderHeader method.
                Console.Clear();
                mView.RenderHeader("  Det finns inga medlemmar att spara ", bgcolor: ConsoleColor.Yellow, fgcolor: ConsoleColor.Black);
            }
        }
Esempio n. 2
0
        // Private static method for loading the list of members.
        private static List<Member> LoadMembers()
        {
            MemberView mView = new MemberView();

            // Try to open a file named "members.txt" and the return the list so we can use that list
            // for all the other methods.
            try
            {
                MemberDirectory repo = new MemberDirectory("members.txt");
                List<Member> members = repo.Load();
                return members;
            }
            // Else catch the exception and return NULL as well as a error message will be presented.
            catch (Exception)
            {
                // Display a header from the RenderHeader method.
                Console.Clear();
                mView.RenderHeader(" FEL! Ett fel inträffade då medlemsregistret lästes in.", bgcolor: ConsoleColor.Red);

                // And return null.
                return null;
            }
        }