Пример #1
0
        public async Task <IActionResult> OnGetVueDataAsync(int pageIndex = 1, int pageSize = 10)
        {
            PageIndex = pageIndex;
            PageSize  = pageSize;

            TreeDomain = await _context.TreeDomains.OrderBy(t => t.OrderNumber).ToPagedListAsync(pageIndex, pageSize);

            var model = TreeDomain.Select(t => new
            {
                t.SampleColumn,
                t.ParentId,
                t.OrderNumber,
                RowVersion = t.RowVersion.ToHexString().TrimStart('0'),
                t.IsDeleted,
                CreationTime         = t.CreationTime.ToString("yyyy-MM-dd HH:mm:ss zzz"),
                LastModificationTime = t.LastModificationTime.ToString("yyyy-MM-dd HH:mm:ss zzz"),
                t.CreationUserId,
                t.LastModificationUserId,
                EditLink    = Url.Page("Edit", new{ id = t.Id }),
                DetailsLink = Url.Page("Details", new{ id = t.Id }),
                DeleteLink  = Url.Page("Delete", new{ id = t.Id })
            });

            return(new JsonResult(model));
            //.Include(t => t.CreationUser)
            //.Include(t => t.LastModificationUser)
            //.Include(t => t.Parent).ToListAsync();
        }
Пример #2
0
        public async Task <bool> CreateTree(TreeDomain tree)
        {
            try
            {
                await Task.Yield();

                using (var session = driver.Session())
                {
                    var id = session.WriteTransaction((tx) =>
                    {
                        var result = tx.Run(@"
                            CREATE (tree: Tree) 
                            SET 
                                tree.uuid = $uuid,
                                tree.type = $type,
                                tree.lastUpdateDate = datetime.realtime()
                            RETURN id(tree)
                        ", new
                        {
                            uuid = tree.uuid,
                            type = tree.type,
                        });
                        return((result.Single())[0].As <string>());
                    });
                    logger.LogInformation(id);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                return(false);
            }
        }
Пример #3
0
        private int[] PathTree(TreeDomain tree, int id)
        {
            if (tree.id == id)
            {
                return new int[] { id }
            }
            ;

            int nodeIdRef = 0;

            int[]      intArr = new int[0];
            int        count  = 0;
            TreeDomain node   = new TreeDomain();

            while (nodeIdRef != tree.id)
            {
                Array.Resize(ref intArr, intArr.Length + 1);

                intArr[count] = id;
                count++;
                recursiveCompareNodes(ref node, tree, id);
                id        = node.id;
                nodeIdRef = node.id;
            }
            Array.Resize(ref intArr, intArr.Length + 1);
            intArr[count] = tree.id;
            return(intArr);
        }
Пример #4
0
        private static bool Menu()
        {
            Console.Clear();
            Console.WriteLine("Qual desafio deseja acessar?:");
            Console.WriteLine("1) Desafio 1 - Exibir nome e sobrenome ao lado de multiplos");
            Console.WriteLine("2) Desafio 2 - Soma De Quadrados");
            Console.WriteLine("3) Desafio 3 - Sequencia Fibonnaci");
            Console.WriteLine("4) Desafio 4 - Árvore e nós");
            Console.WriteLine("5) Desafio 5 - Não implementado");
            Console.WriteLine("6) Desafio 6 - Números Triangulos");
            Console.WriteLine("0) Sair");
            Console.Write("\r\nSelecione uma opção: ");

            switch (Console.ReadLine())
            {
            case "1":
                QuestionFactory <IQuestion> .Register(1, () => new FirstQuestion("Renan", "Tavares"));

                ExecuteQuestion(1);
                return(true);

            case "2":
                QuestionFactory <IQuestion> .Register(2, () => new SecondQuestion(new int[] { 1, 2, 3, 4, 5 }));

                ExecuteQuestion(2);
                return(true);

            case "3":
                QuestionFactory <IQuestion> .Register(3, () => new ThirdQuestion());

                ExecuteQuestion(3);
                return(true);

            case "4":
                QuestionFactory <IQuestion> .Register(4, () => new FourthQuestion(TreeDomain.GenerateTree(), 9));

                ExecuteQuestion(4);
                return(true);

            case "5":
                Console.WriteLine("Não implementado");
                return(false);

            case "6":
                QuestionFactory <IQuestion> .Register(6, () => new SixthQuestion("SKY"));

                ExecuteQuestion(6);
                return(true);

            default:
                return(false);
            }
        }
Пример #5
0
        public void TestDesafio4()
        {
            QuestionFactory <IQuestion> .Register(4, () => new FourthQuestion(TreeDomain.GenerateTree(), 9));

            IQuestion question = QuestionFactory <IQuestion> .Create(4);

            var result = question.Execute();

            int[] actual = result.ListResultsInt.ToArray();
            Array.Reverse(actual);
            CollectionAssert.AreEqual(new int[] { 1, 4, 2, 12, 13, 9 }, actual);
        }
Пример #6
0
        public ActionResult Challenge()
        {
            ViewBag.Message = "Desafio 4.";
            QuestionFactory <IQuestion> .Register(4, () => new FourthQuestion(TreeDomain.GenerateTree(), 9));

            IQuestion question = QuestionFactory <IQuestion> .Create(4);

            var result = question.Execute();
            var model  = new DesafioModel();

            model.Resultado = result.ListResultsInt.ToArray();
            return(View(model));
        }
Пример #7
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFoundView());
            }

            TreeDomain = await _context.TreeDomains
                         .Include(t => t.Parent).FirstOrDefaultAsync(m => m.Id == id);

            if (TreeDomain == null)
            {
                return(NotFoundView());
            }
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFoundView());
            }

            TreeDomain = await _context.TreeDomains.FindAsync(id);

            if (TreeDomain != null)
            {
                _context.TreeDomains.Remove(TreeDomain);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #9
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFoundView());
            }

            TreeDomain = await _context.TreeDomains
                         .Include(t => t.Parent).FirstOrDefaultAsync(m => m.Id == id);

            if (TreeDomain == null)
            {
                return(NotFoundView());
            }
            ViewData["ParentId"] = new SelectList(_context.TreeDomains, "Id", "SampleColumn");
            return(Page());
        }
