public ExecuteResult<CouponInfoResponse> Get(CouponInfoGetRequest request)
        {
            if (request == null)
            {
                return new ExecuteResult<CouponInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误" };
            }

            var entity = this._couponRepository.GetItem(request.CouponId);

            if (entity.User_Id == request.AuthUid && entity.CouponId == request.CouponCode)
            {
                return new ExecuteResult<CouponInfoResponse>(MappingManager.CouponInfoResponseMapping(entity));
            }

            return new ExecuteResult<CouponInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "您不能领取他人的优惠券" };
        }
Esempio n. 2
0
        public ActionResult Detail(CouponInfoGetRequest request, int? authuid, UserModel authUser)
        {
            request.AuthUser = authUser;
            if (request == null)
                return new RestfulResult { Data = new ExecuteResult<CouponInfoResponse>(null) };
            var linq = _couponRepo.Get(c => c.User_Id == authUser.Id && c.Status != (int)CouponStatus.Deleted);
            var linq2 = linq.GroupJoin(_productRepo.GetAll(), o => o.FromProduct, i => i.Id, (o, i) => new { C = o, Pd = i })
                           .GroupJoin(_promotionRepo.GetAll(), o => o.C.FromPromotion, i => i.Id, (o, i) => new { C = o.C, Pd = o.Pd, Pr = i });
            var responseData = from l in linq2.ToList()
                               select new CouponInfoResponse().FromEntity<CouponInfoResponse>(l.C,
                                            c =>
                                            {
                                                var prod = l.Pd.FirstOrDefault();
                                                if (prod != null)
                                                {
                                                    c.ProductInfoResponse = new ProductInfoResponse().FromEntity<ProductInfoResponse>(prod);
                                                    c.ProductId = c.ProductInfoResponse.Id;
                                                    c.ProductName = c.ProductInfoResponse.Name;
                                                    c.ProductDescription = c.ProductInfoResponse.Description;
                                                }
                                                var pro = l.Pr.FirstOrDefault();
                                                if (pro != null)
                                                {
                                                    c.PromotionInfoResponse = new PromotionInfoResponse().FromEntity<PromotionInfoResponse>(pro);

                                                }
                                            });
            return new RestfulResult { Data = new ExecuteResult<CouponInfoResponse>(responseData.FirstOrDefault()) };
        }