public virtual Result Create(T entity, BaseAppUser user, Action <bool, T> action = null) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (user == null) { throw new ArgumentNullException(nameof(user), "可跟踪实体必须提供操作人信息"); } entity.BeforeCreate(user); var error = BeforeCreate(entity, user); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.AuthFail(error)); } entity.Id = Db.Create(entity); var success = entity.Id > 0; action?.Invoke(success, entity); return(success ? ResultUtil.Success(entity) : ResultUtil.Fail()); }
/// <summary> /// 创建实体 /// </summary> /// <param name="entity">实体对象</param> /// <param name="user">操作人</param> /// <returns></returns> public virtual Result Create(T entity, IAppUser user, Action Cb = null) { var error = ValidateCreate(entity, user); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.AuthFail(error)); } entity.BeforeCreate(user); var id = db.Create <T>(entity); if (id > 0) { if (Cb != null) { Cb(); } return(ResultUtil.Success <int>(id)); } else { return(ResultUtil.Fail()); } }
public Result <int> Create(AssetCate cate, IAppUser user) { try { var error = Validate(cate); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.Do(ResultCodes.验证失败, 0, error)); } cate.BeforeCreate(user); var id = _db.Create(cate); if (id > 0) { AssetCateUtil.Clear(); return(ResultUtil.Success(id)); } return(ResultUtil.Do(ResultCodes.数据库操作失败, 0, "数据写入失败")); } catch (Exception ex) { return(ResultUtil.Exception(ex, 0)); } }
/// <summary> /// 创建 /// </summary> /// <param name="entity"></param> /// <returns></returns> public Result <int> Create(ServiceApply entity) { entity.ReceiveAt = null; entity.CompleteAt = null; entity.State = "待处理"; entity.CreateAt = DateTime.Now; entity.ServiceManId = null; entity.ServiceManName = null; entity.Reply = ""; entity.Score = "--"; var id = _db.Create(entity); return(id > 0 ? ResultUtil.Success(id) : ResultUtil.Do(ResultCodes.数据库操作失败, 0)); }
public Result <int> Create(User u, IAppUser user) { var error = Validate(u); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.Do(ResultCodes.验证失败, 0, error)); } u.Pw = AESEncriptUtil.Encrypt("123456"); u.Version = Guid.NewGuid().ToString("N"); u.BeforeCreate(user); var id = _db.Create(u); return(id > 0 ? ResultUtil.Success(id) : ResultUtil.Do(ResultCodes.数据库操作失败, 0)); }
public virtual Result Create(T entity, Action <bool, T> action = null) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } var error = BeforeCreate(entity); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.AuthFail(error)); } entity.Id = Db.Create(entity); action?.Invoke(entity.Id > 0, entity); return(entity.Id > 0 ? ResultUtil.Success(entity) : ResultUtil.Fail()); }
public virtual Result <int> Create(T t, IAppUser user) { try { var error = ValidCreate(t, user); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.Do(ResultCodes.验证失败, 0, error)); } t.BeforeCreate(user); var id = db.Create(t); return(id > 0 ? ResultUtil.Success(id) : ResultUtil.Do(ResultCodes.数据库操作失败, 0, "数据写入失败")); } catch (Exception ex) { return(ResultUtil.Exception(ex, 0)); } }
/// <summary> /// 创建 /// </summary> /// <param name="entity"></param> /// <param name="user"></param> /// <returns></returns> public Result <int> Create(Account entity, IAppUser user) { try { var error = Validate(entity); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.Do <int>(ResultCodes.验证失败, 0, error)); } entity.BeforeCreate(user); var id = _db.Create <Account>(entity); return(id > 0 ? ResultUtil.Success <int>(id) : ResultUtil.Do <int>(ResultCodes.数据库操作失败, 0, "数据写入失败")); } catch (Exception ex) { return(ResultUtil.Exception <int>(ex, 0)); } }