/// <summary>
 /// Initializes a new instance of the <see cref="ProductItemViewModel"/> class.
 /// </summary>
 /// <param name="contentItem">The content item.</param>
 /// <param name="provider">The provider.</param>
 public ProductItemViewModel(ProductItem contentItem, ContentDataProviderBase provider)
     : base(contentItem, provider)
 {
     this.price = contentItem.Price;
     this.quantityInStock = contentItem.QuantityInStock;
     this.whatIsInThebox = contentItem.WhatIsInTheBox;
 }
        private static void AddTaxaToProduct(ProductItem productItem, TaxonomyManager taxManager, string taxaName, string taxonName)
        {
            var taxon = taxManager.GetTaxa<FlatTaxon>().SingleOrDefault(t => t.Name == taxonName);

            // Check if a tag with the same name is already added
            var tagExists = productItem.Organizer.TaxonExists(taxaName, taxon.Id);

            if (!tagExists)
            {
                // Add the tag and save the changes
                productItem.Organizer.AddTaxa(taxaName, taxon.Id);
            }
        }
        private void AddImageToProductItem(ProductItem product)
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager();

            if (product == null)
            {
                return;        // Product does not exist
            }

            var defaultAlbum = librariesManager.GetAlbums().FirstOrDefault(a => a.Id == LibrariesModule.DefaultImagesLibraryId);

            Telerik.Sitefinity.Libraries.Model.Image image = UploadImage(librariesManager, "imageTitle1", "imageTitle1", "Some description", 0, Guid.Empty, defaultAlbum);

            product.CreateRelation(image, "ProductImage");
        }
 private static void DeleteProduct(ProductItem product, ProductsManager productsManager)
 {
     productsManager.DeleteProduct(product);
     productsManager.SaveChanges();
 }
        /// <summary>
        /// Create a product item with specific primary key
        /// </summary>
        /// <param name="id">Primary key</param>
        /// <returns>Newly created product item in transaction</returns>
        public override ProductItem CreateProduct(Guid id)
        {
            var product = new ProductItem();
            product.Id = id;
            product.ApplicationName = this.ApplicationName;
            product.Owner = SecurityManager.GetCurrentUserId();
            var dateValue = DateTime.UtcNow;
            product.DateCreated = dateValue;
            product.PublicationDate = dateValue;
            ((IDataItem)product).Provider = this;

            // news permissions inherit form the security root
            var securityRoot = this.GetSecurityRoot();
            if (securityRoot != null)
            {
                this.providerDecorator.CreatePermissionInheritanceAssociation(securityRoot, product);
            }
            else
            {
                var msg = Res.Get<SecurityResources>().NoSecurityRoot;
                msg = string.Format(msg, typeof(ProductItem).AssemblyQualifiedName);
                throw new InvalidOperationException(msg);
            }

            // items with empty guid are used in the UI to get a "blank" data item
            // -> i.e. to fill a data item with default values
            // if this is the case, we leave the item out of the transaction
            if (id != Guid.Empty)
            {
                this.GetContext().Add(product);
            }

            return product;
        }
        /// <summary>
        /// Delete a product
        /// </summary>
        /// <param name="product">Product to delete</param>
        public override void DeleteProduct(ProductItem product)
        {
            var scope = this.GetContext();

            this.ClearContentLinks(product);


            ////remove the item from the parent list of inheritors
            //var securityRoot = this.GetSecurityRoot();
            //if (securityRoot != null)
            //{
            //    List<PermissionsInheritanceMap> parentInheritors = securityRoot.PermissionChildren.Where(c => c.ChildObjectId == product.Id).ToList();
            //    for (int inheritor = 0; inheritor < parentInheritors.Count(); inheritor++)
            //    {
            //        securityRoot.PermissionChildren.Remove(parentInheritors[inheritor]);
            //    }
            //}
            ////remove the relevant permissions
            this.providerDecorator.DeletePermissions(product);
            this.ClearLifecycle(product, this.GetProducts());
            if (scope != null)
            {
                scope.Remove(product);
            }

            this.DeleteItemComments(product.GetType(), product.Id);
        }
 public abstract void DeleteProduct(ProductItem product);