예제 #1
0
        /**
         * 发布文章
         *
         * @param contents 文章对象
         */
        public int publish(ContentInput contents)
        {
            if (null == contents.AuthorId)
            {
                throw new Exception("请登录后发布文章");
            }
            contents.Created  = DateTime.Now;
            contents.Modified = DateTime.Now;
            contents.Hits     = 0;
            if (contents.FmtType.IsNullOrWhiteSpace())
            {
                contents.FmtType = "markdown";
            }
            var tags       = contents.Tags;
            var categories = contents.Categories;

            var entity = new Contents();

            _mapper.Map(contents, entity);

            var cid = _repository.InsertOrUpdateAndGetId(entity);

            _metasService.saveMetas(cid, tags, Types.TAG);
            _metasService.saveMetas(cid, categories, Types.CATEGORY);

            return(cid);
        }
예제 #2
0
        public async Task <int> AddEditContentWithFile(ContentInput model)
        {
            var activeTheme = await _settingStore.GetSettingOrNullAsync(TenantId, null, ConfigConst.Theme);

            if (model.Id == 0)
            {
                var mainPageContent = new MainPageContentManager.Entities.MainPageContent();
                var id = _mainPageContentProvider.AddContent(mainPageContent);

                var resolvedFolder = string.Format(FileFolder, TenantId, activeTheme.Value);
                var image          = _imageProvider.SaveImage(null, null, model.File, resolvedFolder);
                mainPageContent.Value = image;
                return(id);
            }
            else
            {
                var mainPageContent = _mainPageContentProvider.GetContent(model.Id);
                var resolvedFolder  = string.Format(FileFolder, TenantId, activeTheme.Value);
                mainPageContent.Key = model.Key;
                if (model.File.ContentLength <= 0)
                {
                    return(mainPageContent.Id);
                }
                var image = _imageProvider.SaveImage(null, null, model.File, resolvedFolder);
                mainPageContent.Value = image;
                return(mainPageContent.Id);
            }
        }
예제 #3
0
        public ApiResponse NewPage([FromBody] ContentInput contents)
        {
            var users = _userService.CurrentUsers;

            contents.Type      = Types.PAGE;
            contents.AllowPing = true;
            contents.AuthorId  = users.Uid;
            _contentsService.publish(contents);
            return(ApiResponse.Ok());
        }
예제 #4
0
        public ApiResponse UpdatePage([FromBody] ContentInput contents)
        {
            if (null == contents.Id)
            {
                return(ApiResponse.Fail("缺少参数,请重试"));
            }
            int cid = contents.Id.Value;

            contents.Type = Types.PAGE;
            _contentsService.updateArticle(contents);
            return(ApiResponse.Ok(cid));
        }
예제 #5
0
        public ApiResponse <int> UpdateArticle([FromBody] ContentInput contents)
        {
            if (contents?.Id == null)
            {
                return(ApiResponse <int> .Fail("缺少参数,请重试"));
            }
            contents.Type = Types.ARTICLE;
            var cid = contents.Id.Value;

            _contentsService.updateArticle(contents);
            return(ApiResponse <int> .Ok(cid, cid));
        }
예제 #6
0
                public void StartListening()
                {
                    while (true)
                    {
                        if (ContentInput is null)
                        {
                            return;
                        }

                        ContentInput.Invoke(this, Console.ReadLine());
                    }
                }
예제 #7
0
        public ApiResponse <int> NewArticle([FromBody] ContentInput contents)
        {
            var user = _userService.CurrentUsers;

            contents.Type     = Types.ARTICLE;
            contents.AuthorId = user.Uid;
            //将点击数设初始化为0
            contents.Hits = 0;
            //将评论数设初始化为0
            contents.CommentsNum = 0;
            if (StringKit.IsBlank(contents.Categories))
            {
                contents.Categories = "默认分类";
            }
            var cid = _contentsService.publish(contents);

            return(ApiResponse <int> .Ok(cid, cid));
        }
예제 #8
0
        public int AddEditContent(ContentInput input)
        {
            if (input.Id != 0)
            {
                var content = _mainPageContentProvider.GetContent(input.Id);
                if (content == null)
                {
                    throw new UserFriendlyException();
                }
                var edited = input.MapTo(content);
                return(_mainPageContentProvider.AddContent(edited));
            }
            var newContent = input.MapTo <MainPageContentManager.Entities.MainPageContent>();

            newContent.ThemeReferenceId   = "Custom";
            newContent.ThemeReferenceName = "Custom";
            newContent.IsStatic           = false;
            return(_mainPageContentProvider.AddContent(newContent));
        }
예제 #9
0
        /**
         * 编辑文章
         *
         * @param contents 文章对象
         */
        public void updateArticle(ContentInput contents)
        {
            contents.Modified   = DateTime.Now;
            contents.Tags       = contents.Tags ?? "";
            contents.Categories = contents.Categories ?? "";

            var entity = new Contents();

            _mapper.Map(contents, entity);

            var cid = _repository.InsertOrUpdateAndGetId(entity);

            var tags       = contents.Tags;
            var categories = contents.Categories;

            if (null != contents.Type && !contents.Type.Equals(Types.PAGE))
            {
                _relationshipService.DeleteByContentId(cid);
            }

            _metasService.saveMetas(cid, tags, Types.TAG);
            _metasService.saveMetas(cid, categories, Types.CATEGORY);
        }