示例#1
0
        private ComAttributeCacheDTO GetComAttributeCacheDTO(SecondAttributeDTO comAttr)
        {
            var dto = new ComAttributeCacheDTO
            {
                Id          = comAttr.Id,
                AttributeId = comAttr.AttributeId,
                Name        = comAttr.Name,
                SubTime     = comAttr.SubTime
            };

            return(dto);
        }
示例#2
0
        /// <summary>
        /// 属性删除
        /// </summary>
        /// <param name="secondAttributeId">次级属性ID</param>
        /// <param name="appid"></param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO DelSecondAttributeExt(System.Guid secondAttributeId, System.Guid appid)
        {
            try
            {
                ContextSession  contextSession  = ContextFactory.CurrentThreadContext;
                SecondAttribute secondAttribute = SecondAttribute.ObjectSet().Where(n => n.Id == secondAttributeId).FirstOrDefault();
                if (secondAttribute != null)
                {
                    secondAttribute.EntityState = System.Data.EntityState.Modified;
                    secondAttribute.IsDel       = true;
                    contextSession.SaveObject(secondAttribute);
                    contextSession.SaveChanges();

                    //后台线程更新属性缓存
                    System.Threading.ThreadPool.QueueUserWorkItem(a =>
                    {
                        ComAttributeCacheDTO dto = new ComAttributeCacheDTO
                        {
                            Id          = secondAttribute.Id,
                            Name        = secondAttribute.Name,
                            AttributeId = secondAttribute.AttributeId,
                            SubTime     = secondAttribute.SubTime
                        };
                        Jinher.JAP.Cache.GlobalCacheWrapper.Remove("G_AttributeInfo", dto.Id.ToString(), "BTPCache");
                        Jinher.JAP.Common.Loging.LogHelper.Info("删除颜色/尺寸时更新了缓存");
                    });
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("删除属性服务异常。secondAttributeId:{0},appid:{1}", secondAttributeId, appid), ex);
                return(new ResultDTO {
                    ResultCode = 1, Message = "Error"
                });
            }

            return(new ResultDTO {
                ResultCode = 0, Message = "Success"
            });
        }
示例#3
0
        /// <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"
            });
        }