Пример #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 void SaveToDB(string Detail, string Title)
 {
     _repoWrapper.Log.Add(new LogEntity
     {
         CreateDate = DateTime.Now,
         IsDeleted  = false,
         LogText    = Detail,
         LogTitle   = Title
     });
     _repoWrapper.Save();
 }
Пример #3
0
        public Models.ResultModels.BaseResultModel <Models.ResultModels.ApiResultModel> GetCurrentVersion()
        {
            try
            {
                Models.ResultModels.BaseResultModel <Models.ResultModels.ApiResultModel> apiVersion = new Models.ResultModels.BaseResultModel <Models.ResultModels.ApiResultModel>();

                if (!_memoryCache.TryGetValue(memoryCacheKey, out apiVersion))
                {
                    var result = _repoWrapper.ApiVersion.GetUptoDateVersion();
                    apiVersion = new Models.ResultModels.BaseResultModel <Models.ResultModels.ApiResultModel>
                    {
                        Result       = true,
                        ResultObject = new Models.ResultModels.ApiResultModel
                        {
                            VersionName   = result.VersionName,
                            VersionDetail = result.VersionDetail
                        }
                    };

                    var cacheExpirationOpts = new MemoryCacheEntryOptions
                    {
                        AbsoluteExpiration = DateTime.Now.AddMinutes(1),
                        Priority           = CacheItemPriority.Normal
                    };
                    _memoryCache.Set(memoryCacheKey, apiVersion, cacheExpirationOpts);
                }

                return(apiVersion);
            }
            catch (Exception ex)
            {
                _repoWrapper.Log.Add(new Data.Models.LogEntity
                {
                    CreateDate = DateTime.Now,
                    IsDeleted  = false,
                    LogText    = ex.ToString(),
                    LogTitle   = "GetCurrentVersion Metodunda Hata"
                });
                _repoWrapper.Save();
                return(new Models.ResultModels.BaseResultModel <Models.ResultModels.ApiResultModel>
                {
                    Result = false,
                    ErrorText = "Bir hata oluştu, daha sonra tekrar deneyiniz"
                });
            }
        }
Пример #4
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"
                });
            }
        }