Exemple #1
0
        public ActionResult Edit(long?block_id)
        {
            using (TemplateRepository template_repository = new TemplateRepository())
            {
                ViewBag.templates = template_repository.All(CurrentUser.user_domain);

                if (block_id.HasValue)
                {
                    using (BlockRepository block_repository = new BlockRepository())
                    {
                        ViewBag.item = block_repository.GetByID(block_id.Value);
                    }
                }
            }

            return(View());
        }
        public ActionResult Edit(long?content_id, long block_id, long?content_root, long?content_template)
        {
            ViewBag.domain_id = CurrentUser.user_domain;

            ViewBag.content_id = content_id;

            ViewBag.block_id = block_id;

            ViewBag.content_root = content_root;

            using (BlockRepository block_repository = new BlockRepository())
            {
                using (ContentRepository content_repository = new ContentRepository())
                {
                    using (TemplateRepository template_repository = new TemplateRepository())
                    {
                        ViewBag.block = block_repository.GetByID(block_id);

                        string allow_templates = string.Empty;

                        if (content_root.HasValue)
                        {
                            dynamic root_item = content_repository.GetByID(content_root.Value);

                            dynamic root_template = template_repository.GetByID(root_item.content_template);

                            allow_templates = root_template.template_allow_subpartitions && root_item.content_block == block_id ? root_template.template_templates : string.Empty;
                        }

                        if (content_id.HasValue)
                        {
                            ViewBag.item = content_repository.GetByID(content_id.Value);
                        }

                        ViewBag.templates = template_repository.GetByIDs(string.IsNullOrWhiteSpace(allow_templates) ? ViewBag.block.block_templates : allow_templates);
                    }
                }
            }

            if (ViewBag.templates.Count > 0)
            {
                ViewBag.current_template = ViewBag.templates[0];

                foreach (var template in ViewBag.templates)
                {
                    if (content_template.HasValue)
                    {
                        if (content_template.Value == template.template_id)
                        {
                            ViewBag.current_template = template;
                            break;
                        }
                    }
                    else if (ViewBag.item != null && template.template_id == ViewBag.item.content_template)
                    {
                        ViewBag.current_template = template;
                        break;
                    }
                }

                using (ViewRepository view_repository = new ViewRepository())
                {
                    ViewBag.content_views = view_repository.GetByIDs(ViewBag.current_template.template_views);
                }

                using (FieldRepository field_repository = new FieldRepository())
                {
                    ViewBag.fields = field_repository.GetByIDs(ViewBag.current_template.template_fields);
                }
            }

            return(View());
        }
        public ActionResult Index(long block_id, long?page, long?content_root)
        {
            ViewBag.block_id = block_id;

            dynamic block = null;

            using (BlockRepository block_repository = new BlockRepository())
            {
                block = block_repository.GetByID(block_id);

                ViewBag.blcoks = block_repository.All(CurrentUser.user_domain);
            }

            content_root = content_root ?? block.block_content_root;

            ViewBag.content_root = content_root;

            page = page ?? 1;

            long totals;

            using (ContentRepository content_repository = new ContentRepository())
            {
                string order_by = (string.IsNullOrWhiteSpace(block.block_order_fields) || block.block_allow_sort ? "content_order, content_publish desc" : block.block_order_fields);

                if (content_root.HasValue)
                {
                    using (TemplateRepository template_repository = new TemplateRepository())
                    {
                        dynamic root_item = content_repository.GetByID(content_root.Value);

                        dynamic root_template = template_repository.GetByID(root_item.content_template);

                        if (root_template.template_allow_subpartitions)
                        {
                            ViewBag.template_allow_sort = root_template.template_allow_sort;

                            order_by = (string.IsNullOrWhiteSpace(root_template.template_order_fields) || root_template.template_allow_sort ? "content_order, content_publish desc" : root_template.template_order_fields);
                        }
                    }
                }

                ViewBag.items = content_repository.Get(CurrentUser.user_domain, block_id, content_root, order_by, page ?? 1, block.block_allow_sort ? Int64.MaxValue : 50, out totals);
            }

            ViewBag.page = page;

            ViewBag.totals = totals;

            List <dynamic> nav = content_root != null?ModelUtility.GetNavi(content_root, block.block_content_root, false) : new List <dynamic>();

            if (nav.Count > 0 && block.block_content_root == null)
            {
                nav.Insert(0, null);
            }

            ViewBag.nav = nav;

            ViewBag.block = block;


            return(View());
        }