示例#1
0
        public override async Task HandleAsync(ForkItemToWorkbanchAction action, IDispatcher dispatcher)
        {
            if (!await _workbanchService.ContainsItem(action.Item.Id))
            {
                var wbitem = new WorkbanchItemVM
                {
                    Id    = action.Item.Id,
                    Title = action.Item.Title,
                    Type  = action.Type
                };
                switch (action.Type)
                {
                case WorkbanchItemType.Article:
                    var article = action.Item as WorkbanchArticleVM;
                    Console.WriteLine(article.Content);
                    await _workbanchService.CreateNewItem(wbitem, article);

                    dispatcher.Dispatch(new FetchWorkbanchArticleResultAction(article));
                    break;

                case WorkbanchItemType.Course:
                    var course = action.Item as CourseFullInfoVM;
                    await _workbanchService.CreateNewItem(wbitem, course);

                    dispatcher.Dispatch(new FetchWorkbanchCourseAction(course.Id));
                    break;
                }
            }
        }
示例#2
0
        public async Task CreateNewItem <T>(WorkbanchItemVM wbitem, T item) where T : BaseModel
        {
            if (await _localStorageService.ContainKeyAsync(key_all))
            {
                var allItems = await _localStorageService.GetItemAsync <List <WorkbanchItemVM> >(key_all);

                await _localStorageService.SetItemAsync(key_all, allItems.Prepend(wbitem));
            }
            else
            {
                await _localStorageService.SetItemAsync(key_all, new List <WorkbanchItemVM>() { wbitem });
            }
            if (!await _localStorageService.ContainKeyAsync(key + item.Id))
            {
                await _localStorageService.SetItemAsync(key + item.Id, item);
            }
        }
示例#3
0
        public override async Task HandleAsync(CreateNewWorkbanchItemAction action, IDispatcher dispatcher)
        {
            var id        = action.Id ?? Guid.NewGuid();
            var newWBItem = new WorkbanchItemVM
            {
                Id    = id,
                Title = action.Title,
                Type  = action.Type,
            };

            switch (newWBItem.Type)
            {
            case WorkbanchItemType.Article:
                var newArticle = new WorkbanchArticleVM
                {
                    Id       = id,
                    Title    = action.Title,
                    Content  = "",
                    CourseId = null
                };
                await _workbanchService.CreateNewItem(newWBItem, newArticle);

                break;

            case WorkbanchItemType.Course:
                var newCourse = new CourseFullInfoVM
                {
                    Id         = id,
                    Title      = action.Title,
                    RootRecord = new RecordVM()
                    {
                        Id       = Guid.NewGuid(),
                        Title    = "Root",
                        Type     = RecordType.Root,
                        Children = new()
                    }
                };
                await _workbanchService.CreateNewItem(newWBItem, newCourse);

                break;
            }
            _toastService.ShowToast(MBToastLevel.Success, $"Item was succesfully created!");
            dispatcher.Dispatch(new FetchWorkbanchItemsAction(_workbanchState.Value.SearchString /* _workbanchState.Value.SearchType*/));
        }