/// <summary> /// 移除数据 /// </summary> /// <param name="id"></param> /// <param name="user"></param> /// <returns></returns> public Result Delete(int id, IAppUser user) { try { var entity = _db.Load <Account>(id); if (entity == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "请求的数据不存在")); } var assetCount = _db.GetCount <Asset>(MySearchUtil.New() .AndEqual("AccountId", id) .AndEqual("IsDel", false)); if (assetCount > 0) { return(ResultUtil.Do(ResultCodes.验证失败, "此用户下资产不为空,禁止删除")); } var row = _db.Remove <Account>(id); return(row > 0 ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); } catch (Exception ex) { return(ResultUtil.Exception(ex)); } }
public Result Delete(int id, IAppUser user) { try { var entity = _db.Load <Dept>(id); if (entity == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "请求的数据不存在")); } var childrenCount = _db.GetCount <Dept>(MySearchUtil.New() .AndEqual("ParentId", id) .AndEqual("IsDel", false)); if (childrenCount > 0) { return(ResultUtil.Do(ResultCodes.验证失败, "下属部门不为空,禁止删除")); } var accountCount = _db.GetCount <Account>(MySearchUtil.New() .AndEqual("DeptId", id) .AndEqual("IsDel", false)); if (accountCount > 0) { return(ResultUtil.Do(ResultCodes.验证失败, "部门内员工不为空,禁止删除")); } var row = _db.Remove <Dept>(id); if (row > 0) { DeptUtil.Clear(); return(ResultUtil.Success()); } else { return(ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); } } catch (Exception ex) { return(ResultUtil.Exception(ex)); } }
private string Validate(User entity) { if (string.IsNullOrWhiteSpace(entity.Name)) { return("用户名称不能为空"); } var count = _db.GetCount <User>(MySearchUtil.New() .AndEqual("Name", entity.Name.Trim()) .AndNotEqual("Id", entity.Id) .AndEqual("IsDel", false)); return(count > 0 ? "用户已存在" : string.Empty); }