请问下该怎么做判断
还需要调用接口吗?
wx.request({
url: api.CartAdd,
method: 'POST',
data: { UserId:uid,ProductId: that.p_id , Quantity: that.data.number },
complete:function(res){
if (res.data != null) {
wx.showToast({
title: '添加成功'
});
that.setData({
openAttr: !that.data.openAttr,
cartGoodsCount:res.data.Quantity
});
}
else{
wx.showToast({
image: '/images/icon_error.png',
title: res.errMsg,
mask: true
});
}
}
})
.NET
API:
[HttpPost]
public async Task<IActionResult> Create(string productid,int quantity, WsUserCartViewModel model)
{
var predicate = PredicateBuilder.True<WsUserCart>();
predicate = predicate.And(a => a.Deleted == false);
if (!string.IsNullOrEmpty(productid))
{
predicate = predicate.And(a => a.ProductId == productid);
}
var page = _wsUserCartService.GetPagedList(predicate, 1, 10000).Result;
//查询是否有数据 条件ProductId(唯一的)
if (page.Count==0)
{ //添加数据 实现小程序产品加入购物车功能 判断是否有重复的 累加
if (ModelState.IsValid)
{
model.CreatedOn = DateTime.Now;
model.UpdatedOn = DateTime.Now;
await _wsUserCartService.AddViewModel(model);
}
return Ok(model);
}
else
{ //查询当前购物车列表 上面if里添加的这条数据 的数量 在下面 修改的时候 加上修改的数量 总数量=page1[0].Quantity+quantity
var page1 = _wsUserCartService.GetPagedList(predicate, 1, 10000).Result;
var id = page[0].Id;
var ucmodel = await _wsUserCartService.GetViewModel(id);
ucmodel.Quantity = page1[0].Quantity+quantity;
await _wsUserCartService.UpdateViewModel(ucmodel);
return Ok(ucmodel);
}
}