Beispiel #1
0
        public ResponseData <ArticleTb> DeleteArticle([FromBody] ArticlePostData postData)
        {
            ResponseData <ArticleTb> responseData;

            if (SessionHelper.IsExist(postData.Guid))
            {
                var article = db.ArticleTb.Where(a => a.articleId == postData.ArticleId).FirstOrDefault();

                article.isDel = true;

                try
                {
                    db.Entry(article).State = System.Data.Entity.EntityState.Modified;
                    if (db.SaveChanges() > 0)
                    {
                        responseData = ResponseHelper <ArticleTb> .SendSuccessResponse();
                    }
                    else
                    {
                        responseData = ResponseHelper <ArticleTb> .SendErrorResponse("修改失败");
                    }
                }
                catch (Exception ex)
                {
                    responseData = ResponseHelper <ArticleTb> .SendErrorResponse(ex.Message);
                }
            }
            else
            {
                responseData = ResponseHelper <ArticleTb> .SendErrorResponse("未登录", Models.StatusCode.OPERATION_ERROR);
            }

            return(responseData);
        }
Beispiel #2
0
        public ResponseData <object> UpdateAritcle([FromBody] ArticlePostData postData)
        {
            ResponseData <object> responseData;

            if (SessionHelper.IsExist(postData.Guid))
            {
                ArticleTb article =
                    db.ArticleTb
                    .Where(a => a.isDel == false && a.articleId == postData.ArticleId)
                    .First();

                if (article != null)
                {
                    article.title   = postData.Title ?? article.title;
                    article.content = postData.Content ?? article.content;
                    try
                    {
                        db.Entry(article).State = System.Data.Entity.EntityState.Modified;
                        if (db.SaveChanges() > 0)
                        {
                            List <object> res = new List <object>()
                            {
                                new
                                {
                                    article.title,
                                    article.content
                                }
                            };
                            responseData = ResponseHelper <object> .SendSuccessResponse(res);
                        }
                        else
                        {
                            responseData = ResponseHelper <object> .SendErrorResponse("修改失败");
                        }
                    }
                    catch (Exception ex)
                    {
                        responseData = ResponseHelper <object> .SendErrorResponse(ex.Message);
                    }
                }
                else
                {
                    responseData = ResponseHelper <object> .SendErrorResponse("无此文章数据");
                }
            }
            else
            {
                responseData = ResponseHelper <object> .SendErrorResponse("未登录", Models.StatusCode.OPERATION_ERROR);
            }

            return(responseData);
        }
Beispiel #3
0
        public ResponseData <ArticleTb> PublishNewArticle([FromBody] ArticlePostData postData)
        {
            ResponseData <ArticleTb> responseData;

            if (SessionHelper.IsExist(postData.Guid))
            {
                ArticleTb article = new ArticleTb()
                {
                    title       = postData.Title,
                    content     = postData.Content,
                    publishTime = DateTime.Now,
                    authorId    = postData.AuthorId
                };

                try
                {
                    db.ArticleTb.Add(article);
                    if (db.SaveChanges() > 0)
                    {
                        responseData = ResponseHelper <ArticleTb> .SendSuccessResponse();
                    }
                    else
                    {
                        responseData = ResponseHelper <ArticleTb> .SendErrorResponse("发布失败");
                    }
                }
                catch (Exception ex)
                {
                    responseData = ResponseHelper <ArticleTb> .SendErrorResponse(ex.Message);
                }
            }
            else
            {
                responseData = ResponseHelper <ArticleTb> .SendErrorResponse("未登录", Models.StatusCode.OPERATION_ERROR);
            }

            return(responseData);
        }