Пример #1
0
 void AssignCreatingOwner(ActivatedContentContext context, CommonAspect part) {
     // and use the current user as Owner
     if (part.Record.OwnerId == 0) {
         part.Owner = _authenticationService.GetAuthenticatedUser();
     }
 }
        public CategoriesController(ICategoryService categoryService)
        {
            _categoryService = CommonAspect <ICategoryService> .Create(categoryService);

            //_categoryService = categoryService;
        }
Пример #3
0
        private void UpdateEditor(UpdateEditorModelContext context, CommonAspect instance) {
            // this event is hooked so the modified timestamp is changed when an edit-post occurs.
            // kind of a loose rule of thumb. may not be sufficient
            instance.ModifiedUtc = _clock.UtcNow;
            instance.VersionModifiedUtc = _clock.UtcNow;

            var currentUser = _authenticationService.GetAuthenticatedUser();
            if (!_authorizationService.TryCheckAccess(Permissions.ChangeOwner, currentUser, instance)) {
                return;
            }

            var viewModel = new OwnerEditorViewModel();
            if (instance.Owner != null)
                viewModel.Owner = instance.Owner.UserName;

            var priorOwner = viewModel.Owner;
            context.Updater.TryUpdateModel(viewModel, "CommonAspect", null, null);

            if (viewModel.Owner != null && viewModel.Owner != priorOwner) {
                var newOwner = _membershipService.GetUser(viewModel.Owner);
                if (newOwner == null) {
                    context.Updater.AddModelError("CommonAspect.Owner", T("Invalid user name"));
                }
                else {
                    instance.Owner = newOwner;
                }
            }

            context.AddEditor(new TemplateViewModel(viewModel, "CommonAspect") { TemplateName = "Parts/Common.Owner", ZoneName = "primary", Position = "999" });
        }
Пример #4
0
        private void GetEditor(BuildEditorModelContext context, CommonAspect instance) {
            var currentUser = _authenticationService.GetAuthenticatedUser();
            if (!_authorizationService.TryCheckAccess(Permissions.ChangeOwner, currentUser, instance)) {
                return;
            }
            var viewModel = new OwnerEditorViewModel();
            if (instance.Owner != null)
                viewModel.Owner = instance.Owner.UserName;

            context.AddEditor(new TemplateViewModel(viewModel, "CommonAspect") { TemplateName = "Parts/Common.Owner", ZoneName = "primary", Position = "999" });
        }
Пример #5
0
        static void PropertySetHandlers(ActivatedContentContext context, CommonAspect aspect) {
            // add handlers that will update records when aspect properties are set

            aspect.OwnerField.Setter(user => {
                                         if (user == null) {
                                             aspect.Record.OwnerId = 0;
                                         }
                                         else {
                                             aspect.Record.OwnerId = user.ContentItem.Id;
                                         }
                                         return user;
                                     });

            // Force call to setter if we had already set a value
            if (aspect.OwnerField.Value != null)
                aspect.OwnerField.Value = aspect.OwnerField.Value;

            aspect.ContainerField.Setter(container => {
                                             if (container == null) {
                                                 aspect.Record.Container = null;
                                             }
                                             else {
                                                 aspect.Record.Container = container.ContentItem.Record;
                                             }
                                             return container;
                                         });

            // Force call to setter if we had already set a value
            if (aspect.ContainerField.Value != null)
                aspect.ContainerField.Value = aspect.ContainerField.Value;
        }
Пример #6
0
 void LazyLoadHandlers(LoadContentContext context, CommonAspect aspect) {
     // add handlers that will load content for id's just-in-time
     aspect.OwnerField.Loader(() => _contentManager.Get<IUser>(aspect.Record.OwnerId));
     aspect.ContainerField.Loader(() => aspect.Record.Container == null ? null : _contentManager.Get(aspect.Record.Container.Id));
 }
Пример #7
0
 private static void CopyOwnerAndContainer(VersionContentContext c, CommonAspect c1, CommonAspect c2) {
     c2.Owner = c1.Owner;
     c2.Container = c1.Container;
 }