Beispiel #1
0
        /// <summary>
        /// Helper function for printing lists
        /// </summary>
        /// <param name="list"></param>
        /// <param name="displayMode"></param>
        void PrintList(List <object> list, ListDisplayMode displayMode)
        {
            foreach (object entry in list)
            {
                if (entry == null)
                {
                    continue;
                }

                var line = $"{list.IndexOf(entry)} ";

                if (entry.GetType() == typeof(MemberData))
                {
                    line += MemberToString((MemberData)entry, displayMode);
                }
                else if (entry.GetType() == typeof(BoatData))
                {
                    line += BoatToString((BoatData)entry, displayMode);
                }
                else
                {
                    line += entry.ToString();
                }

                Console.WriteLine(line);
            }
        }
        private MvcWidgetProxy CreateBlogPostsMvcWidget(ListDisplayMode displayMode, int itemsCount)
        {
            string defaultSortExpr = "PublicationDate DESC";

            var mvcProxy = this.CreateBlogPostsMvcWidget(displayMode, itemsCount, defaultSortExpr);

            return(mvcProxy);
        }
Beispiel #3
0
        /// <summary>
        /// Boilerplate function for showing a list with basic selection function
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="topMessage"></param>
        /// <param name="dataList"></param>
        /// <param name="listDisplay"></param>
        /// <returns></returns>
        T ListSelection <T>(string topMessage, List <object> dataList, ListDisplayMode listDisplay = ListDisplayMode.Compact)
        {
            int selection = -1;

            while (selection >= dataList.Count() || selection < 0)
            {
                Console.Clear();
                Console.WriteLine(topMessage);
                PrintList(dataList.ToList(), listDisplay);
                Console.WriteLine("\nWrite the index number for the item you want to select");
                int.TryParse(Console.ReadLine(), out selection);
            }

            return((T)dataList.ElementAt(selection));
        }
        private MvcWidgetProxy CreateBlogsMvcWidget(ListDisplayMode displayMode, int itemsPerPage, string sortExpression)
        {
            var mvcProxy = new MvcWidgetProxy();

            mvcProxy.ControllerName = typeof(BlogController).FullName;
            var controller = new BlogController();

            controller.Model.DisplayMode    = displayMode;
            controller.Model.ItemsPerPage   = itemsPerPage;
            controller.Model.SortExpression = sortExpression;

            mvcProxy.Settings = new ControllerSettings(controller);

            return(mvcProxy);
        }
