예제 #1
0
        public override async Task HandleAsync(EditWorkbanchArticleContentAction action, IDispatcher dispatcher)
        {
            var success = await _workbanchService.EditArticleContent(action.Id, action.Content);

            if (success)
            {
                _toastService.ShowToast(MBToastLevel.Success, "Article was successfully saved!");
                var currentArticle = _workbanchArticleState.Value.Article;
                currentArticle.Content = action.Content;
                dispatcher.Dispatch(new FetchWorkbanchArticleResultAction(currentArticle));
            }
            else
            {
                _toastService.ShowToast(MBToastLevel.Error, "Something went wrong");
            }
        }
예제 #2
0
        public override async Task HandleAsync(DeleteWorkBanchItemAction action, IDispatcher dispatcher)
        {
            await _workbanchService.DeleteItem(action.Id);

            _toastService.ShowToast(MBToastLevel.Success, $"Item was succesfully deleted!");
            Console.WriteLine(_workbanchState.Value.SearchString);
            dispatcher.Dispatch(new FetchWorkbanchItemsAction(_workbanchState.Value.SearchString /*, _workbanchState.Value.SearchType*/));
        }
예제 #3
0
        public override async Task HandleAsync(EditWorkbanchCourseRecordAction action, IDispatcher dispatcher)
        {
            if (_workbanchCourseState.Value.Course.RootRecord.Contains(action.Record.Id))
            {
                await _workbanchService.EditCourse(_workbanchCourseState.Value.Course);

                _toastService.ShowToast(MBToastLevel.Success, "Item was successfully changed!");
            }
        }
예제 #4
0
        public override async Task HandleAsync(EditWorkbanchCourseInfoAction action, IDispatcher dispatcher)
        {
            var mappedEditedCourse = _mapper.Map <CourseFullInfoVM>(action.Course);

            mappedEditedCourse.RootRecord = _workbanchCourseState.Value.Course.RootRecord;
            mappedEditedCourse.Rating     = _workbanchCourseState.Value.Course.Rating;

            bool success = await _workbanchService.EditCourse(mappedEditedCourse);

            if (success)
            {
                _toastService.ShowToast(MBToastLevel.Success, "Course info was successfully changed!");
                dispatcher.Dispatch(new SetWorkbanchCourseAction(mappedEditedCourse));
            }
            else
            {
                _toastService.ShowToast(MBToastLevel.Error, "Something went wrong");
            }
        }
예제 #5
0
        public override async Task HandleAsync(MoveWorkbanchCourseRecordAction action, IDispatcher dispatcher)
        {
            if (_workbanchCourseState.Value.Course.RootRecord.Contains(action.Record.Id))
            {
                if (action.PreviousElement != null && _workbanchCourseState.Value.Course.RootRecord.Contains(action.PreviousElement.Id))
                {
                    var destParent = action.DestinationParent != null && _workbanchCourseState.Value.Course.RootRecord.Contains(action.DestinationParent.Id) ? action.DestinationParent :
                                     _workbanchCourseState.Value.Course.RootRecord.Find(r => r.Children != null && r.Children.Contains(action.PreviousElement));
                    if (destParent.Children.IndexOf(action.Record) == destParent.Children.IndexOf(action.PreviousElement) + 1)
                    {
                        await Success();

                        return;
                    }
                }
                else
                {
                    if (action.DestinationParent != null && _workbanchCourseState.Value.Course.RootRecord.Contains(action.DestinationParent.Id) && action.Record != action.DestinationParent)
                    {
                        var destParent = _workbanchCourseState.Value.Course.RootRecord.Find(r => r.Children != null && r.Children.Contains(action.Record));
                        if (destParent.Children.IndexOf(action.Record) == 0)
                        {
                            await Success();

                            return;
                        }
                    }
                }
            }
            _toastService.ShowToast(MBToastLevel.Error, "Someting went wrong");

            async Task Success()
            {
                await _workbanchService.EditCourse(_workbanchCourseState.Value.Course);

                _toastService.ShowToast(MBToastLevel.Success, "Item was successfully moved!");
            }
        }
예제 #6
0
        public override async Task HandleAsync(AddArticleCommitAction action, IDispatcher dispatcher)
        {
            var article = await _articleService.GetArticle(action.ArticleId, action.PrevCommitId);

            var prevCommit = article?.Commits?.FirstOrDefault(c => c.Id == action.PrevCommitId);

            if (prevCommit != null)
            {
                var oldContent = article.ArticleInfo.Content;
                var diffResult = Differ.Instance.CreateWordDiffs(oldContent, action.Content, false, false, new[] { ' ' });
                var diffWords  = new List <string>();
                foreach (var diff in diffResult.DiffBlocks)
                {
                    if (diff.InsertCountB != 0)
                    {
                        diffWords.AddRange(diffResult.PiecesNew.Skip(diff.InsertStartB).Take(diff.InsertCountB));
                    }
                }
                //var commit = new ArticleCommitVM
                //{
                //    Id = Guid.NewGuid(),
                //    Title = action.Title,
                //    Description = action.Description,
                //    Type = action.CommitType,
                //    CreatedAt = DateTime.Now,
                //    CreatedBy = "artbiel",
                //    CommitState = CommitState.Unsent,
                //    DiffBlocks = diffResult.DiffBlocks.ToArticleDiffBlocks(),
                //    DiffWords = diffWords.ToArray(),
                //    PrevCommitId = action.PrevCommitId
                //};
                //article.Commits.Add(commit);
                //dispatcher.Dispatch(new SetArticleCommitsAction(article.Commits, commit));
            }
            var commit = new ArticleCommitMainInfoVM
            {
                Id           = Guid.NewGuid(),
                Title        = action.Title,
                Description  = action.Description,
                Type         = action.CommitType,
                CreatedAt    = DateTime.Now,
                CreatedBy    = "artbiel",
                CommitState  = CommitState.Unsent,
                PrevCommitId = action.PrevCommitId,
                Content      = action.Content
            };
            await _articleService.AddCommit(action.ArticleId, commit);

            _toastService.ShowToast(MBToastLevel.Success, "Commit was successfully added!");
        }
예제 #7
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*/));
        }