Example #1
0
        public ActionResult Create(string type)
        {
            if (!_orchardServices.Authorizer.Authorize(Permissions.ManageForums, T("Not allowed to create forums")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (string.IsNullOrWhiteSpace(type))
            {
                var forumTypes = _forumService.GetForumTypes();
                if (forumTypes.Count > 1)
                {
                    return(Redirect(Url.ForumSelectTypeForAdmin()));
                }

                if (forumTypes.Count == 0)
                {
                    _orchardServices.Notifier.Warning(T("You have no forum types available. Add one to create a forum."));
                    return(Redirect(Url.DashboardForAdmin()));
                }

                type = forumTypes.Single().Name;
            }

            var forum = _contentManager.New <ForumPart>(type);

            if (forum == null)
            {
                return(HttpNotFound());
            }

            var model = _contentManager.BuildEditor(forum);

            return(View((object)model));
        }
        public ActionResult Edit(int id)
        {
            if (!_orchardServices.Authorizer.Authorize(Permissions.ManageContact))
            {
                return(new HttpUnauthorizedResult());
            }
            object model;

            if (id == 0)
            {
                var newContent = _contentManager.New(contentType);
                //if (idCampaign > 0) {
                //    List<int> lids = new List<int>();
                //    lids.Add(idCampaign);
                //    ((dynamic)newContent).CommunicationAdvertisingPart.Campaign.Ids = lids.ToArray();
                //}
                //  model = _contentManager.BuildEditor(newContent);
                //   _contentManager.Create(newContent);
                model = _contentManager.BuildEditor(newContent);
            }
            else
            {
                model = _contentManager.BuildEditor(_contentManager.Get(id, VersionOptions.Latest));
            }
            return(View((object)model));
        }
        public ActionResult Edit(int id, int idCampaign = 0)
        {
            if (!_orchardServices.Authorizer.Authorize(TestPermission))
            {
                return(new HttpUnauthorizedResult());
            }
            object model;

            if (id == 0)
            {
                var newContent = _contentManager.New(contentType);
                if (idCampaign > 0)
                {
                    newContent.As <CommunicationAdvertisingPart>().CampaignId = idCampaign;
                }
                //  model = _contentManager.BuildEditor(newContent);
                //   _contentManager.Create(newContent);
                model = _contentManager.BuildEditor(newContent);
            }
            else
            {
                model = _contentManager.BuildEditor(_contentManager.Get(id, VersionOptions.Latest));
            }
            return(View((object)model));
        }
Example #4
0
        public ActionResult Create(string returnUrl = null)
        {
            var customerPart = _customersService.GetCustomer();

            if (customerPart == null)
            {
                if (Services.Authorizer.Authorize(CustomersPermissions.EditOwnCustomerAccount, T("You are not allowed to create an account.")))
                {
                    var customer = _contentManager.New("Customer");
                    customerPart = customer.As <CustomerPart>();
                    if (customerPart != null)
                    {
                        customerPart.User = Services.WorkContext.CurrentUser;
                    }
                    return(View(_contentManager.BuildEditor(customer)));
                }
                else
                {
                    return(this.RedirectLocal(returnUrl, () => new HttpUnauthorizedResult()));
                }
            }
            else
            {
                return(RedirectToAction("Edit", new { ReturnUrl = returnUrl }));
            }
        }
        public ActionResult Create(string id, int?containerId)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(CreatableTypeList(containerId));
            }

            var contentItem = _contentManager.New(id);

            if (!Services.Authorizer.Authorize(Permissions.EditContent, contentItem, T("Cannot create content")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (containerId.HasValue && contentItem.Is <ContainablePart>())
            {
                var common = contentItem.As <CommonPart>();
                if (common != null)
                {
                    common.Container = _contentManager.Get(containerId.Value);
                }
            }

            dynamic model = _contentManager.BuildEditor(contentItem);

            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
            return(View((object)model));
        }
Example #6
0
        public ActionResult Create(string id, int?containerId)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(CreatableTypeList(containerId));
            }

            if (_contentDefinitionManager.GetTypeDefinition(id) == null)
            {
                return(RedirectToAction("Create", new { id = "" }));
            }

            var contentItem = _contentManager.New(id);

            if (!Services.Authorizer.Authorize(Permissions.CreateContent, contentItem, T("Cannot create content")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (containerId.HasValue && contentItem.Is <ContainablePart>())
            {
                var common = contentItem.As <CommonPart>();
                if (common != null)
                {
                    common.Container = _contentManager.Get(containerId.Value);
                }
            }

            var model = _contentManager.BuildEditor(contentItem);

            return(View(model));
        }
Example #7
0
 public dynamic BuildEditor(IContent content)
 {
     if (content.Is <FrontendEditConfigurationPart>())
     {
         return(_frontEndEditService.BuildFrontEndShape(
                    _contentManager.BuildEditor(content),
                    PartTest,
                    FieldTest));
     }
     return(_contentManager.BuildEditor(content));
 }
        public ActionResult Create()
        {
            var mirroringConfiguration = _contentManager.New(ContentTypes.MirroringConfiguration);

            if (!IsAuthorizedToEditMirroringConfiguration(mirroringConfiguration))
            {
                return(new HttpUnauthorizedResult());
            }

            return(View(_contentManager.BuildEditor(mirroringConfiguration)));
        }
        public ActionResult Register()
        {
            // ensure users can register
            var registrationSettings = _orchardServices.WorkContext.CurrentSite.As <RegistrationSettingsPart>();

            if (!registrationSettings.UsersCanRegister)
            {
                return(HttpNotFound());
            }

            ViewData["PasswordLength"] = MinPasswordLength;

            var shape = _orchardServices.New.Register();

            var user = _orchardServices.ContentManager.New("User");

            if (user != null && !_frontEndProfileService.UserHasNoProfilePart(user.As <IUser>()))
            {
                shape.UserProfile = _frontEndProfileService.BuildFrontEndShape(
                    _contentManager.BuildEditor(user),
                    _frontEndProfileService.MayAllowPartEdit,
                    _frontEndProfileService.MayAllowFieldEdit);
            }

            return(new ShapeResult(this, shape));
        }
Example #10
0
        public ActionResult Translate(int id, string to)
        {
            var masterContentItem = _contentManager.Get(id, VersionOptions.Latest);

            if (masterContentItem == null)
            {
                return(HttpNotFound());
            }

            var masterLocalizationPart = masterContentItem.As <LocalizationPart>();

            if (masterLocalizationPart == null)
            {
                return(HttpNotFound());
            }

            // Check is current item stll exists, and redirect.
            var existingTranslation = _localizationService.GetLocalizedContentItem(masterContentItem, to);

            if (existingTranslation != null)
            {
                var existingTranslationMetadata = _contentManager.GetItemMetadata(existingTranslation);
                return(RedirectToAction(
                           Convert.ToString(existingTranslationMetadata.EditorRouteValues["action"]),
                           existingTranslationMetadata.EditorRouteValues));
            }

            var contentItemTranslation = _contentManager.New <LocalizationPart>(masterContentItem.ContentType);

            contentItemTranslation.MasterContentItem = masterLocalizationPart.MasterContentItem == null ? masterContentItem : masterLocalizationPart.MasterContentItem;

            var content = _contentManager.BuildEditor(contentItemTranslation);

            return(View(content));
        }
        private ShapeResult PersonListDashboardShapeResult(ContentItem item)
        {
            // The editor shape is the tree of shapes containing every shape needed to build the editor of the item. E.g.
            // it contains all the parts' editor shapes that build up the item.
            var itemEditorShape = _contentManager.BuildEditor(item);

            /*
             * Now this is interesting! We've created a new ad-hoc shape here, called PersonListDashboard and passed it
             *  some data.
             *
             * Essentially we instantiated a new dynamic shape object here (called PersonListDashboard) and added
             * properties to it. We use the shape here as a kind of view model. However since this shape, inside a
             * ShapeResult, is returned from our action it will be used like a view too: Orchard will display it (just
             * as we call Display() on the Person List item's editor shape in the editor template as you'll soon see),
             * meaning Orchard will try to find a corresponding template for the shape.
             *
             * Orchard will try to find a corresponding template by probing for conventionally named files. We happen to
             * have one under Views/TrainingDemo.PersonListDashboard. Notice two things: first, dots in template names
             * are converted to underscores in shape names (and dashes to double underscores) and that we use a kind of
             * namespacing by prefixing the name with the module's name. Since shape names are global, this way the
             * uniqueness can be ensured.
             *
             * You could also create a statically typed view model and use standard MVC views too of course.
             *
             * NEXT STATION: Check out Views/PersonListDashboard and come back here!
             *
             * NEXT STATION: Check out the two other actions in this controller: LatestPersonLists and LatestPersonList!
             *
             */
            var editorShape = _orchardServices.New.TrainingDemo_PersonListDashboard(EditorShape: itemEditorShape);

            return(new ShapeResult(this, editorShape));
        }
Example #12
0
        /// <summary>
        /// Defines the shapes required for the part's main view.
        /// </summary>
        /// <param name="part">The part.</param>
        /// <param name="displayType">The display type.</param>
        /// <param name="shapeHelper">The shape helper.</param>
        protected override DriverResult Display(ContactFormPart part, string displayType, dynamic shapeHelper)
        {
            var viewModel = new ContactFormViewModel();

            if (part != null && displayType.Contains("Detail"))
            {
                viewModel.ContentRecordId     = part.Record.Id;
                viewModel.ShowSubjectField    = !part.UseStaticSubject;
                viewModel.ShowNameField       = part.DisplayNameField;
                viewModel.RequireNameField    = part.RequireNameField;
                viewModel.EnableFileUpload    = part.EnableUpload;
                viewModel.AcceptPolicy        = part.AcceptPolicy;
                viewModel.AcceptPolicyText    = part.AcceptPolicyText;
                viewModel.AcceptPolicyUrl     = part.AcceptPolicyUrl;
                viewModel.AcceptPolicyUrlText = part.AcceptPolicyUrlText;
                return(ContentShape("Parts_ContactForm",
                                    () => shapeHelper.Parts_ContactForm(
                                        ContactForm: viewModel,
                                        AdditionalShape: _frontEndEditService.BuildFrontEndShape(
                                            _contentManager.BuildEditor(part),
                                            OnlyShowReCaptcha,
                                            NoFields)
                                        )));
            }
            return(null); // don't display if display type is not "detail"
        }
        public ActionResult Create(int id)
        {
            var form = _contentManager.Get(id);

            if (form == null || !form.Has <CustomFormPart>())
            {
                return(HttpNotFound());
            }

            var customForm = form.As <CustomFormPart>();

            var contentItem = _contentManager.New(customForm.ContentType);

            if (!contentItem.Has <ICommonPart>())
            {
                throw new OrchardException(T("The content type must have CommonPart attached"));
            }

            if (!Services.Authorizer.Authorize(Permissions.CreateSubmitPermission(customForm.ContentType), contentItem, T("Cannot create content")))
            {
                return(new HttpUnauthorizedResult());
            }

            var model = _contentManager.BuildEditor(contentItem);

            model
            .ContentItem(form)
            .ReturnUrl(Url.RouteUrl(_contentManager.GetItemMetadata(form).DisplayRouteValues));

            return(View(model));
        }
        protected override DriverResult Display(ScriptingAdminTestbedPart part, string displayType, dynamic shapeHelper)
        {
            return(Combined(
                       ContentShape("Pages_ScriptingAdminTestbed_ScriptPicker",
                                    () => shapeHelper.DisplayTemplate(
                                        TemplateName: "Pages/Admin/Testbed.ScriptPicker",
                                        Model: part,
                                        Prefix: Prefix)),
                       ContentShape("Pages_ScriptingAdminTestbed",
                                    () => {
                if (part.ScriptId == 0)
                {
                    part.EditorShape = part.EditorShape ?? _contentManager.BuildEditor(_contentManager.New("Script"));
                }
                else if (part.Script == null)
                {
                    part.Script = _contentManager.Get(part.ScriptId, VersionOptions.Latest);
                }

                return shapeHelper.DisplayTemplate(
                    TemplateName: "Pages/Admin/Testbed",
                    Model: part,
                    Prefix: Prefix);
            })));
        }
Example #15
0
        public ActionResult Register()
        {
            // ensure users can register
            var membershipSettings = _membershipService.GetSettings();

            if (!membershipSettings.UsersCanRegister)
            {
                return(HttpNotFound());
            }

            ViewData["PasswordLength"]              = membershipSettings.GetMinimumPasswordLength();
            ViewData["LowercaseRequirement"]        = membershipSettings.GetPasswordLowercaseRequirement();
            ViewData["UppercaseRequirement"]        = membershipSettings.GetPasswordUppercaseRequirement();
            ViewData["SpecialCharacterRequirement"] = membershipSettings.GetPasswordSpecialRequirement();
            ViewData["NumberRequirement"]           = membershipSettings.GetPasswordNumberRequirement();

            var shape = _orchardServices.New.Register();

            var user = _orchardServices.ContentManager.New("User");

            if (user != null && !_frontEndProfileService.UserHasNoProfilePart(user.As <IUser>()))
            {
                shape.UserProfile = ((IFrontEndEditService)_frontEndProfileService).BuildFrontEndShape(
                    _contentManager.BuildEditor(user),
                    _frontEndProfileService.MayAllowPartEdit,
                    _frontEndProfileService.MayAllowFieldEdit);
            }

            return(new ShapeResult(this, shape));
        }
Example #16
0
        public ActionResult Create(int id)
        {
            var form = _contentManager.Get(id);

            if (form == null || !form.Has <CustomFormPart>())
            {
                return(HttpNotFound());
            }

            var customForm = form.As <CustomFormPart>();

            var contentItem = _contentManager.New(customForm.ContentType);

            if (!contentItem.Has <ICommonPart>())
            {
                throw new OrchardException(T("The content type must have CommonPart attached"));
            }

            if (!Services.Authorizer.Authorize(Permissions.CreateSubmitPermission(customForm.ContentType), contentItem, T("Cannot create content")))
            {
                return(new HttpUnauthorizedResult());
            }

            dynamic model = _contentManager.BuildEditor(contentItem);

            model
            .ContenItem(form)
            .ReturnUrl(Url.RouteUrl(_contentManager.GetItemMetadata(form).DisplayRouteValues));

            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
            return(View((object)model));
        }
Example #17
0
        public ActionResult CreateTerritory(string id, int hierarchyId)
        {
            // id is the name of the ContentType for the territory we are trying to create. By calling
            // that argument "id" we can use the standard MVC routing (i.e. controller/action/id?querystring).
            // This is especially nice on POST calls.
            ActionResult redirectTo;

            if (ShouldRedirectForPermissions(hierarchyId, out redirectTo))
            {
                return(redirectTo);
            }

            // The null checks for these objects are done in ShouldRedirectForPermissions
            var hierarchyItem  = _contentManager.Get(hierarchyId, VersionOptions.Latest);
            var hierarchyPart  = hierarchyItem.As <TerritoryHierarchyPart>();
            var hierarchyTitle = _contentManager.GetItemMetadata(hierarchyItem).DisplayText;

            if (!id.Equals(hierarchyPart.TerritoryType, StringComparison.OrdinalIgnoreCase))
            {
                // The hierarchy expects a TerritoryType different form the one we are trying to create
                var errorText = string.IsNullOrWhiteSpace(hierarchyTitle) ?
                                T("The requested type \"{0}\" does not match the expected TerritoryType for the hierarchy.", id) :
                                T("The requested type \"{0}\" does not match the expected TerritoryType for hierarchy \"{1}\".", id, hierarchyTitle);
                AddModelError("", errorText);
                return(RedirectToAction("Index"));
            }

            // There must be "unused" TerritoryInternalRecords for this hierarchy.
            if (_territoriesService
                .GetAvailableTerritoryInternals(hierarchyPart)
                .Any())
            {
                // Creation
                var territoryItem = _contentManager.New(id);
                // Cannot insert Territory in the Hierarchy here, because its records do not exist yet.
                // We will have to do it in the POST call.
                // We can and should tell the drivers for the TerritoryPart what is the hierarchy we are
                // creating territories for:
                territoryItem.As <TerritoryPart>().CreationHierarchy = hierarchyPart;
                // Allow user to Edit stuff
                var model = _contentManager.BuildEditor(territoryItem);
                return(View(model.Hierarchy(hierarchyItem)));
            }

            AddModelError("", T("There are no territories that may be added to hierarchy \"{1}\".", hierarchyTitle));
            return(RedirectToAction("Index"));
        }
Example #18
0
        protected override DriverResult Display(CommentsPart part, string displayType, dynamic shapeHelper)
        {
            if (part.CommentsShown == false)
            {
                return(null);
            }

            var commentsForCommentedContent = _commentService.GetCommentsForCommentedContent(part.ContentItem.Id);
            var pendingCount  = new Lazy <int>(() => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count());
            var approvedCount = new Lazy <int>(() => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Approved).Count());

            return(Combined(
                       ContentShape("Parts_ListOfComments",
                                    () => {
                // create a hierarchy of shapes
                var firstLevelShapes = new List <dynamic>();
                var allShapes = new Dictionary <int, dynamic>();
                var comments = commentsForCommentedContent.Where(x => x.Status == CommentStatus.Approved).OrderBy(x => x.Position).List().ToList();

                foreach (var item in comments)
                {
                    var shape = shapeHelper.Parts_Comment(ContentPart: item, ContentItem: item.ContentItem);
                    allShapes.Add(item.Id, shape);
                }

                foreach (var item in comments)
                {
                    var shape = allShapes[item.Id];
                    if (item.RepliedOn.HasValue)
                    {
                        allShapes[item.RepliedOn.Value].Add(shape);
                    }
                    else
                    {
                        firstLevelShapes.Add(shape);
                    }
                }

                var list = shapeHelper.List(Items: firstLevelShapes);

                return shapeHelper.Parts_ListOfComments(List: list, CommentCount: approvedCount.Value);
            }),
                       ContentShape("Parts_CommentForm",
                                    () => {
                var newComment = _contentManager.New("Comment");
                if (newComment.Has <CommentPart>())
                {
                    newComment.As <CommentPart>().CommentedOn = part.Id;
                }
                var editorShape = _contentManager.BuildEditor(newComment);

                return shapeHelper.Parts_CommentForm(EditorShape: editorShape);
            }),
                       ContentShape("Parts_Comments_Count",
                                    () => shapeHelper.Parts_Comments_Count(CommentCount: approvedCount.Value, PendingCount: pendingCount.Value)),
                       ContentShape("Parts_Comments_Count_SummaryAdmin",
                                    () => shapeHelper.Parts_Comments_Count_SummaryAdmin(CommentCount: approvedCount.Value, PendingCount: pendingCount.Value))
                       ));
        }
Example #19
0
        public ActionResult Edit(int id)
        {
            var address = _customerService.GetAddress(id);
            var model   = _contentManager.BuildEditor(address);

            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
            return(View((object)model));
        }
        public ActionResult Translate(int id, string to)
        {
            var contentItem = _contentManager.Get(id, VersionOptions.Latest);

            // only support translations from the site culture, at the moment at least
            if (contentItem == null)
            {
                return(HttpNotFound());
            }

            if (!contentItem.Is <LocalizationPart>() || contentItem.As <LocalizationPart>().MasterContentItem != null)
            {
                var metadata = _contentManager.GetItemMetadata(contentItem);
                return(RedirectToAction(Convert.ToString(metadata.EditorRouteValues["action"]), metadata.EditorRouteValues));
            }

            var siteCultures    = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem) && s != _cultureManager.GetSiteCulture());
            var selectedCulture = siteCultures.SingleOrDefault(s => string.Equals(s, to, StringComparison.OrdinalIgnoreCase))
                                  ?? _cultureManager.GetCurrentCulture(HttpContext); // could be null but the person doing the translating might be translating into their current culture

            //todo: need a better solution for modifying some parts when translating - or go with a completely different experience

            /*
             * if (contentItem.Has<RoutePart>()) {
             *  RoutePart routePart = contentItem.As<RoutePart>();
             *  routePart.Slug = string.Format("{0}{2}{1}", routePart.Slug, siteCultures.Any(s => string.Equals(s, selectedCulture, StringComparison.OrdinalIgnoreCase)) ? selectedCulture : "", !string.IsNullOrWhiteSpace(routePart.Slug) ? "-" : "");
             *  routePart.Path = null;
             * }*/

            if (contentItem.As <LocalizationPart>().Culture != null)
            {
                contentItem.As <LocalizationPart>().Culture.Culture = null;
            }
            var model = new AddLocalizationViewModel {
                Id = id,
                SelectedCulture = selectedCulture,
                SiteCultures    = siteCultures,
                Content         = _contentManager.BuildEditor(contentItem)
            };

            // Cancel transaction so that the routepart is not modified.
            Services.TransactionManager.Cancel();

            return(View(model));
        }
