/// <summary> /// 修改操作 /// </summary> public void Updates(SecondAttributeDTO secondAttributeDTO) { SecondAttribute secondAttribute = new SecondAttribute().FromEntityData(secondAttributeDTO); ContextSession contextSession = ContextFactory.CurrentThreadContext; secondAttribute.EntityState = System.Data.EntityState.Modified; contextSession.SaveObject(secondAttribute); contextSession.SaveChanges(); }
private ComAttributeCacheDTO GetComAttributeCacheDTO(SecondAttributeDTO comAttr) { var dto = new ComAttributeCacheDTO { Id = comAttr.Id, AttributeId = comAttr.AttributeId, Name = comAttr.Name, SubTime = comAttr.SubTime }; return(dto); }
/// <summary> /// 查询订单下商品 /// </summary> /// <param name="commodityOrderId"></param> /// <returns></returns> public List <OrderItemsVM> SelectOrderItemsByOrderId(Guid commodityOrderId, Guid appId) { CommodityCategory cc = new CommodityCategory(); IEnumerable <OrderItemsVM> query = from data in OrderItem.ObjectSet() join data1 in Commodity.ObjectSet() on data.CommodityId equals data1.Id where (data.CommodityOrderId == commodityOrderId && data1.CommodityType == 0) select new OrderItemsVM { CommodityOrderId = data.CommodityOrderId, CommodityId = data.CommodityId, CommodityIdName = data1.Name, PicturesPath = data1.PicturesPath, Price = data.CurrentPrice, //取订单商品列表中的价格 Number = data.Number, SizeAndColorId = data.ComAttributeIds, //CommodityCategorys = cc.GetCommodityCategory(data1.Id).Select(n => n.Name).ToList(), }; query = query.ToList(); //遍历查询商品的类别信息 ps:真的要这么做么? foreach (var item in query) { var category = (from data in CommodityCategory.ObjectSet() join data1 in Category.ObjectSet() on data.CategoryId equals data1.Id where data.CommodityId == item.CommodityId && data.AppId == appId select data1.Name).ToList(); item.CommodityCategorys = category; } //获取订单商品的一些信息 List <OrderItemsVM> orderItemsVMList = query.ToList <OrderItemsVM>(); SecondAttribute secondAttribute = new SecondAttribute(); Jinher.AMP.BTP.BE.Attribute attribute = new Jinher.AMP.BTP.BE.Attribute(); //获取app的所有次级属性 List <SecondAttributeDTO> secondAttributeDTOList = secondAttribute.GetSecondAttributeBySellerID(appId); //获取app的所有属性(目前只有颜色和尺寸两种) List <Attribute> attributeDTOList = Attribute.ObjectSet().ToList(); List <OrderItemsVM> orderItemslist = new List <OrderItemsVM>(); Collection collect = new Collection(); //遍历商品信息,获取每个商品对应的颜色、尺寸属性 foreach (OrderItemsVM model in orderItemsVMList) { List <ComAttibuteDTO> comAlist = new List <ComAttibuteDTO>(); string attributeString = model.SizeAndColorId; if (!string.IsNullOrWhiteSpace(attributeString)) { string[] attributeStringArray = attributeString.Split(','); for (int i = 0; i < attributeStringArray.Length; i++) { SecondAttributeDTO tempSecondDTO = secondAttributeDTOList.Where(p => p.Id == Guid.Parse(attributeStringArray[i])).FirstOrDefault(); if (tempSecondDTO != null) { Attribute tempDTO = attributeDTOList.Where(p => p.Id == tempSecondDTO.AttributeId).FirstOrDefault(); ComAttibuteDTO comA = new ComAttibuteDTO(); comA.AttributeId = tempDTO.Id; comA.Code = "1"; comA.SubTime = DateTime.Now; comA.AttributeName = tempDTO.Name; comA.CommodityId = model.CommodityId; comA.SecondAttributeName = tempSecondDTO.Name; comA.SecondAttributeId = tempSecondDTO.Id; comAlist.Add(comA); } } } model.SelectedComAttibutes = comAlist; orderItemslist.Add(model); } return(orderItemslist); }
/// <summary> /// 添加尺寸/颜色 /// </summary> /// <param name="attributeId">属性ID</param> /// <param name="name">二级属性名</param> public ResultDTO AddSecondAttributeExt(System.Guid attributeId, string name, Guid appid) { //缓存列表 List <SecondAttributeDTO> attrList = new List <SecondAttributeDTO>(); ContextSession contextSession = ContextFactory.CurrentThreadContext; try { if (!string.IsNullOrEmpty(name)) { name = name.Replace(';', ','); string[] names = name.Split(',').Distinct().ToArray(); for (int i = 0; i < names.Length; i++) { SecondAttributeDTO secondAttributeDTO = new SecondAttributeDTO(); secondAttributeDTO.Id = Guid.NewGuid(); secondAttributeDTO.AttributeId = attributeId; secondAttributeDTO.Name = names[i]; secondAttributeDTO.AppId = appid; //this.SaveSecondAttribute(secondAttributeDTO); secondAttributeDTO.EntityState = System.Data.EntityState.Added; SecondAttribute secondAttribute = new SecondAttribute().FromEntityData(secondAttributeDTO); DateTime date = DateTime.Now.AddSeconds(i); secondAttribute.SubTime = date; contextSession.SaveObject(secondAttribute); attrList.Add(secondAttributeDTO); contextSession.SaveChanges(); } } } catch (Exception ex) { LogHelper.Error(string.Format("添加颜色尺寸服务异常。attributeId:{0},name:{1},appid:{2}", attributeId, name, appid), ex); return(new ResultDTO { ResultCode = 1, Message = "Error" }); } //后台线程更新属性缓存 System.Threading.ThreadPool.QueueUserWorkItem(a => { List <ComAttributeCacheDTO> cache = new List <ComAttributeCacheDTO>(); foreach (SecondAttributeDTO comAttr in attrList) { ComAttributeCacheDTO dto = GetComAttributeCacheDTO(comAttr); Jinher.JAP.Cache.GlobalCacheWrapper.Add("G_AttributeInfo", dto.Id.ToString(), cache, "BTPCache"); Jinher.JAP.Common.Loging.LogHelper.Info("添加颜色/尺寸时更新了缓存"); } }); return(new ResultDTO { ResultCode = 0, Message = "Success" }); }