/// <summary> /// 绑定表单 /// </summary> protected override void OnBind(Product bindFrom) { // 基本信息 Name = bindFrom.Name; Type = bindFrom.Type ?? new ProductTypeListItemProvider().GetItems().Select(i => i.Value).FirstOrDefault(); State = bindFrom.State ?? new ProductStateListItemProvider().GetItems().Select(i => i.Value).FirstOrDefault(); DisplayOrder = bindFrom.DisplayOrder; ProductClass = new HashSet <Guid>(bindFrom.Classes.Select(c => c.Id)); ProductTag = new HashSet <Guid>(bindFrom.Tags.Select(t => t.Id)); Seller = bindFrom.Seller == null ? null : bindFrom.Seller.Username; Remark = bindFrom.Remark; // 商品相册 var templateManager = Application.Ioc.Resolve <TemplateManager>(); var configManager = Application.Ioc.Resolve <GenericConfigManager>(); var albumSettings = configManager.GetData <ProductAlbumSettings>(); ProductAlbumAlert = new HtmlString(templateManager.RenderTemplate( "shopping.product/tmpl.album_alert.html", new { width = albumSettings.OriginalImageWidth, height = albumSettings.OriginalImageHeight })); ProductAlbum = new ProductAlbumUploadData(bindFrom.Id); // 属性规格 Category = bindFrom.Category?.Id; PropertyValues = bindFrom.PropertyValues.ToEditList(); // 价格库存 MatchedDatas = bindFrom.MatchedDatas.ToEditList(); // 商品介绍 Introduction = bindFrom.Introduction; }
/// <summary> /// 绑定表单 /// </summary> protected override void OnBind(Product bindFrom) { // 基本信息 Name = bindFrom.Name; Type = bindFrom.Type ?? new ProductTypeListItemProvider().GetItems().Select(i => i.Value).FirstOrDefault(); State = bindFrom.State ?? new ProductStateListItemProvider().GetItems().Select(i => i.Value).FirstOrDefault(); DisplayOrder = bindFrom.DisplayOrder; ProductClass = new HashSet <Guid>(bindFrom.Classes.Select(c => c.Id)); ProductTag = new HashSet <Guid>(bindFrom.Tags.Select(t => t.Id)); Seller = bindFrom.Seller == null ? null : bindFrom.Seller.Username; Remark = bindFrom.Remark; // 商品相册 var templateManager = Application.Ioc.Resolve <TemplateManager>(); var configManager = Application.Ioc.Resolve <GenericConfigManager>(); var albumSettings = configManager.GetData <ProductAlbumSettings>(); ProductAlbumAlert = new T("Uploaded pictures will be scaled to {0}x{1}, " + "upload pictures of this size can achieve the best display effect", albumSettings.OriginalImageWidth, albumSettings.OriginalImageHeight); ProductAlbum = new ProductAlbumUploadData(bindFrom.Id); // 属性规格 Category = bindFrom.Category?.Id; PropertyValues = bindFrom.PropertyValues.ToEditList(); // 价格库存 MatchedDatas = bindFrom.MatchedDatas.ToEditList(); // 商品介绍 Introduction = bindFrom.Introduction; }
/// <summary> /// 解析提交的字段的值 /// </summary> public object Parse(FormField field, IList <string> values) { var data = new ProductAlbumUploadData(); var attribute = (ProductAlbumUploaderAttribute)field.Attribute; var request = HttpManager.CurrentContext.Request; data.MainImageIndex = request.Get <long>(attribute.Name + "_MainImageIndex"); for (int x = 1; x <= ProductAlbumUploadData.MaxImageCount; ++x) { var image = request.GetPostedFile(attribute.Name + "_Image_" + x); var deleteImage = request.Get <bool>(attribute.Name + "_DeleteImage_" + x); attribute.Check(image); data.UploadedImages.Add(image); data.DeleteImages.Add(deleteImage); } return(data); }