本文整理汇总了C#中IProductRepository.SaveProduct方法的典型用法代码示例。如果您正苦于以下问题:C# IProductRepository.SaveProduct方法的具体用法?C# IProductRepository.SaveProduct怎么用?C# IProductRepository.SaveProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IProductRepository
的用法示例。
在下文中一共展示了IProductRepository.SaveProduct方法的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();
}