/// <summary> /// 添加商品收藏 /// </summary> /// <param name="commodityId">商品ID</param> /// <param name="userId">用户ID</param> /// <param name="channelId">渠道Id</param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO SaveCommodityCollectionExt(System.Guid commodityId, System.Guid userId, System.Guid channelId) { ResultDTO result = new ResultDTO { ResultCode = 0, Message = "Success" }; ContextSession contextSession = ContextFactory.CurrentThreadContext; try { List <Commodity> needRefreshCacheCommodityList = new List <Commodity>(); int collections = SetCollection.ObjectSet().Count(n => n.ColType == 1 && n.UserId == userId && n.ColKey == commodityId && n.ChannelId == channelId); if (collections == 0) { SetCollection collection = SetCollection.CreateSetCollection(); collection.ChannelId = channelId; collection.ColKey = commodityId; collection.SubId = userId; collection.ColType = 1; collection.UserId = userId; contextSession.SaveObject(collection); Commodity com = Commodity.ObjectSet().FirstOrDefault(n => n.Id == commodityId); if (com != null) { com.EntityState = System.Data.EntityState.Modified; com.TotalCollection += 1; contextSession.SaveObject(com); needRefreshCacheCommodityList.Add(com); } contextSession.SaveChanges(); if (needRefreshCacheCommodityList.Any()) { needRefreshCacheCommodityList.ForEach(c => c.RefreshCache(EntityState.Modified)); } } else { result = new ResultDTO { ResultCode = 0, Message = "已有收藏" }; } } catch (Exception ex) { LogHelper.Error(string.Format("添加收藏服务异常。commodityId:{0},userId:{1},channelId:{2},", commodityId, userId, channelId), ex); return(new ResultDTO { ResultCode = 1, Message = "Error" }); } return(result); }
/// <summary> /// 店铺收藏 /// </summary> /// <param name="appId">appId</param> /// <param name="userId">用户ID</param> /// <param name="channelId"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO SaveAppCollectionExt(System.Guid appId, System.Guid userId, System.Guid channelId) { ResultDTO result = new ResultDTO { ResultCode = 0, Message = "Success" }; ContextSession contextSession = ContextFactory.CurrentThreadContext; try { int collections = SetCollection.ObjectSet().Count(n => n.ColType == 2 && n.UserId == userId && n.ColKey == appId && n.ChannelId == channelId); if (collections == 0) { SetCollection collection = SetCollection.CreateSetCollection(); collection.ChannelId = channelId; collection.ColKey = appId; collection.SubTime = DateTime.Now; collection.SubId = userId; collection.ColType = 2; collection.UserId = userId; contextSession.SaveObject(collection); contextSession.SaveChanges(); } else { result = new ResultDTO { ResultCode = 0, Message = "已有收藏" }; } } catch (Exception ex) { LogHelper.Error(string.Format("添加收藏服务异常。appId:{0},userId:{1},channelId:{2},", appId, userId, channelId), ex); return(new ResultDTO { ResultCode = 1, Message = "Error" }); } return(result); }