Example #21
0
        public ActionResult ViewVersion(int id, int versionId)
        {
            var contentItem = _contentManager.Get(id, VersionOptions.Number(versionId));

            if (contentItem == null)
            {
                return(HttpNotFound());
            }

            if (!_authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent, contentItem))
            {
                return(new HttpUnauthorizedResult());
            }

            var model = _contentManager.BuildEditor(contentItem);

            return(View(model));
        }
Example #22
0
        public ActionResult Edit(int id)
        {
            if (!_orchardServices.Authorizer.Authorize(TestPermission))
            {
                return(new HttpUnauthorizedResult());
            }
            object model;

            if (id == 0)
            {
                var newContent = _orchardServices.ContentManager.New(contentType);
                model = _contentManager.BuildEditor(newContent);
            }
            else
            {
                model = _contentManager.BuildEditor(_orchardServices.ContentManager.Get(id));
            }
            return(View((object)model));
        }
Example #23
0
        public static TContent BuildEditorShape <TContent>(this IContentManager manager, int id) where TContent : class, IContent
        {
            var content = manager.Get <TContent>(id);

            if (content == null)
            {
                return(null);
            }
            return(manager.BuildEditor(content));
        }
        public WidgetsContainerPartHandler(
            IContentManager contentManager,
            IWidgetManager widgetManager,
            ILocalizationService localizationService,
            ShellSettings shellSettings,
            ITaxonomyService taxonomyService)
        {
            _contentManager      = contentManager;
            _widgetManager       = widgetManager;
            _localizationService = localizationService;
            _shellSettings       = shellSettings;
            _taxonomyService     = taxonomyService;
            if (!string.IsNullOrEmpty(_shellSettings.RequestUrlPrefix))
            {
                _urlPrefix = new UrlPrefix(_shellSettings.RequestUrlPrefix);
            }
            T = NullLocalizer.Instance;

            OnRemoved <WidgetsContainerPart>((context, part) => {
                DeleteWidgets(part);
            });
            OnUpdateEditorShape <WidgetsContainerPart>((context, part) => {
                var lPart = part.ContentItem.As <LocalizationPart>();
                if (lPart != null)
                {
                    var settings = part.Settings.GetModel <WidgetsContainerSettings>();
                    if (settings.TryToLocalizeItems)
                    {
                        var culture = lPart.Culture;
                        var widgets = _widgetManager.GetWidgets(part.ContentItem.Id, part.ContentItem.IsPublished())
                                      .Where(p => p.ContentItem.Has <LocalizationPart>() &&
                                             p.ContentItem.Get <LocalizationPart>().Culture == null);
                        foreach (var widget in widgets)
                        {
                            var ci = widget.ContentItem;
                            _localizationService.SetContentCulture(ci, culture.Culture);
                            // manage taxonomy field out of the normal flow:
                            // gets translations of selected terms in taxonomy fields before BuildEditor()
                            var translatedTaxo = TranslateTaxonomies(ci, culture, _localizationService);

                            // simulates a user that opens in edit model the widget and saves it
                            // to trigger all handlers and drivers
                            var shapeWidget = _contentManager.BuildEditor(ci);
                            var shapeUpdate = _contentManager.UpdateEditor(ci, new CustomUpdater(shapeWidget, culture.Culture, Logger));

                            // sets translated terms in taxonomy fields after UpdateEditor()
                            ApplyTranslatedTaxonomies(ci, translatedTaxo, _taxonomyService);

                            ci.VersionRecord.Published = false;
                            _contentManager.Publish(ci);
                        }
                    }
                }
            });
        }
