Example #1
0
        static void ListAll(SoftUniEntities context)
        {
            var data = context.Projects
                       .Select(p => new
            {
                p.ProjectID,
                p.Name
            })
                       .ToList();
            var projectPaginator = new Paginator(data

                                                 .Select(p => $"{ p.ProjectID,4}|{ p.Name }").ToList(), 2, 0, 14, true);

            while (true)
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.White;

                Console.Clear();
                Console.WriteLine($"ID   |   Project name (Page {projectPaginator.CurrentPage + 1} of {projectPaginator.MaxPages})");
                Console.WriteLine("===================================");

                projectPaginator.Print();

                var key = Console.ReadKey(true);

                if (!KeyboardController.PageController(key, projectPaginator, context))
                {
                    return;
                }
            }
        }
        public static bool PageController(ConsoleKeyInfo key, Paginator paginator, SoftUniEntities context)
        {
            switch (key.Key.ToString())
            {
            case "Enter":
                var projectIDAsString = paginator
                                        .Data
                                        .Skip(paginator.PageSize * paginator.CurrentPage + paginator.CursorPos - 1)
                                        .First()
                                        .Substring(0, 4)
                ;
                int projectID = int.Parse(projectIDAsString);

                var currentProject = context.Projects.First(p => p.ProjectID == projectID);
                ShowDetails(currentProject);
                break;

            case "UpArrow":
                if (paginator.CursorPos > 1)
                {
                    paginator.CursorPos--;
                }
                else if (paginator.CurrentPage > 0)
                {
                    paginator.CurrentPage--;
                    paginator.CursorPos = paginator.PageSize;
                }
                break;

            case "DownArrow":
                if (paginator.CursorPos < paginator.PageSize)
                {
                    if (paginator.CurrentPage == paginator.MaxPages - 1 && paginator.CursorPos + 1 > paginator.Data.Count % paginator.PageSize)
                    {
                        break;
                    }
                    paginator.CursorPos++;
                }
                else if (paginator.CurrentPage + 1 < paginator.MaxPages)
                {
                    paginator.CurrentPage++;
                    paginator.CursorPos = 1;
                }
                break;

            case "Escape": return(false);
            }

            return(true);
        }
Example #3
0
        public static void Main()
        {
            //Window initialization ;

            Console.WindowHeight    = 17;
            Console.WindowWidth     = 50;
            Console.BufferHeight    = 17;
            Console.BufferWidth     = 50;
            Console.CursorVisible   = false;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;

            //db init
            var context = new SoftUniEntities();

            ListAll(context);
        }