Exemple #1
0
        public CustomerPartHandler(
            IContentManager contentManager,
            ICustomersService customersService,
            IRepository <CustomerPartRecord> repository
            )
        {
            Filters.Add(StorageFilter.For(repository));

            OnActivated <CustomerPart>((context, part) => {
                // User field
                part._user.Loader(user => contentManager.Get <IUser>(part.UserId));
                part._user.Setter(user => {
                    part.UserId = (user != null ? user.Id : 0);
                    return(user);
                });

                // Default address field
                part._defaultAddress.Loader(address => customersService.GetAddress(part.DefaultAddressId));
                part._defaultAddress.Setter(address => {
                    part.DefaultAddressId = (address != null ? address.Id : 0);
                    return(address);
                });

                // Addresses field
                part._addresses.Loader(addresses => customersService.GetAddressesForCustomer(part));
            });

            OnRemoving <CustomerPart>((context, part) => {
                foreach (var address in part.Addresses)
                {
                    contentManager.Remove(address.ContentItem);
                }
            });
        }
        public CustomerPartHandler(
            IContentManager contentManager,
            ICustomersService customersService,
            IRepository<CustomerPartRecord> repository
            )
        {
            Filters.Add(StorageFilter.For(repository));

            OnActivated<CustomerPart>((context, part) => {
                // User field
                part._user.Loader(user => contentManager.Get<IUser>(part.UserId));
                part._user.Setter(user => {
                    part.UserId = (user != null ? user.Id : 0);
                    return user;
                });

                // Default address field
                part._defaultAddress.Loader(address => customersService.GetAddress(part.DefaultAddressId));
                part._defaultAddress.Setter(address => {
                    part.DefaultAddressId = (address != null ? address.Id : 0);
                    return address;
                });

                // Addresses field
                part._addresses.Loader(addresses => customersService.GetAddressesForCustomer(part));
            });

            OnRemoving<CustomerPart>((context, part) => {
                foreach (var address in part.Addresses) {
                    contentManager.Remove(address.ContentItem);
                }
            });
        }