public ExecuteResult<ProductInfoResponse> CreateFavor(CreateFavorProductRequest request) { if (request == null) { return new ExecuteResult<ProductInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误" }; } var product = _productRepository.GetItem(request.ProductId); if (product == null) { return new ExecuteResult<ProductInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误" }; } var favorentity = _favoriteService.Get(request.AuthUid, product.Id, SourceType.Product); if (favorentity != null) { return new ExecuteResult<ProductInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "您已经添加过收藏了" }; } _favoriteService.Create(new FavoriteEntity { CreatedDate = DateTime.Now, CreatedUser = request.AuthUid, Description = String.Empty, FavoriteSourceId = product.Id, FavoriteSourceType = (int)SourceType.Product, Status = 1, User_Id = request.AuthUid, Store_Id = product.Store_Id }); //+1 product = _productRepository.SetCount(ProductCountType.FavoriteCount, product.Id, 1); //TODO:没有更新当前的isfavorite var response = MappingManager.ProductInfoResponseMapping(product); if (request.AuthUser != null) { response = IsR(response, request.AuthUser, product.Id); } return new ExecuteResult<ProductInfoResponse>(response); }
public ActionResult Favor(CreateFavorProductRequest request, int? authuid, UserModel authUser) { request.AuthUid = authuid.Value; request.AuthUser = authUser; if (System.String.Compare(request.Method, DefineRestfulMethod.Destroy, System.StringComparison.OrdinalIgnoreCase) == 0) { //d return new RestfulResult { Data = this._productDataService.DestroyFavor(new DestroyFavorProductRequest(request)) }; } if (String.IsNullOrWhiteSpace(request.Method)) { return new RestfulResult { Data = this._productDataService.CreateFavor(new CreateFavorProductRequest(request)) }; } return new RestfulResult { Data = new ExecuteResult() { StatusCode = StatusCode.ClientError, Message = "参数错误" } }; }