当前位置: 首页>>代码示例>>C#>>正文


C# IProductRepository.SaveProductTagList方法代码示例

本文整理汇总了C#中IProductRepository.SaveProductTagList方法的典型用法代码示例。如果您正苦于以下问题:C# IProductRepository.SaveProductTagList方法的具体用法?C# IProductRepository.SaveProductTagList怎么用?C# IProductRepository.SaveProductTagList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IProductRepository的用法示例。


在下文中一共展示了IProductRepository.SaveProductTagList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveProduct

        private void SaveProduct(IProductRepository productRepository)
        {
            double price;
            double wholesalePrice;

            if (
                string.IsNullOrEmpty(txtName.Text) ||
                string.IsNullOrEmpty(txtDescription.Text) ||
                string.IsNullOrEmpty(txtWholesalePrice.Text) ||
                string.IsNullOrEmpty(txtPrice.Text) ||
                !double.TryParse(txtPrice.Text, out price) ||
                !double.TryParse(txtWholesalePrice.Text, out wholesalePrice)
               )
            {
                MessageBox.Show("Сначала ведите все поля", "Ошибка");
                return;
            }

            var prod = new Product();

            prod.ID = Guid.NewGuid();
            prod.Name = txtName.Text;
            prod.Created = DateTime.UtcNow;
            prod.Description = txtDescription.Text;
            prod.Price = price;
            prod.WholesalePrice = wholesalePrice;

            prod.Height = sizeQualifier.SHeight;
            prod.Waist = sizeQualifier.SWaist;
            prod.Breast = sizeQualifier.SBreast;
            prod.Hips = sizeQualifier.SHips;
            prod.ArmLength = sizeQualifier.SArmLength;
            prod.LegLength = sizeQualifier.SLegLength;
            prod.Letter = sizeQualifier.SLetter;
            prod.Number = sizeQualifier.SValue;

            productRepository.SaveProduct(prod);

            List<ProductTag> prodTags = new List<ProductTag>();
            foreach (var tag in tagsForm.SelectedTags)
            {
                prodTags.Add(new ProductTag()
                {
                    ProductID = prod.ID,
                    TagID = tag.ID
                });
            }

            productRepository.SaveProductTagList(prodTags);

            var imageRoot = Path.Combine(StorageContext.Current.XmlStorageDir, "Product", prod.ID.ToString(), ConfigManager.ImageUrlPrefix);

            List<ProductImage> prodImages = new List<ProductImage>();
            foreach (var imgKey in ilPhoto.Images.Keys)
            {
                var photo = Photos[imgKey];
                var aspectRatio = (double)photo.Width / (double)photo.Height;

                Directory.CreateDirectory(imageRoot);

                var smallImage = imgKey + "_small.jpg";
                prodImages.Add(new ProductImage()
                {
                    Url = "/" + ConfigManager.ImageUrlPrefix + "/" + smallImage,
                    ProductID = prod.ID
                });
                var smallBmp = ImageUtilities.ResizeImage(photo, 200, Convert.ToInt32(200 / aspectRatio));
                ImageUtilities.SaveJpeg(Path.Combine(imageRoot, smallImage), smallBmp, 80);

                var bigImage = imgKey + "_big.jpg";
                prodImages.Add(new ProductImage()
                {
                    Url = "/" + ConfigManager.ImageUrlPrefix + "/" + bigImage,
                    ProductID = prod.ID
                });
                var bigBmp = ImageUtilities.ResizeImage(photo, 500, Convert.ToInt32(500 / aspectRatio));
                ImageUtilities.SaveJpeg(Path.Combine(imageRoot, bigImage), bigBmp, 80);
            }

            productRepository.SaveProductImageList(prodImages);

            if (productRepository is UrkSecond.Domain.Repository.DB.ProductRepository)
            {
                var ftpClient = new FTP(ConfigManager.FTPHost, ConfigManager.FTPUser, ConfigManager.FTPPassword);
                foreach (var productImage in prodImages)
                {
                    //ftpClient.Upload(productImage.Url, Path.Combine(imageRoot, productImage.Url));
                    File.Delete(Path.Combine(imageRoot, productImage.Url));
                }
            }

            MessageBox.Show("Успешно сохранено", "Операция выполнена успешно");

            ClearForm();
        }
开发者ID:JTOne123,项目名称:ukrsecond,代码行数:95,代码来源:AddProductForm.cs


注:本文中的IProductRepository.SaveProductTagList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。