Exemple #1
0
        public async Task ApplyItem(int rowIndex, Func <ItemsChangedArgs, Task> asyncAction)
        {
            var editingFields = Fields.Where(f => CreateFieldState(f, rowIndex)?.IsEditing == true);

            _validations = _dataValidationProvider.ValidateModel(Form, ModelItems[rowIndex], rowIndex, editingFields);
            UpdateFieldStateValidations(_validations, rowIndex);

            if (_validations.Any())
            {
                return;
            }

            Error = null;
            var args = new ItemsChangedArgs {
                Entity = ModelType, RowIndex = rowIndex
            };

            args.Operation = ModelItems[rowIndex].GetBag <RowState>().IsNew ? ItemOperations.Add : ItemOperations.Update;

            try
            {
                // await ItemsChanged.InvokeAsync(args);
                await asyncAction(args);
            }
            catch (Exception exc)
            {
                LogException(exc);
                // StateHasChanged();
            }

            if (Error == null)
            {
                ModelItems[rowIndex].GetBag <RowState>().IsEditing = false;
                ModelItems[rowIndex].GetBag <RowState>().IsNew     = false;
                IsEditing = false;
                SetPrimaryKeyIsNew(rowIndex, false);
            }
        }
 public async Task Validate()
 {
     _validations = _dataValidationProvider.ValidateModel(_form, ModelItem, 0, Fields, _fieldStates);
     UpdateFieldStateValidations(_validations, 0);
 }