示例#1
0
 public void SaveProduct(Product product)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     using (session.BeginTransaction())
     {
         session.Save(product);
         session.Transaction.Commit();
     }
 }
示例#2
0
        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();
        }
示例#3
0
 public void SaveProduct(Product product)
 {
     Serialization.SerializeToXmlFile<Product>(product, FilePath_Product(product.ID));
 }