示例#1
0
        public async Task <Models.ResultModels.BaseResultModel <object> > DeleteArticle([FromBody] Models.PostModels.ArticlePostModel model)
        {
            try
            {
                var _currentArticle = await _repoWrapper.Article.GetArticleDetailByIdWithAuthor(model.Id);

                var _author = GetCurrentAuthor;
                if (_currentArticle.Author.Id != _author.Id)
                {
                    return(new Models.ResultModels.BaseResultModel <object>
                    {
                        ErrorText = "Bu başkasına ait bir makale",
                        Result = false
                    });
                }

                _currentArticle.IsDeleted = true;

                _repoWrapper.Article.Update(_currentArticle);
                _repoWrapper.Save();
                return(new Models.ResultModels.BaseResultModel <object>
                {
                    Result = true
                });
            }
            catch (Exception ex)
            {
                _logService.SaveToDB(ex.ToString(), "DeleteArticle Metodunda Hata");
                return(new Models.ResultModels.BaseResultModel <object>
                {
                    ErrorText = "Bir hata oluştu",
                    Result = false
                });
            }
        }
示例#2
0
        public Models.ResultModels.BaseResultModel <object> CreateComment([FromBody] Models.PostModels.CommentModel model)
        {
            try
            {
                var _article = _repoWrapper.Article.Get(model.ArticleId);
                if (_article == null)
                {
                    return(new Models.ResultModels.BaseResultModel <object>
                    {
                        Result = false,
                        ErrorText = "Article bulunamadı"
                    });
                }

                Data.Models.CommentEntity commentEntity = new Data.Models.CommentEntity();
                commentEntity.IsDeleted       = false;
                commentEntity.CreateDate      = DateTime.Now;
                commentEntity.CommentatorName = model.CommentatorName;
                commentEntity.CommentContent  = model.CommentContent;


                commentEntity.Article = _article;

                _repoWrapper.Comment.Add(commentEntity);
                _repoWrapper.Save();

                return(new Models.ResultModels.BaseResultModel <object>
                {
                    Result = true
                });
            }
            catch (Exception ex)
            {
                _logService.SaveToDB(ex.ToString(), "CreateComment Metodunda Hata");
                return(new Models.ResultModels.BaseResultModel <object>
                {
                    Result = false,
                    ErrorText = "Bir hata oluştu, daha sonra tekrar deneyiniz"
                });
            }
        }