Example #25
0
        public ActionResult Translate(int id, string to)
        {
            var contentItem = _contentManager.Get(id, VersionOptions.Latest);

            if (contentItem == null)
            {
                return(HttpNotFound());
            }

            if (!contentItem.Is <LocalizationPart>() || contentItem.As <LocalizationPart>().MasterContentItem != null || string.IsNullOrEmpty(to))
            {
                var metadata = _contentManager.GetItemMetadata(contentItem);
                return(RedirectToAction(Convert.ToString(metadata.EditorRouteValues["action"]), metadata.EditorRouteValues));
            }

            var contentCulture = _localizationService.GetContentCulture(contentItem);

            var potCultures     = _cultureManager.ListCultures().Where(s => s != contentCulture);
            var selectedCulture = potCultures.SingleOrDefault(s => string.Equals(s, to, StringComparison.OrdinalIgnoreCase))
                                  ?? _cultureManager.GetCurrentCulture(HttpContext); // could be null but the person doing the translating might be translating into their current culture


            var lPs = _cultureService.GetLocalizations(contentItem.As <LocalizationPart>(), VersionOptions.Latest);
            // the existing culture are the real existing ones and the one we are creating
            var siteCultures = lPs.Select(p => p.Culture.Culture).Union(new string[] { selectedCulture }).Distinct().ToList();    // necessary because the culture in cultureRecord will be set to null before expr resolution

            if (contentItem.As <LocalizationPart>().Culture != null)
            {
                contentItem.As <LocalizationPart>().Culture.Culture = null;
            }
            var model = new AddLocalizationViewModel {
                Id = id,
                SelectedCulture = selectedCulture,
                SiteCultures    = siteCultures,
                Content         = _contentManager.BuildEditor(contentItem)
            };

            // Cancel transaction so that the CultureRecord is not modified.
            Services.TransactionManager.Cancel();

            return(View(model));
        }
