コード例 #1
0
ファイル: HomeController.cs プロジェクト: cchanal/documentify
        public ActionResult CreateProject([Bind(Include = "id_projet,nom,description")] projet projet)
        {
            HomePageViewModel model = new HomePageViewModel();

            if (ModelState.IsValid)
            {
                page homePage = new page
                {
                    titre = "HomePage",
                    numero = 0
                };

                projet.pages.Add(homePage);
                db.projets.Add(projet);

                db.SaveChanges();

                model = createDefaultHomeViewModel();
                model.validation = true;
                model.validationMessage = "Projet crée avec succès";

                return View("Index", model);
            }

            model = createDefaultHomeViewModel();
            model.projet = projet;
            model.creation = true;

            return View("Index", model);
        }
コード例 #2
0
        private PageViewModel createDefaultPageViewModel(page currentPage)
        {
            PageViewModel model = new PageViewModel();
            model.titre = currentPage.titre;
            model.description = currentPage.description;
            model.id_projet = currentPage.id_projet;

            IEnumerable<page> pages = db.projets.Find(currentPage.id_projet).pages.OrderBy(p => p.numero);
            IList<PageLinkViewModel> pagesLinks = new List<PageLinkViewModel>();

            foreach (page p in pages)
            {
                PageLinkViewModel link = new PageLinkViewModel();
                link.titre = p.titre;
                link.page_url = "/pages/Details/" + p.id_page;

                if (currentPage.id_page == p.id_page)
                {
                    link.isCurrent = true;
                }
                else
                {
                    link.isCurrent = false;
                }
                pagesLinks.Add(link);
            }

            model.pages = pagesLinks;
            model.sections = currentPage.sections.OrderBy(s => s.ordre);

            model.page = new page();
            model.page.id_page = currentPage.id_page;
            model.page.id_projet = currentPage.id_projet;
            model.page.numero = pages.Max(p => p.numero) + 1;

            return model;
        }