public JsonResponse ChangeCategoryShow([FromBody] ChangeCategoryShowDto dto) { //判断用户是否登录 if (!TokenHelper.CheckLoginStateByUserId(dto.UserId)) { return(BadResponse("用户未登录", null, false)); } //将所有dto.ShowName的IsShow改为true //将所有dto.HideName的IsShow改为false //dto.ShowName->"'1','2'" var sql = "update AccountCategory set IsShow = 1 where Name in(" + dto.ShowName + ");update AccountCategory set IsShow = 0 where UserId in(" + dto.HideName + ")"; if (!AccountCategoryBll.ExecuteSql(sql)) { return(BadResponse("网络错误,请重试!")); } return(OkResponse(null, "修改成功!")); }
public JsonResponse DeleteUserCategory([FromBody] AccountCategoryDto dto) { //判断用户是否登录 if (!TokenHelper.CheckLoginStateByUserId(dto.UserId)) { return(BadResponse("用户未登录", null, false)); } //查询该类别的Id var categoryModel = AccountCategoryBll.GetModelByName(dto.Name); //从UserInfo中的Category字段里删除该类别 var userModel = UserInfoBll.GetModelById(dto.UserId); if (userModel == null) { return(BadResponse("用户信息出错,请重试!")); } userModel.Category = userModel.Category.Replace((categoryModel.Name + ","), ""); if (!UserInfoBll.Update(userModel)) { return(BadResponse("网络错误,请重试!")); } if (categoryModel == null) { //此时代表数据库出问题了,应作出处理----------------------------------------------------------------- return(OkResponse(null, "删除成功!")); } //类别表中该类别使用数-1,若使用数为0则删除该类别 if (categoryModel.UserNum == 1) { AccountCategoryBll.ExecuteSql("delete from AccountCategory where Name='" + categoryModel.Name + "'"); } else { categoryModel.UserNum--; if (AccountCategoryBll.Update(categoryModel)) { return(BadResponse("网络错误,请重试!")); } } return(OkResponse(null, "删除成功!")); }