Beispiel #1
0
        public async Task <ApiResult> AdminEditArticleAsync(AdminEditArticleRequest request)
        {
            var user = GetUser();

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

            return(await _articleService.AdminEditArticleAsync(request, user.UserId, user.UserName));
        }
Beispiel #2
0
        /// <summary>
        /// 后台-编辑文章
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ApiResult> AdminEditArticleAsync(AdminEditArticleRequest request, long userId, string userName)
        {
            var response = new ApiResult();

            try
            {
                var article = await _articleRepository.Table
                              .FirstOrDefaultAsync(item => item.Id == request.ArticleId && item.Status == 1 && item.UserId == userId);

                var detail = await _articleDetailRepository.Table
                             .FirstOrDefaultAsync(item => item.ArticleId == request.ArticleId && item.Status == 1);

                if (article == null || detail == null)
                {
                    response.Code    = Code.Error;
                    response.Message = "查无文章";
                    return(response);
                }

                article.Title    = request.Title;
                article.Describe = request.Desc;
                article.IsTop    = request.IsTop;
                detail.Content   = request.Content;

                article.UpdateTime = DateTime.Now;
                article.Operator   = userName;
                detail.UpdateTime  = DateTime.Now;
                detail.Operator    = userName;

                await _work.SaveChangesAsync();

                response.Code    = Code.Ok;
                response.Message = "操作成功";
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError($"编辑文章异常;method={nameof(AdminEditArticleAsync)};param={request.ToJson()};exception messges={ex.Message}");
                response.Code    = Code.Error;
                response.Message = $"编辑文章异常:{ex.Message}";
                return(response);
            }
        }