protected virtual async Task <ApiResult> UpdateInternal( DbContext db, ClassifierType type, ClassifierTree tree, Classifier item, CancellationToken cancellationToken = default) { var validator = new ClassifierValidator(db, type); if (await validator.ValidateUpdate(item, cancellationToken) == false) { return(new ApiResult { Success = false, Errors = validator.Errors }); } var affected = await db.GetTable <DbClassifier>() .Where(x => x.Uid == item.Uid) .Set(x => x.Code, item.Code) .Set(x => x.Name, item.Name) .Set(x => x.ParentUid, type.HierarchyType == HierarchyType.Items ? item.ParentUid : null) .Set(x => x.IsActive, item.IsActive) .UpdateAsync(cancellationToken); var result = await UpdateHierarchy(db, type, tree, item, cancellationToken); if (result.Success == false) { return(result); } return(new ApiResult { AffectedRows = affected }); }
protected virtual async Task <ApiResult> InsertInternal(DbContext db, ClassifierType type, Classifier item, CancellationToken cancellationToken = default) { var validator = new ClassifierValidator(db, type); if (await validator.ValidateInsert(item, cancellationToken) == false) { return(new ApiResult { Success = false, Errors = validator.Errors }); } // todo: company + modification data // insert classifier await db.GetTable <DbClassifier>() .Value(x => x.Uid, item.Uid) .Value(x => x.TypeUid, type.Uid) .Value(x => x.StatusCode, ClassifierStatusCode.Active) .Value(x => x.Code, item.Code) .Value(x => x.Name, item.Name) // todo: validate parent belongs to the same classifier .Value(x => x.ParentUid, type.HierarchyType == HierarchyType.Items ? item.ParentUid : null) .Value(x => x.IsActive, item.IsActive) .Value(x => x.IsSystem, item.IsSystem) .InsertAsync(cancellationToken); var result = await InsertHierarchy(db, type, item, cancellationToken); if (result.Success == false) { return(result); } return(new ApiResult { Uid = item.Uid }); }