Example #26
0
        // If there will be a need for extending global SEO settings it would perhaps also need the usage of separate settings into groups.
        // See site settings (Orchard.Core.Settings.Controllers.AdminController and friends for how it is done.
        public ActionResult GlobalSettings()
        {
            if (!_authorizer.Authorize(Permissions.ManageSeo, T("You're not allowed to manage SEO settings.")))
            {
                return(new HttpUnauthorizedResult());
            }

            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation, despite
            // being it highly unlikely with Onestop, just in case...
            return(View((object)_contentManager.BuildEditor(_seoSettingsManager.GetGlobalSettings())));
        }
        private ActionResult CreateHierarchy(ContentTypeDefinition typeDefinition)
        {
            if (AllowedHierarchyTypes == null)
            {
                return(new HttpUnauthorizedResult(TerritoriesUtilities.Default401HierarchyMessage));
            }
            if (!AllowedHierarchyTypes.Any(ty => ty.Name == typeDefinition.Name))
            {
                return(new HttpUnauthorizedResult(TerritoriesUtilities.SpecificHierarchy401Message(typeDefinition.DisplayName)));
            }
            if (!typeDefinition.Parts.Any(pa => pa.PartDefinition.Name == TerritoryHierarchyPart.PartName))
            {
                AddModelError("", T("The requested type \"{0}\" is not a Hierarchy type.", typeDefinition.DisplayName));
                return(RedirectToAction("Index"));
            }
            //We should have filtered out the cases where we cannot or should not be creating the new item here
            var hierarchyItem = _contentManager.New(typeDefinition.Name);
            var model         = _contentManager.BuildEditor(hierarchyItem);

            return(View(model));
        }
        private ActionResult EditImplementation(IContent content, string folderPath)
        {
            if (!_authorizer.Authorize(Permissions.ManageCloudMediaContent, T("You are not authorized to manage Microsoft Azure Media content.")))
            {
                return(new HttpUnauthorizedResult());
            }

            var editorShape = _contentManager.BuildEditor(content);
            var model       = New.ViewModel(Editor: editorShape, FolderPath: folderPath);

            return(View(model));
        }
        public ActionResult Edit(int id)
        {
            if (!_orchardServices.Authorizer.Authorize(TestPermission))
            {
                return(new HttpUnauthorizedResult());
            }
            object model;

            if (id == 0)
            {
                var newContent = _orchardServices.ContentManager.New(contentType);
                ((dynamic)newContent).CommunicationCampaignPart.FromDate.DateTime = DateTime.Now;
                //    ((dynamic)newContent).CommunicationCampaignPart.ToDate.DateTime = DateTime.Now.AddYears(1);
                model = _contentManager.BuildEditor(newContent);
            }
            else
            {
                model = _contentManager.BuildEditor(_orchardServices.ContentManager.Get(id));
            }
            return(View((object)model));
        }
