public virtual ActionResult SavePageCommonSettings(PageViewModel model)
        {
            if (ModelState.IsValid)
            {
                var page = new Page();
                if (!permissionService.IsAllowed((Int32)PageOperations.AddNewPages, this.CorePrincipal(), typeof(Page), null))
                {
                    throw new HttpException((int)HttpStatusCode.NotFound, Translate("Messages.NotFound"));
                }

                page.OrderNumber = pageService.GetLastOrderNumber(model.ParentPageId == 0 ? null : model.ParentPageId);
                if (this.CorePrincipal() != null)
                    page.User = new User
                    {
                        Id = this.CorePrincipal().PrincipalId
                    };
                page = model.MapTo(page);
                if (!model.TemplateId.HasValue)
                {
                    page.PageLayout = new PageLayout
                    {
                        LayoutTemplate = LayoutHelper.DefaultLayoutTemplate,
                        Page = page
                    };
                }
                if (pageService.Save(page))
                {
                    permissionService.SetupDefaultRolePermissions(
                        ResourcePermissionsHelper.GetResourceOperations(typeof(Page)), typeof(Page), page.Id);
                    if (model.ClonedPageId != null)
                    {
                        var sourcePage = pageService.Find((long)model.ClonedPageId);
                        if (permissionService.IsAllowed((Int32)PageOperations.View, this.CorePrincipal(),
                                                        typeof(Page), sourcePage.Id, IsPageOwner(sourcePage),
                                                        PermissionOperationLevel.Object))
                        {
                            PageHelper.ClonePageSettings(sourcePage, page);
                        }
                    }
                    else if (model.TemplateId.HasValue)
                    {
                        var sourceTemplate = pageService.Find((long)model.TemplateId);
                        if (permissionService.IsAllowed((Int32)PageOperations.View, this.CorePrincipal(),
                                                        typeof(Page), sourceTemplate.Id, IsPageOwner(sourceTemplate),
                                                        PermissionOperationLevel.Object))
                        {
                            PageHelper.ClonePageSettingsFromTemplate(sourceTemplate, page, model.WidgetId);
                        }
                    }

                    TempData["Success"] = true;
                }

                model = model.MapFrom(page);
            }
            else Error(Translate("Messages.ValidationError"));

            return PartialView(MVC.Pages.Views.PageCreateForm, model);
        }
        public virtual ActionResult SavePageCommonSettings(PageViewModel model)
        {
            if (ModelState.IsValid)
            {
                var page = new Page();
                if (!permissionService.IsAllowed((Int32)PageOperations.AddNewPages, this.CorePrincipal(), typeof(Page), null))
                {
                    throw new HttpException((int)HttpStatusCode.NotFound, Translate("Messages.NotFound"));
                }

                page.OrderNumber = pageService.GetLastOrderNumber(model.ParentPageId == 0 ? null : model.ParentPageId);
                if (this.CorePrincipal() != null)
                {
                    page.User = new User
                    {
                        Id = this.CorePrincipal().PrincipalId
                    }
                }
                ;
                page = model.MapTo(page);
                if (!model.TemplateId.HasValue)
                {
                    page.PageLayout = new PageLayout
                    {
                        LayoutTemplate = LayoutHelper.DefaultLayoutTemplate,
                        Page           = page
                    };
                }
                if (pageService.Save(page))
                {
                    permissionService.SetupDefaultRolePermissions(
                        ResourcePermissionsHelper.GetResourceOperations(typeof(Page)), typeof(Page), page.Id);
                    if (model.ClonedPageId != null)
                    {
                        var sourcePage = pageService.Find((long)model.ClonedPageId);
                        if (permissionService.IsAllowed((Int32)PageOperations.View, this.CorePrincipal(),
                                                        typeof(Page), sourcePage.Id, IsPageOwner(sourcePage),
                                                        PermissionOperationLevel.Object))
                        {
                            PageHelper.ClonePageSettings(sourcePage, page);
                        }
                    }
                    else if (model.TemplateId.HasValue)
                    {
                        var sourceTemplate = pageService.Find((long)model.TemplateId);
                        if (permissionService.IsAllowed((Int32)PageOperations.View, this.CorePrincipal(),
                                                        typeof(Page), sourceTemplate.Id, IsPageOwner(sourceTemplate),
                                                        PermissionOperationLevel.Object))
                        {
                            PageHelper.ClonePageSettingsFromTemplate(sourceTemplate, page, model.WidgetId);
                        }
                    }

                    TempData["Success"] = true;
                }

                model = model.MapFrom(page);
            }
            else
            {
                Error(Translate("Messages.ValidationError"));
            }

            return(PartialView(MVC.Pages.Views.PageCreateForm, model));
        }