コード例 #1
0
        protected async Task SubmitAsync()
        {
            if (!string.IsNullOrEmpty(Comment.Content) &&
                Comment.Content != PreviousComment)
            {
                if (Id == null)
                {
                    Comment.PostId = PostId;
                    var contentActivity = new ContentActivity()
                    {
                        Node    = Comment,
                        Message = $"Added a new forum comment: {Comment.Snippet}"
                    };
                    await NodeService.AddAsync(contentActivity);
                }
                else
                {
                    var contentActivity = new ContentActivity()
                    {
                        Node    = Comment,
                        Message = $"Updated a new forum comment: {Comment.Snippet}"
                    };
                    await NodeService.UpdateAsync(contentActivity);
                }
                await OnSave.InvokeAsync(Comment);

                PreviousComment = Comment.Content;
                Comment.Content = string.Empty;
            }
        }
コード例 #2
0
        protected async Task Save()
        {
            if (OnSave.HasDelegate)
            {
                IsSaving = true;
                await OnSave.InvokeAsync(EditingItem);
            }

            Editing(default);
コード例 #3
0
        protected async Task SubmitAsync()
        {
            if (string.IsNullOrEmpty(Id))
            {
                Post.TopicId = TopicId;
                var contentActivity = new ContentActivity()
                {
                    Node    = Post,
                    Message = $"Added a new forum post: {Post.Snippet}"
                };
                await NodeService.AddAsync(contentActivity);
            }
            else
            {
                var contentActivity = new ContentActivity()
                {
                    Node    = Post,
                    Message = $"Updated a forum post: {Post.Snippet}"
                };
                await NodeService.UpdateAsync(contentActivity);
            }

            await OnSave.InvokeAsync(Post);
        }
コード例 #4
0
        private async Task SaveDataAsync(SaveAction saveAction)
        {
            if (DataType == null)
            {
                if (DataSource == null)
                {
                    throw new BlazuiException(2, "DataType 或 DataSource 必须设置一个");
                }
                DataType = DataSource.GetType().GetGenericArguments()[0];
            }
            var row = Activator.CreateInstance(DataType);

            foreach (var header in Headers)
            {
                if ((!header.IsEditable && header.EditorRenderConfig == null) || (saveAction != SaveAction.Create && !CanEdit(header)))
                {
                    if (header.Property != null && (header.Property.Name.Contains("Id") || header.Property.Name.Contains("Key")) && saveAction != SaveAction.Create)
                    {
                        header.Property.SetValue(row, header.Property.GetValue(header.RawValue));
                    }
                    Clear(header);
                    continue;
                }
                if (saveAction != SaveAction.Delete)
                {
                    object cell = Convert.ChangeType(header.EditorRenderConfig.EditingValue, header.Property.PropertyType);
                    if (header.EditorRenderConfig.IsRequired && cell == null)
                    {
                        Toast(header.EditorRenderConfig.RequiredMessage);
                        editingTaskCompletionSource?.TrySetResult(-1);
                        return;
                    }
                    header.Property.SetValue(row, cell);
                }
                Clear(header);
            }
            var tableSaveArg = new TableSaveEventArgs()
            {
                Action = saveAction,
                Data   = row,
                Table  = this,
            };

            if (!OnSave.HasDelegate)
            {
                if (DataType == typeof(KeyValueModel))
                {
                    OnSave = EventCallback.Factory.Create <TableSaveEventArgs>(this, TableRender.DefaultSaverAsync);
                }
                else if (!string.IsNullOrWhiteSpace(Key))
                {
                    OnSave = EventCallback.Factory.Create <TableSaveEventArgs>(this, TableRender.DefaultSaverAsync);
                }
                else
                {
                    Toast("OnSave 事件没有注册或数据源类型不是 KeyValueModel 或没指定 Key");
                    editingTaskCompletionSource?.TrySetResult(-1);
                    return;
                }
            }
            tableSaveArg.Key      = Key;
            tableSaveArg.DataType = DataType;
            if (editingTaskCompletionSource != null)
            {
                await OnSave.InvokeAsync(tableSaveArg);

                if (tableSaveArg.Cancel)
                {
                    editingTaskCompletionSource.TrySetResult(-1);
                    return;
                }
                editingRow        = null;
                dataSourceUpdated = true;
                await RefreshDataSourceAsync(false);

                editingTaskCompletionSource.TrySetResult(0);
                SyncFieldValue();
            }
            else
            {
                if (OnSave.HasDelegate)
                {
                    await OnSave.InvokeAsync(tableSaveArg);

                    if (tableSaveArg.Cancel)
                    {
                        editingTaskCompletionSource?.TrySetResult(-1);
                        return;
                    }
                    editingRow        = null;
                    dataSourceUpdated = true;
                    await RefreshDataSourceAsync(false);

                    editingTaskCompletionSource?.TrySetResult(0);
                    SyncFieldValue();
                    return;
                }
                editingTaskCompletionSource?.TrySetResult(-1);
            }
        }
コード例 #5
0
 public void HandleSave(TItem item)
 {
     OnSave.InvokeAsync(item);
     IsOpen = false;
 }
コード例 #6
0
 protected Task Save()
 => OnSave.InvokeAsync(TodoItem);
コード例 #7
0
 public async Task SaveAsync()
 {
     await OnSave.InvokeAsync(Category);
 }
コード例 #8
0
 Task Save()
 {
     return(OnSave.InvokeAsync(Agent));
 }
コード例 #9
0
        protected async Task Save()
        {
            await JsRuntime.InvokeVoidAsync("laterlist.collapse", $"#{CollapseCardId}", "hide");

            await OnSave.InvokeAsync(InternalTodoList);
        }