public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } ProductPropertyValue = await _context.ProductPropertyValue .Include(p => p.ProductProperty).FirstOrDefaultAsync(m => m.ProductPropertyValueId == id); if (ProductPropertyValue == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } ProductPropertyValue = await _context.ProductPropertyValue.FindAsync(id); if (ProductPropertyValue != null) { _context.ProductPropertyValue.Remove(ProductPropertyValue); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } ProductPropertyValue = await _context.ProductPropertyValue .Include(p => p.ProductProperty).FirstOrDefaultAsync(m => m.ProductPropertyValueId == id); if (ProductPropertyValue == null) { return(NotFound()); } ViewData["ProductPropertyId"] = new SelectList(_context.ProductProperty, "ProductPropertyId", "Name"); return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Product = await _context.Product.FirstOrDefaultAsync(m => m.ProductId == id); if (Product == null) { return(NotFound()); } ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategory, "ProductCategoryId", "Name"); ViewData["Properties"] = _context.ProductProperty; IList <ProductPropertyValue> ValuesList = new List <ProductPropertyValue>(); var values = _context.ProductPropertyValue.Include(a => a.ProductProperty); for (int i = 0; i < values.Count(); i++) { ProductPropertyValue value = values.ToList()[i]; var map = await _context.ProductPropertyMap .FindAsync(Product.ProductId, value.ProductPropertyValueId); if (map != null) { value.isSelected = true; } ValuesList.Add(value); } ViewData["Values"] = ValuesList; return(Page()); }
public ProductPropertyValue Sync(int productId, string channelPropertyValueName, string channelPropertyValueId, ProductPropertyType productPropertyType) { using (var db = new YintaiHZhouContext()) { // 是否为颜色 var isColor = productPropertyType == ProductPropertyType.Color; // 映射类型 var mapType = isColor ? ChannelMapType.ColorId : ChannelMapType.SizeId; /** * 映射商品颜色或尺寸的属性值Id * 映射关系{productId}+{propertyValueId} */ var mapKey = Utils.GetProductProprtyMapKey(productId, channelPropertyValueId); var propertyValueMap = _channelMapper.GetMapByChannelValue(mapKey, mapType); var valueDesc = string.IsNullOrWhiteSpace(channelPropertyValueName) ? channelPropertyValueId : channelPropertyValueName; if (propertyValueMap == null) { // 检查当前商品是否存在颜色或尺寸的属性 var propertyExt = GetProductProperty(productId, mapType); if (propertyExt == null) { // 没有映射关系进行创建属性 propertyExt = new ProductProperty() { IsColor = isColor, IsSize = !isColor, ChannelPropertyId = 0, ProductId = productId, PropertyDesc = isColor ? "颜色" : "尺寸", SortOrder = 0, Status = 1, UpdateDate = DateTime.Now, UpdateUser = SystemDefine.SystemUser }; db.ProductProperties.Add(propertyExt); // 必须先进性保存,获取上面的Last_Update_id db.SaveChanges(); } var ppv = db.ProductPropertyValues.FirstOrDefault( p => p.PropertyId == propertyExt.Id && p.ValueDesc == valueDesc); if (ppv == null) { var newProductPropertyValue = new ProductPropertyValue() { PropertyId = propertyExt.Id, CreateDate = DateTime.Now, Status = 1, UpdateDate = DateTime.Now, ValueDesc = valueDesc }; db.ProductPropertyValues.Add(newProductPropertyValue); // 保存属性值 db.SaveChanges(); ppv = newProductPropertyValue; // 保存映射关系 var newChannelMap = new ChannelMap() { LocalId = ppv.Id, ChannnelValue = Utils.GetProductProprtyMapKey(productId, channelPropertyValueId), MapType = mapType }; _channelMapper.CreateMap(newChannelMap); } return(ppv); } var propertyValueExt = GetProductPropertyValue(productId, propertyValueMap.LocalId, mapType); if (propertyValueExt == null) { _channelMapper.RemoveMap(propertyValueMap); Log.ErrorFormat("属性数据错误,映射关系存在,数据不存在, property value id {0}", propertyValueMap.LocalId); return(null); } propertyValueExt.ValueDesc = valueDesc; propertyValueExt.UpdateDate = DateTime.Now; db.SaveChanges(); return(propertyValueExt); } }
public ProductPropertyValue SyncSize(int productId, ProductDto productDto) { using (var db = new YintaiHZhouContext()) { // 检查当前商品是否存在尺码属性 var propertyExt = db.ProductProperties.FirstOrDefault( p => p.ProductId == productId && p.IsSize.HasValue && p.IsSize.Value); if (propertyExt == null) { // 创建属性 propertyExt = new ProductProperty() { IsColor = false, IsSize = true, ChannelPropertyId = 0, ProductId = productId, PropertyDesc = "尺码", SortOrder = 0, Status = 1, UpdateDate = DateTime.Now, UpdateUser = SystemDefine.SystemUser }; db.ProductProperties.Add(propertyExt); db.SaveChanges(); } else { var ppvMapKey = productDto.ProductId; var ppvMap = _channelMapper.GetMapByChannelValue(ppvMapKey, ChannelMapType.ProductId4Size); if (ppvMap == null) { var newProductPropertyValue = new ProductPropertyValue() { PropertyId = propertyExt.Id, CreateDate = DateTime.Now, Status = 1, UpdateDate = DateTime.Now, ValueDesc = productDto.ColorId }; db.ProductPropertyValues.Add(newProductPropertyValue); // 保存属性值 db.SaveChanges(); // 保存映射关系 var newChannelMap = new ChannelMap() { LocalId = newProductPropertyValue.Id, ChannnelValue = ppvMapKey, MapType = ChannelMapType.ProductId4Size }; _channelMapper.CreateMap(newChannelMap); return(newProductPropertyValue); } var ppv = db.ProductPropertyValues.FirstOrDefault(x => x.Id == ppvMap.LocalId); if (ppv == null) { return(null); } if (ppv.ValueDesc != productDto.SizeId) { ppv.ValueDesc = productDto.SizeId; ppv.UpdateDate = DateTime.Now; db.SaveChanges(); } return(ppv); } } return(null); }