Example #30
0
        public ActionResult Index(string id, string returnUrl)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            if (!_contentMetadataService.CheckEntityPublished(id))
            {
                return(Content(T("The \"{0}\" hasn't been published!", id).Text));
            }
            var     contentItem           = _contentManager.New(id);
            dynamic model                 = _contentManager.BuildEditor(contentItem);
            var     contentTypeDefinition = contentItem.TypeDefinition;
            string  layout                = contentTypeDefinition.Settings.ContainsKey("Layout")
                ? contentTypeDefinition.Settings["Layout"]
                : string.Empty;

            layout = string.IsNullOrEmpty(layout)
                ? "<fd-section section-columns=\"1\" section-columns-width=\"6:6\" section-title=\"Sample Title\"><fd-row><fd-column></fd-column></fd-row></fd-section>"
                : layout;
            var viewModel = Services.New.ViewModel();

            viewModel.Layout      = layout;
            viewModel.DisplayName = contentItem.TypeDefinition.DisplayName;
            var templates = new List <dynamic>();
            var fields    = _contentDefinitionManager.GetPartDefinition(id).Fields
                            .Select(x => new FieldViewModel {
                DisplayName = x.DisplayName, Name = x.Name
            })
                            .ToList();

            foreach (var item in model.Content.Items)
            {
                if (item.TemplateName != null && item.TemplateName.StartsWith("Fields/"))
                {
                    templates.Add(item);
                }
                else if (item.TemplateName == "Parts/Relationship.Edit")
                {
                    templates.Add(item);
                    var name = item.ContentPart.GetType().Name;
                    fields.Add(new FieldViewModel {
                        Name        = name,
                        DisplayName = _contentDefinitionManager.GetPartDefinition(name).Settings["DisplayName"]
                    });
                }
            }
            viewModel.Templates = templates;
            viewModel.Fields    = fields;

            return(View((object)viewModel));
        }