Esempio n. 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);
                }
            });
        }
Esempio n. 2
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 ActionResult GetAddress(string id, string addrId)
        {
            var serviceResult = _service.GetAddress(id, addrId);

            if (serviceResult.Status == eOperationStatus.Success)
            {
                return(Ok(serviceResult));
            }

            if (serviceResult.Status == eOperationStatus.NotFound)
            {
                return(NotFound(serviceResult.ExceptionMessage));
            }

            return(BadRequest(serviceResult));
        }
Esempio n. 4
0
        public ActionResult PreviewAddress(int id)
        {
            var address = _customersService.GetAddress(id);

            if (address == null)
            {
                return(new HttpNotFoundResult());
            }
            else if (Services.Authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent, address))
            {
                return(new ShapeResult(this, _contentManager.BuildDisplay(address.ContentItem)));
            }
            else
            {
                return(new HttpUnauthorizedResult());
            }
        }