Пример #10
0
 public static void recursiveCompareNodes(ref TreeDomain node, TreeDomain tree, int id)
 {
     if (tree.nodes != null)
     {
         foreach (var el in tree.nodes)
         {
             if (el.id == id)
             {
                 node = tree;
             }
             else
             {
                 recursiveCompareNodes(ref node, el, id);
             }
         }
     }
 }
Пример #11
0
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFoundView());
            }

            TreeDomain = await _context.TreeDomains
                         .Include(t => t.CreationUser)
                         .Include(t => t.LastModificationUser)
                         .Include(t => t.Parent).FirstOrDefaultAsync(m => m.Id == id);

            if (TreeDomain == null)
            {
                return(NotFoundView());
            }
            ViewData["CreationUserId"]         = new SelectList(_context.Users, "Id", "UserName");
            ViewData["LastModificationUserId"] = new SelectList(_context.Users, "Id", "UserName");
            ViewData["ParentId"] = new SelectList(_context.TreeDomains, "Id", "SampleColumn");
            return(Page());
        }
Пример #12
0
        public static TreeDomain GenerateTree()
        {
            var node8 = new TreeDomain()
            {
                id = 8
            };
            var node9 = new TreeDomain()
            {
                id = 9
            };
            var node6 = new TreeDomain()
            {
                id = 6
            };
            var node5 = new TreeDomain()
            {
                id = 5
            };
            var node3 = new TreeDomain()
            {
                id = 3
            };

            var node10 = new TreeDomain()
            {
                id = 10, nodes = new TreeDomain[] { node8 }
            };
            var node13 = new TreeDomain()
            {
                id = 13, nodes = new TreeDomain[] { node9 }
            };
            var node11 = new TreeDomain()
            {
                id = 11, nodes = new TreeDomain[] { node6, node5 }
            };

            var node12 = new TreeDomain()
            {
                id = 12, nodes = new TreeDomain[] { node13 }
            };

            var node2 = new TreeDomain()
            {
                id = 2, nodes = new TreeDomain[] { node12 }
            };

            var node4 = new TreeDomain()
            {
                id = 4, nodes = new TreeDomain[] { node10, node2 }
            };
            var node7 = new TreeDomain()
            {
                id = 7, nodes = new TreeDomain[] { node3, node11 }
            };

            var tree = new TreeDomain()
            {
                id = 1, nodes = new TreeDomain[] { node4, node7 }
            };

            return(tree);
        }
Пример #13
0
 public FourthQuestion(TreeDomain tree, int id)
 {
     this._tree = tree;
     this._id   = id;
 }