/// <summary> /// Handles the Click event of the lbAdd control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param> protected void lbAdd_Click(object sender, CommandEventArgs e) { try { int attributeId = 0; int.TryParse(e.CommandArgument.ToString(), out attributeId); if (attributeId > 0) { Where where = new Where(); where.ColumnName = ProductAttributeMap.Columns.ProductId; where.DbType = DbType.Int32; where.ParameterValue = productId; Query query = new Query(ProductAttributeMap.Schema); object strSortOrder = query.GetMax(ProductAttributeMap.Columns.SortOrder, where); int maxSortOrder = 0; int.TryParse(strSortOrder.ToString(), out maxSortOrder); ProductAttributeMap map = new ProductAttributeMap(); map.AttributeId = attributeId; map.ProductId = productId; map.SortOrder = maxSortOrder + 1; map.Save(WebUtility.GetUserName()); Store.Caching.ProductCache.RemoveAssociatedAttributeCollectionFromCache(productId); LoadAvailableAttributes(); LoadAssociatedAttributes(); } } catch (Exception ex) { Logger.Error(typeof(attributes).Name + ".lbAdd_Click", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }
/// <summary> /// Handles the Click event of the btnPostSimilar control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnCopy_Click(object sender, EventArgs e) { this.btnSave_Click(null, EventArgs.Empty); //Save any changes first Product newProduct = new Product(); newProduct.ProductGuid = Guid.NewGuid(); newProduct.BaseSku = string.Empty; newProduct.Name = product.Name = txtName.Text.Trim() + " - Copy"; newProduct.ShortDescription = product.ShortDescription; newProduct.OurPrice = product.OurPrice; newProduct.RetailPrice = product.RetailPrice; newProduct.ManufacturerId = product.ManufacturerId; newProduct.ProductStatusDescriptorId = product.ProductStatusDescriptorId; newProduct.ProductTypeId = product.ProductTypeId; newProduct.TaxRateId = product.TaxRateId; newProduct.ShippingEstimateId = product.ShippingEstimateId; newProduct.Weight = product.Weight; newProduct.Length = product.Length; newProduct.Height = product.Height; newProduct.Width = product.Width; newProduct.TotalRatingVotes = product.TotalRatingVotes; newProduct.RatingSum = product.RatingSum; newProduct.Save(WebUtility.GetUserName()); if (newProduct.ProductId > 0) { foreach (Category cat in product.GetCategoryCollection()) { ProductCategoryMap map = new ProductCategoryMap(); map.CategoryId = cat.CategoryId; map.ProductId = newProduct.ProductId; map.Save(WebUtility.GetUserName()); Store.Caching.ProductCache.RemoveProductsByCategoryIdFromCache(cat.CategoryId); } AssociatedAttributeCollection productAttributes = Store.Caching.ProductCache.GetAssociatedAttributeCollectionByProduct(product.ProductId); foreach (AssociatedAttribute at in productAttributes) { int sortOrder = 0; ProductAttributeMap map = new ProductAttributeMap(); map.AttributeId = at.AttributeId; map.ProductId = newProduct.ProductId; map.SortOrder = sortOrder++; map.IsRequired = at.IsRequired; map.Save(WebUtility.GetUserName()); } Response.Redirect(string.Format("~/admin/productedit.aspx?view=g&productId={0}", newProduct.ProductId.ToString()), false); } else { base.MasterPage.MessageCenter.DisplayFailureMessage(LocalizationUtility.GetText("lblProductNotSaved")); } }
/// <summary> /// Handles the ItemReorder event of the Items control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Items_ItemReorder(object sender, EventArgs e) { try { ImageButton theButton = sender as ImageButton; Query query = new Query(ProductAttributeMap.Schema). WHERE(ProductAttributeMap.Columns.ProductId, Comparison.Equals, productId). ORDER_BY(ProductAttributeMap.Columns.SortOrder); ProductAttributeMapCollection productAttributeMapCollection = new ProductAttributeMapController().FetchByQuery(query); if (productAttributeMapCollection != null) { int attributeId = 0; int.TryParse(theButton.CommandArgument.ToString(), out attributeId); if (attributeId > 0) { ProductAttributeMap productAttributeMapMoved = productAttributeMapCollection.Find(delegate(ProductAttributeMap productAttributeMap) { return(productAttributeMap.AttributeId == attributeId); }); int index = productAttributeMapCollection.IndexOf(productAttributeMapMoved); productAttributeMapCollection.RemoveAt(index); if (theButton.CommandName.ToLower() == "up") { productAttributeMapCollection.Insert(index - 1, productAttributeMapMoved); } else if (theButton.CommandName.ToLower() == "down") { productAttributeMapCollection.Insert(index + 1, productAttributeMapMoved); } int i = 1; foreach (ProductAttributeMap productAttributeMap in productAttributeMapCollection) { productAttributeMap.SortOrder = i++; } productAttributeMapCollection.SaveAll(WebUtility.GetUserName()); LoadAssociatedAttributes(); } } } catch (Exception ex) { Logger.Error(typeof(attributes).Name + ".Items_ItemReorder", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }
/// <inheritdoc/> public async Task UpdateProduct(OperableProductDto input) { input.CheckNotNull("input"); input.Id.CheckGreaterThan("input.Id", 0); var product = await _productRepository.GetAsync(input.Id); int onShelfState = 0;//0:未更改;1:上架;2:下架; if (product.IsOnShelf != input.IsOnShelf) { onShelfState = input.IsOnShelf ? 1 : 2; } input.MapTo(product); if (onShelfState == 1) { product.OnShelfTime = DateTime.Now; } if (onShelfState == 2) { product.OffShelfTime = DateTime.Now; } //更新属性 var exsitAttributes = await _productAttributeRepository.GetAll().Where(p => p.ProductId == input.Id).ToListAsync(); foreach (var group in input.GroupAttributes) { foreach (var item in group.Attributes) { var attribute = new ProductAttributeMap { ProductId = input.Id, AttributeId = item.Id, Value = item.Value, AttributeOptionIds = item.AttributeType == ProductAttributeType.Switch ? FormatOptionIds(item.attributeOptionId) : item.AttributeType == ProductAttributeType.Multiple ? FormatOptionIds(item.attributeOptionIds.ExpandAndToString()) : "" }; var exsitAttribute = exsitAttributes.SingleOrDefault(p => p.AttributeId == attribute.AttributeId); if (exsitAttribute == null) { await _productAttributeRepository.InsertAsync(attribute); } else { if (attribute.Value != exsitAttribute.Value || attribute.AttributeOptionIds != exsitAttribute.AttributeOptionIds) { exsitAttribute.Value = attribute.Value; exsitAttribute.AttributeOptionIds = attribute.AttributeOptionIds; await _productAttributeRepository.UpdateAsync(exsitAttribute); } } } } //更新相册 string[] existPaths = product.Assets.Select(m => m.Path).ToArray(); string[] addPaths = input.Albums.Except(existPaths).ToArray(); string[] removePaths = existPaths.Except(input.Albums).ToArray(); foreach (var path in addPaths) { await _assetRepository.InsertAsync(new ProductAsset { Path = path, ProductId = input.Id, AssetType = AssetType.Picture }); } await _assetRepository.DeleteAsync(p => removePaths.Contains(p.Path)); //更新商品 await _productRepository.UpdateAsync(product); }
/// <summary> /// Handles the Click event of the lbAdd control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param> protected void lbAdd_Click(object sender, CommandEventArgs e) { try { int attributeId = 0; int.TryParse(e.CommandArgument.ToString(), out attributeId); if(attributeId > 0) { Where where = new Where(); where.ColumnName = ProductAttributeMap.Columns.ProductId; where.DbType = DbType.Int32; where.ParameterValue = productId; Query query = new Query(ProductAttributeMap.Schema); object strSortOrder = query.GetMax(ProductAttributeMap.Columns.SortOrder, where); int maxSortOrder = 0; int.TryParse(strSortOrder.ToString(), out maxSortOrder); ProductAttributeMap map = new ProductAttributeMap(); map.AttributeId = attributeId; map.ProductId = productId; map.SortOrder = maxSortOrder + 1; map.Save(WebUtility.GetUserName()); Store.Caching.ProductCache.RemoveAssociatedAttributeCollectionFromCache(productId); LoadAvailableAttributes(); LoadAssociatedAttributes(); } } catch(Exception ex) { Logger.Error(typeof(attributes).Name + ".lbAdd_Click", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }
/// <summary> /// Handles the Click event of the btnPostSimilar control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnCopy_Click(object sender, EventArgs e) { this.btnSave_Click(null, EventArgs.Empty); //Save any changes first Product newProduct = new Product(); newProduct.ProductGuid = Guid.NewGuid(); newProduct.BaseSku = string.Empty; newProduct.Name = product.Name = txtName.Text.Trim() + " - Copy"; newProduct.ShortDescription = product.ShortDescription; newProduct.OurPrice = product.OurPrice; newProduct.RetailPrice = product.RetailPrice; newProduct.ManufacturerId = product.ManufacturerId; newProduct.ProductStatusDescriptorId = product.ProductStatusDescriptorId; newProduct.ProductTypeId = product.ProductTypeId; newProduct.TaxRateId = product.TaxRateId; newProduct.ShippingEstimateId = product.ShippingEstimateId; newProduct.Weight = product.Weight; newProduct.Length = product.Length; newProduct.Height = product.Height; newProduct.Width = product.Width; newProduct.TotalRatingVotes = product.TotalRatingVotes; newProduct.RatingSum = product.RatingSum; newProduct.Save(WebUtility.GetUserName()); if (newProduct.ProductId > 0) { foreach (Category cat in product.GetCategoryCollection()) { ProductCategoryMap map = new ProductCategoryMap(); map.CategoryId = cat.CategoryId; map.ProductId = newProduct.ProductId; map.Save(WebUtility.GetUserName()); Store.Caching.ProductCache.RemoveProductsByCategoryIdFromCache(cat.CategoryId); } AssociatedAttributeCollection productAttributes = Store.Caching.ProductCache.GetAssociatedAttributeCollectionByProduct(product.ProductId); foreach (AssociatedAttribute at in productAttributes) { int sortOrder = 0; ProductAttributeMap map = new ProductAttributeMap(); map.AttributeId = at.AttributeId; map.ProductId = newProduct.ProductId; map.SortOrder = sortOrder++; map.IsRequired = at.IsRequired; map.Save(WebUtility.GetUserName()); } Response.Redirect(string.Format("~/admin/productedit.aspx?view=g&productId={0}", newProduct.ProductId.ToString()), false); } else { base.MasterPage.MessageCenter.DisplayFailureMessage(LocalizationUtility.GetText("lblProductNotSaved")); } }
public void Update(int AttributeId,int ProductId,int SortOrder,bool IsRequired) { ProductAttributeMap item = new ProductAttributeMap(); item.AttributeId = AttributeId; item.ProductId = ProductId; item.SortOrder = SortOrder; item.IsRequired = IsRequired; item.MarkOld(); item.Save(UserName); }