Beispiel #5
0
        /// <summary>
        /// Helper function for reading MemberData to a human-readable string
        /// </summary>
        /// <param name="data"></param>
        /// <param name="displayMode"></param>
        /// <returns></returns>
        string MemberToString(MemberData data, ListDisplayMode displayMode)
        {
            string result = "";

            if (displayMode == ListDisplayMode.Compact)
            {
                result += $"{data.Name}, PN: {data.PersonalNumber} ID: {data.ID}, Boats;\n";
                foreach (BoatData boat in data.Boats)
                {
                    result += $"   {boat.Length}m {boat.BoatType} (ID: {boat.ID})\n";
                }
            }
            else
            {
                result += $"{data.Name}, ID: {data.ID}, {data.Boats.Count} boat(s)";
            }

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Shows a context-sensitive menu for listing, viewing, creating, editing, or deleting members
        /// </summary>
        /// <param name="dataMode"></param>
        /// <param name="displayMode"></param>
        /// <param name="selectedID"></param>
        void ShowMemberMenu(DataMode dataMode, ListDisplayMode displayMode = ListDisplayMode.Compact, string selectedID = null)
        {
            Console.Clear();

            string     selected     = selectedID;
            MemberData selectedData = null;

            if (dataMode != DataMode.Create)
            {
                if (selected == null)
                {
                    selected = SelectMember($"Please select the member whose details you wish to {(dataMode == DataMode.View ? "view" : "edit")}:\n", displayMode);
                }

                selectedData = (MemberData)DataController.RetrieveByID(selected);
            }

            switch (dataMode)
            {
            case DataMode.Create:
            case DataMode.Edit:
            {
                Dictionary <string, object> arguments = new Dictionary <string, object>();

                Console.WriteLine("Please fill out the following fields");
                Console.Write("Name: ");
                arguments.Add("name", Console.ReadLine());

                Console.Write("Personal Number: ");
                var pn = ReadValidInput((s) => {
                        var res = s.Length != 10 || s.Sum(c => { return(("0123456789".Contains(c)) ? 0 : c); }) > 0;
                        if (res)
                        {
                            Console.WriteLine("The personal number has to be all digits and ten digits long!");
                        }
                        return(res);
                    });
                arguments.Add("personal-num", pn);

                if (dataMode == DataMode.Create)
                {
                    DataController.CreateData(typeof(MemberData), arguments);
                }
                else
                {
                    DataController.ChangeData(selected, arguments);
                }
                break;
            }

            case DataMode.View:
            {
                Console.Clear();
                Console.Write(
                    $"Member ID: {selectedData.ID}\n" +
                    $"Time of creation: {selectedData.Timestamp}\n\n" +
                    $"Name: {selectedData.Name}\n" +
                    $"Personal Number: {selectedData.PersonalNumber}\n" +
                    $"Boats: ({selectedData.Boats.Count})\n");
                foreach (BoatData boat in selectedData.Boats)
                {
                    Console.WriteLine($" - {boat.Length}m {boat.BoatType} (Boat ID: {boat.ID})");
                }

                Console.WriteLine("\nPress E to edit this - Press D to delete this - Any else to return to main menu...");

                var key = Console.ReadKey().Key;

                switch (key)
                {
                case ConsoleKey.E: ShowMemberMenu(DataMode.Edit, selectedID: selected); break;

                case ConsoleKey.D: ShowDeleteConfirmation(selected); break;

                default: return;
                }

                break;
            }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Helper function for reading BoatData to a human-readable string
        /// </summary>
        /// <param name="data"></param>
        /// <param name="displayMode"></param>
        /// <returns></returns>
        string BoatToString(BoatData data, ListDisplayMode displayMode)
        {
            var owner = data.Owner;

            return($"ID: {data.ID}, {data.Length}m {data.BoatType}, " + (owner == null ? "ownerless" :$" owned by {owner.Name} (ID: {owner.ID})"));
        }
Beispiel #8
0
        /// <summary>
        /// Shows a list of items that can be selected; special for Boats
        /// </summary>>
        /// <param name="topMessage"></param>
        /// <param name="listDisplay"></param>
        /// <returns></returns>
        string SelectBoat(string topMessage, ListDisplayMode listDisplay = ListDisplayMode.Compact)
        {
            var boats = DataController.RetrieveByQuery(d => d.GetType() == typeof(BoatData)).ToList <object>();

            return(ListSelection <BoatData>(topMessage, boats, listDisplay).ID);
        }
Beispiel #9
0
        /// <summary>
        /// Shows a list of items that can be selected; special for Members
        /// </summary>
        /// <param name="topMessage"></param>
        /// <param name="listDisplay"></param>
        /// <returns></returns>
        string SelectMember(string topMessage, ListDisplayMode listDisplay = ListDisplayMode.Compact)
        {
            var members = DataController.RetrieveByQuery(d => d.GetType() == typeof(MemberData)).ToList <object>();

            return(ListSelection <MemberData>(topMessage, members, listDisplay).ID);
        }
Beispiel #10
0
 public void ShowMembers(ListDisplayMode displayMode)
 {
 }
        private MvcWidgetProxy CreateBlogsMvcWidget(ListDisplayMode displayMode, int itemsPerPage)
        {
            string defaultSortExpr = "PublicationDate DESC";

            var mvcProxy = this.CreateBlogsMvcWidget(displayMode, itemsPerPage, defaultSortExpr);

            return mvcProxy;
        }
        private MvcWidgetProxy CreateBlogsMvcWidget(ListDisplayMode displayMode, int itemsPerPage, string sortExpression)
        {
            var mvcProxy = new MvcWidgetProxy();
            mvcProxy.ControllerName = typeof(BlogController).FullName;
            var controller = new BlogController();

            controller.Model.DisplayMode = displayMode;
            controller.Model.ItemsPerPage = itemsPerPage;
            controller.Model.SortExpression = sortExpression;

            mvcProxy.Settings = new ControllerSettings(controller);

            return mvcProxy;
        }
Beispiel #13
0
        /// <summary>
        /// Shows a list of items that can be selected; special for Boats
        /// </summary>>
        /// <param name="topMessage"></param>
        /// <param name="listDisplay"></param>
        /// <returns></returns>
        string SelectBoat(string topMessage, ListDisplayMode listDisplay = ListDisplayMode.Compact)
        {
            var boats = DataController.GetBoats().ToList <object>();

            return(ListSelection <BoatData>(topMessage, boats, listDisplay).ID);
        }
Beispiel #14
0
        /// <summary>
        /// Shows a list of items that can be selected; special for Members
        /// </summary>
        /// <param name="topMessage"></param>
        /// <param name="listDisplay"></param>
        /// <returns></returns>
        string SelectMember(string topMessage, ListDisplayMode listDisplay = ListDisplayMode.Compact)
        {
            var members = DataController.GetMembers().ToList <object>();

            return(ListSelection <MemberData>(topMessage, members, listDisplay).ID);
        }