Esempio n. 1
0
        // Gets the "table" of that section
        public IEnumerable <SectionRow> getTable(List <Section> sections)
        {
            List <SectionRow> sectionTable    = new List <SectionRow>();
            List <int>        visitedSections = sections.Select(s => s.ID).ToList();
            int i = 1;

            // Visit each section of the row
            while (visitedSections.Count > 0)
            {
                SectionRow row = new SectionRow();
                row.Order = i;
                List <Section> columns = new List <Section>();
                List <Section> Parents = sections.Where(s => s.ParentID == 0).ToList();
                // Get the parent if any exist for each column
                if (i != 1)
                {
                    Parents = new List <Section>();
                    SectionRow parentRow = sectionTable.Where(t => t.Order == i - 1).FirstOrDefault();
                    foreach (var p in parentRow.Row)
                    {
                        foreach (var s in sections.Where(s => s.ParentID == p.ID))
                        {
                            Parents.Add(s);
                        }
                    }
                }
                // Add the parent column and remove it from the visitedSections
                foreach (var s in Parents)
                {
                    columns.Add(s);
                    visitedSections.Remove(s.ID);
                }
                row.Row = columns;
                sectionTable.Add(row);
                i++;
            }

            return(sectionTable);
        }
Esempio n. 2
0
        // Gets the "table" of that section
        public IEnumerable<SectionRow> getTable(List<Section> sections)
        {
            List<SectionRow> sectionTable = new List<SectionRow>();
            List<int> visitedSections = sections.Select(s => s.ID).ToList();
            int i = 1;

            // Visit each section of the row
            while (visitedSections.Count > 0)
            {
                SectionRow row = new SectionRow();
                row.Order = i;
                List<Section> columns = new List<Section>();
                List<Section> Parents = sections.Where(s => s.ParentID == 0).ToList();
                // Get the parent if any exist for each column
                if (i != 1)
                {
                    Parents = new List<Section>();
                    SectionRow parentRow = sectionTable.Where(t => t.Order == i - 1).FirstOrDefault();
                    foreach (var p in parentRow.Row)
                    {
                        foreach (var s in sections.Where(s => s.ParentID == p.ID))
                        {
                            Parents.Add(s);
                        }
                    }
                }
                // Add the parent column and remove it from the visitedSections
                foreach (var s in Parents)
                {
                    columns.Add(s);
                    visitedSections.Remove(s.ID);
                }
                row.Row = columns;
                sectionTable.Add(row);
                i++;
            }

            return sectionTable;
        }
Esempio n. 3
0
        public ActionResult Index(int? id, string errMessage = "",
            bool sectionOpen = false, bool categoryOpen = false, bool tagOpen = false,
            bool sectionEditOpen = false, bool categoryEditOpen = false, bool tagEditOpen = false, bool boardEditOpen = false, bool cardEditOpen = false)
        {
            BoardViewModel view = new BoardViewModel();
            string user = User.Identity.GetUserId();
            if (db.Boards.Where(b => b.OwnerID == user).Count() > 0)
            {
                List<Board> boards = db.Boards.Where(b => b.OwnerID == user).ToList();
                List<MiniBoard> miniBoards = new List<MiniBoard>();
                foreach (var b in boards)
                {
                    MiniBoard m = new MiniBoard(b.ID, b.Title);
                    miniBoards.Add(m);
                }
                view.Boards = miniBoards;

                if (id == null)
                {
                    view.SelectedBoard = boards.FirstOrDefault();
                }
                else
                {
                    Board origBoard = db.Boards.Find(id);
                    if (origBoard == null)
                        return HttpNotFound();
                    Board selectedBoard = boards.Where(b => b.ID == id).FirstOrDefault();
                    if (selectedBoard == null)
                        return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
                    view.SelectedBoard = selectedBoard;
                }

                SectionRow row = new SectionRow();
                view.SectionTable = row.getTable(view.SelectedBoard.Sections.ToList());
                foreach (var r in view.SectionTable)
                {
                    r.Row = r.Row.OrderBy(rr => rr.Order).ToList();
                }
                view.ActiveSections = row.getActiveSections(view.SelectedBoard.Sections.ToList(), view.SectionTable);
                List<Section> sections = view.SelectedBoard.Sections.OrderBy(s => s.ParentID).ThenBy(s => s.Order).ToList();
                view.SelectedBoard.Sections = sections;
                List<Card> cards = new List<Card>();
                foreach (var item in view.ActiveSections)
                {
                    cards.AddRange(item.Cards);
                    List<Card> orderCards = item.Cards.OrderBy(c => c.Order).ToList();
                    item.Cards = orderCards;
                }
                ViewBag.uncategorizedCards = cards.Count > 0 ? true : false;
            }

            ViewBag.sectionOpen = sectionOpen;
            ViewBag.categoryOpen = categoryOpen;
            ViewBag.tagOpen = tagOpen;
            ViewBag.sectionEditOpen = sectionEditOpen;
            ViewBag.categoryEditOpen = categoryEditOpen;
            ViewBag.tagEditOpen = tagEditOpen;
            ViewBag.boardEditOpen = boardEditOpen;
            ViewBag.cardEditOpen = cardEditOpen;
            ViewBag.errorMessage = errMessage;
            return View(view);
        }