Пример #1
0
        public RestfulResult Favor(FormCollection formCollection, PromotionFavorCreateRequest request, int? authuid, UserModel authUser)
        {
            request.AuthUid = authuid.Value;
            request.AuthUser = authUser;

            if (System.String.Compare(request.Method, DefineRestfulMethod.Destroy, System.StringComparison.OrdinalIgnoreCase) == 0)
            {
                return new RestfulResult
                {
                    Data = this._promotionDataService.DestroyFavor(new PromotionFavorDestroyRequest(request))
                };
            }
            //default
            if (String.IsNullOrWhiteSpace(request.Method))
            {
                return new RestfulResult
                {
                    Data = this._promotionDataService.CreateFavor(new PromotionFavorCreateRequest(request))
                };
            }

            return new RestfulResult() { Data = new ExecuteResult() { StatusCode = StatusCode.ClientError, Message = "方法错误" } };
        }
        /// <summary>
        /// 创建收藏
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ExecuteResult<PromotionInfoResponse> CreateFavor(PromotionFavorCreateRequest request)
        {
            var promotionEntity = _promotionRepository.GetItem(request.Promotionid);
            if (promotionEntity == null)
            {
                return new ExecuteResult<PromotionInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "活动不存在" };
            }
            //检查是否收藏过
            var favorEntity = _favoriteService.Get(request.AuthUid, request.Promotionid, SourceType.Promotion);
            if (favorEntity != null)
            {
                return new ExecuteResult<PromotionInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "您已经添加过收藏了" };
            }

            _favoriteService.Create(new FavoriteEntity
                {
                    CreatedDate = DateTime.Now,
                    CreatedUser = request.AuthUid,
                    Description = String.Empty,
                    FavoriteSourceId = promotionEntity.Id,
                    FavoriteSourceType = (int)SourceType.Promotion,
                    Status = 1,
                    User_Id = request.AuthUid,
                    Store_Id = promotionEntity.Store_Id
                });

            //TODO
            promotionEntity = _promotionRepository.SetCount(PromotionCountType.FavoriteCount, promotionEntity.Id, 1);

            var re = MappingManager.PromotionResponseMapping(promotionEntity, request.CoordinateInfo);
            re = IsR(re, request.AuthUser, request.AuthUser.Id);

            return new ExecuteResult<PromotionInfoResponse> { Data = re };
        }