Beispiel #1
0
        async Task <ICommandResultBase> InstallInternalAsync(IShellFeature feature, string tag)
        {
            // Validate

            if (feature == null)
            {
                throw new ArgumentNullException(nameof(feature));
            }

            if (string.IsNullOrEmpty(feature.ModuleId))
            {
                throw new ArgumentNullException(nameof(feature.ModuleId));
            }

            var user = await _contextFacade.GetAuthenticatedUserAsync();

            // Our result
            var result = new CommandResultBase();

            var categoryResult = await _tagManager.CreateAsync(new TagBase()
            {
                FeatureId     = feature.Id,
                Name          = tag,
                Description   = $"An example desccription for the '{tag}' tag within '{feature.ModuleId}'.",
                CreatedUserId = user?.Id ?? 0,
                CreatedDate   = DateTimeOffset.UtcNow
            });

            if (!categoryResult.Succeeded)
            {
                return(result.Failed(result.Errors.ToArray()));
            }

            return(result.Success());
        }
Beispiel #2
0
        async Task <TagBase> CreateTag(string name)
        {
            // Current user
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            // We need to be authenticated to add tags
            if (user == null)
            {
                return(null);
            }

            // Get feature for tag
            var feature = await _featureFacade.GetFeatureByIdAsync("Plato.Discuss");

            // Create tag
            var result = await _tagManager.CreateAsync(new Tag()
            {
                FeatureId     = feature?.Id ?? 0,
                Name          = name,
                CreatedUserId = user.Id,
                CreatedDate   = DateTimeOffset.UtcNow
            });

            if (result.Succeeded)
            {
                return(result.Response);
            }

            return(null);
        }
Beispiel #3
0
        public async Task <IActionResult> CreatePost(EditTagViewModel viewModel)
        {
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            if (user == null)
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            // Create tag
            var tag = new Tag()
            {
                FeatureId     = await GetFeatureIdAsync(),
                Name          = viewModel.Name,
                Description   = viewModel.Description,
                CreatedUserId = user.Id,
                CreatedDate   = DateTimeOffset.UtcNow
            };

            // Persist tag
            var result = await _tagManager.CreateAsync(tag);

            if (result.Succeeded)
            {
                // Indicate new tag so UpdateAsync does not execute within our view provider
                result.Response.IsNewTag = true;

                // Execute view providers
                await _viewProvider.ProvideUpdateAsync(result.Response, this);

                // Add confirmation
                _alerter.Success(T["Tag Added Successfully!"]);

                // Return
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                // Report any errors
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            return(View(viewModel));
        }
Beispiel #4
0
        protected virtual async Task <TagEditDto> Create(TagEditDto input)
        {
            //TODO:新增前的逻辑判断,是否允许新增

            var entity = ObjectMapper.Map <Tag>(input);

            //调用领域服务
            entity = await _tagManager.CreateAsync(entity);

            var dto = ObjectMapper.Map <TagEditDto>(entity);

            dto.PostId = input.PostId;
            dto.BlogId = input.BlogId;

            await BlogOrPostOfTag(dto, entity);

            return(dto);
        }
Beispiel #5
0
        async Task <TagBase> CreateTag(string name)
        {
            // Get authenticated user
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            // We need to be authenticated to add tags
            if (user == null)
            {
                return(null);
            }

            // Get feature for tag
            var feature = await _featureFacade.GetFeatureByIdAsync(ModuleId);

            // We always need a feature
            if (feature == null)
            {
                return(null);
            }

            // Create tag
            var result = await _tagManager.CreateAsync(new TagBase()
            {
                FeatureId     = feature.Id,
                Name          = name,
                CreatedUserId = user.Id,
                CreatedDate   = DateTime.UtcNow
            });

            if (result.Succeeded)
            {
                return(result.Response);
            }

            return(null);
        }