/// <summary> /// get the operations available to current user for this product. /// operations includes: /// 1. if can get coupon /// 2. if favored /// </summary> /// <param name="authUser"></param> /// <returns></returns> public ActionResult AvailOperations(GetProductInfoRequest request,[FetchRestfulAuthUserAttribute(IsCanMissing = true, KeyName = Define.Token)] UserModel authUser) { //是否收藏 bool isFavored = false; bool ifCanCoupon = false; var withUserId = (authUser != null && authUser.Id > 0); if (withUserId) { isFavored = _favoriteRepo.Get(f => f.User_Id == authUser.Id && f.FavoriteSourceType == (int)SourceType.Product && f.FavoriteSourceId == request.ProductId && f.Status != (int)DataStatus.Deleted).Any(); } var dbContext = Context; var linq = dbContext.Set<Promotion2ProductEntity>().Where(pp => pp.ProdId == request.ProductId && pp.Status != (int)DataStatus.Deleted) .Join(dbContext.Set<PromotionEntity>().Where(p => p.Status == (int)DataStatus.Normal && p.EndDate > DateTime.Now), o => o.ProId, i => i.Id, (o, i) => new { Pro = i }) .ToList(); ifCanCoupon = linq.Any(l => { bool hadGetCoupon = false; if (withUserId) { hadGetCoupon= dbContext.Set<CouponHistoryEntity>().Where(c => c.User_Id == authUser.Id && c.FromPromotion == l.Pro.Id).Any(); } if (l.Pro.PublicationLimit == null || l.Pro.PublicationLimit == -1) { return (!hadGetCoupon) || (hadGetCoupon && (!l.Pro.IsLimitPerUser.HasValue ||l.Pro.IsLimitPerUser.Value==false)); } else { return l.Pro.InvolvedCount < l.Pro.PublicationLimit && (!hadGetCoupon || (hadGetCoupon && (!l.Pro.IsLimitPerUser.HasValue || l.Pro.IsLimitPerUser.Value == false))); } }); return this.RenderSuccess<GetAvailOperationsResponse>(m=>m.Data=new GetAvailOperationsResponse() { IsFavored = isFavored, IfCanCoupon = ifCanCoupon, IfCanTalk = false }); }
public ExecuteResult<ProductInfoResponse> GetProductInfo(GetProductInfoRequest request) { if (request == null) { return new ExecuteResult<ProductInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误" }; } var entity = _productRepository.GetItem(request.ProductId); var r = MappingManager.ProductInfoResponseMapping(entity); if (r != null && request.CurrentAuthUser != null) { r = IsR(r, request.CurrentAuthUser, r.Id); } return new ExecuteResult<ProductInfoResponse>(r); }
public ActionResult Detail(GetProductInfoRequest request, [FetchRestfulAuthUserAttribute(IsCanMissing = true, KeyName = Define.Token)]UserModel currentAuthUser) { request.CurrentAuthUser = currentAuthUser; return new RestfulResult { Data = this._productDataService.GetProductInfo(request) }; }