Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e23f12c

Browse files
Some Bugs and Problems Solved
Article Getall metoduna includecomment alanları IArticleService interface’ine GetArticleByCommentId metotları ArticlesController refactored Article GetById methoduna includeComments alanları eklendi ArticleManager GetArticlePictureByArticleId CommentWithoutUsers GetById includearticle çalışmıyor CommentWithoutUsers Update Username kontrol etme işlemi CommenWithUser getbyid includearticle
1 parent f8003a0 commit e23f12c

File tree

10 files changed

+68
-35
lines changed

10 files changed

+68
-35
lines changed

‎src/v2/CmnSoftwareBackend.API/Controllers/ArticlesController.cs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ public ArticlesController(IArticleService articleService)
2828
[HttpGet]
2929
[ProducesResponseType(200)]
3030
[Route("[action]")]
31-
public async Task<IActionResult> GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticlePicture)
31+
public async Task<IActionResult> GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticlePicture,boolincludeCommentWithoutUser,boolincludeCommentWithUser)
3232
{
33-
var result = await _articleService.GetAllAsync(isActive, isDeleted, isAscending, currentPage, pageSize, orderBy, includeArticlePicture);
33+
var result = await _articleService.GetAllAsync(isActive, isDeleted, isAscending, currentPage, pageSize, orderBy, includeArticlePicture,includeCommentWithoutUser,includeCommentWithUser);
3434
return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "Articles", Action = "GetAll" })));
3535
}
3636
[HttpGet]
3737
[ProducesResponseType(200)]
3838
[Route("[action]")]
39-
public async Task<IActionResult> GetById(int articleId, bool includeArticlePicture)
39+
public async Task<IActionResult> GetById(int articleId, bool includeArticlePicture,boolcommentWithUser,boolcommentWithoutUser)
4040
{
41-
var result = await _articleService.GetByIdAsync(articleId, includeArticlePicture);
41+
var result = await _articleService.GetByIdAsync(articleId, includeArticlePicture,commentWithUser,commentWithoutUser);
4242
return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "Articles", Action = "GetById" })));
4343
}
4444
[HttpGet]
@@ -54,8 +54,8 @@ public async Task<IActionResult> GetArticleByUserId(Guid userId)
5454
[Route("[action]")]
5555
public async Task<IActionResult> GetArticleByArticlePictureId(int ArticlePictureId)
5656
{
57-
var articles =await _articleService.GetArticleByArticlePictureId(ArticlePictureId);
58-
return Ok(new SuccessDataApiResult(articles,Url.Link("",new {Controller="Articles",Action="GetArticleByArticlePictureId" })));
57+
var articles =await _articleService.GetArticleByArticlePictureId(ArticlePictureId);
58+
return Ok(new SuccessDataApiResult(articles,Url.Link("",new {Controller="Articles",Action="GetArticleByArticlePictureId" })));
5959
}
6060

6161
[HttpPost]
@@ -71,9 +71,9 @@ public async Task<IActionResult> AddAsync(ArticleAddDto articleAddDto)
7171
[ProducesResponseType(400)]
7272
[ProducesResponseType(500)]
7373
[Route("[action]")]
74-
public async Task<IActionResult> DeleteAsync(int articleId,Guid CreatedUserId)
74+
public async Task<IActionResult> DeleteAsync(int articleId,Guid CreatedUserId)
7575
{
76-
var result = await _articleService.DeleteAsync(articleId,CreatedUserId);
76+
var result = await _articleService.DeleteAsync(articleId,CreatedUserId);
7777
return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "Articles", Action = "Delete" })));
7878
}
7979
[HttpPost]

‎src/v2/CmnSoftwareBackend.API/Controllers/CommentWithUsersController.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public async Task<IActionResult> GetAllAsync(bool? isActive, bool? isDeleted, bo
3333
}
3434
[HttpGet]
3535
[Route("[action]")]
36-
public async Task<IActionResult> GetByIdAsync(int commentWithUserId, bool includeArticle)
36+
public async Task<IActionResult> GetByIdAsync(int commentWithUserId, bool includeArticle,boolincludeUser)
3737
{
38-
var result = await _commentWithUserService.GetByIdAsync(commentWithUserId, includeArticle);
38+
var result = await _commentWithUserService.GetByIdAsync(commentWithUserId, includeArticle,includeUser);
3939
return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "CommentWithUser", Action = "GetById" })));
4040
}
4141
[HttpPost]

‎src/v2/CmnSoftwareBackend.API/c:\temp\cmn-internal-nlog.txt‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6393,3 +6393,27 @@ ClientConnectionId:00000000-0000-0000-0000-000000000000
63936393
2021年09月29日 17:13:21.6511 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config
63946394
2021年09月29日 17:13:21.7657 Info Configuration initialized.
63956395
2021年09月29日 17:13:21.7657 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False
6396+
2021年09月29日 17:46:50.9922 Info Message Template Auto Format enabled
6397+
2021年09月29日 17:46:51.0125 Info Loading assembly: NLog.Web.AspNetCore
6398+
2021年09月29日 17:46:51.0497 Info Adding target FileTarget(Name=allfile)
6399+
2021年09月29日 17:46:51.0508 Info Adding target FileTarget(Name=ownFile-web)
6400+
2021年09月29日 17:46:51.0602 Info Adding target DatabaseTarget(Name=database)
6401+
2021年09月29日 17:46:51.1538 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config
6402+
2021年09月29日 17:46:51.2403 Info Configuration initialized.
6403+
2021年09月29日 17:46:51.2411 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False
6404+
2021年09月29日 17:49:31.3686 Info Message Template Auto Format enabled
6405+
2021年09月29日 17:49:31.3895 Info Loading assembly: NLog.Web.AspNetCore
6406+
2021年09月29日 17:49:31.4269 Info Adding target FileTarget(Name=allfile)
6407+
2021年09月29日 17:49:31.4285 Info Adding target FileTarget(Name=ownFile-web)
6408+
2021年09月29日 17:49:31.4381 Info Adding target DatabaseTarget(Name=database)
6409+
2021年09月29日 17:49:31.5269 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config
6410+
2021年09月29日 17:49:31.6204 Info Configuration initialized.
6411+
2021年09月29日 17:49:31.6212 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False
6412+
2021年09月29日 17:57:09.1053 Info Message Template Auto Format enabled
6413+
2021年09月29日 17:57:09.1243 Info Loading assembly: NLog.Web.AspNetCore
6414+
2021年09月29日 17:57:09.1601 Info Adding target FileTarget(Name=allfile)
6415+
2021年09月29日 17:57:09.1613 Info Adding target FileTarget(Name=ownFile-web)
6416+
2021年09月29日 17:57:09.1703 Info Adding target DatabaseTarget(Name=database)
6417+
2021年09月29日 17:57:09.2386 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config
6418+
2021年09月29日 17:57:09.3245 Info Configuration initialized.
6419+
2021年09月29日 17:57:09.3254 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False

‎src/v2/CmnSoftwareBackend.Services/Abstract/IArticleService.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface IArticleService
1010
{
1111
Task<IDataResult> GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending,
1212
int currentPage, int pageSize, OrderBy orderBy,bool includePicture, bool includeCommentWithoutUser, bool includeCommentWithUser);
13-
Task<IDataResult> GetByIdAsync(int articleId,bool includeArticlePicture);
13+
Task<IDataResult> GetByIdAsync(int articleId,bool includeArticlePicture,boolincludeCommentWithUserId,boolincludeCommentWithoutUserId);
1414
Task<IDataResult> GetArticleByCommentWithUserIdAsync(int commentWithUserId);
1515
Task<IDataResult> GetArticleByCommentWithoutUserIdAsync(int commentWithoutUserId);
1616
Task<IDataResult> GetArticleByUserId(Guid userId);

‎src/v2/CmnSoftwareBackend.Services/Abstract/ICommentWithUserService.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace CmnSoftwareBackend.Services.Abstract
99
public interface ICommentWithUserService
1010
{
1111
Task<IDataResult> GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticle, bool includeUser);
12-
Task<IDataResult> GetByIdAsync(int commentWithUserId, bool includeArticle);
12+
Task<IDataResult> GetByIdAsync(int commentWithUserId, bool includeArticle,boolincludeUser);
1313
Task<IDataResult> GetAllCommentByUserId(Guid userId, bool includeArticle);
1414
Task<IDataResult> AddAsync(CommentWithUserAddDto commentWithUserAddDto);
1515
Task<IDataResult> UpdateAsync(CommentWithUserUpdateDto commentWithUserUpdateDto);

‎src/v2/CmnSoftwareBackend.Services/AutoMapper/Profiles/CommentWithUserProfile.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public CommentWithUserProfile()
1515
// CreateMap<ArticleDto, Article>();
1616
//
1717
CreateMap<CommentWithUserDto, CommentWithUser>().ForMember(dest=>dest.CreatedDate,x=>x.MapFrom(x=>DateTime.Now)).ForMember(dest=>dest.ModifiedDate,x=>x.MapFrom(x=>DateTime.Now)).ForMember(dest=>dest.IsActive,x=>x.MapFrom(x=>true)).ForMember(dest=>dest.IsDeleted,x=>x.MapFrom(x=>false));
18+
CreateMap<CommentWithUserAddDto, CommentWithUser>().ForMember(dest=>dest.CreatedDate,x=>x.MapFrom(x=>DateTime.Now)).ForMember(dest=>dest.ModifiedDate,x=>x.MapFrom(x=>DateTime.Now)).ForMember(dest=>dest.IsActive,x=>x.MapFrom(x=>true)).ForMember(dest=>dest.IsDeleted,x=>x.MapFrom(x=>false));
1819
CreateMap<CommentWithUserUpdateDto, CommentWithUser>().ForMember(dest=>dest.ModifiedDate,x=>x.MapFrom(x=>DateTime.Now));
1920

2021
}

‎src/v2/CmnSoftwareBackend.Services/Concrete/ArticleManager.cs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,17 @@ public async Task<IDataResult> GetArticleByUserId(Guid userId)
115115
return new DataResult(ResultStatus.Success, query);
116116
}
117117

118-
public async Task<IDataResult> GetByIdAsync(int articleId, bool includeArticlePicture)
118+
public async Task<IDataResult> GetByIdAsync(int articleId, bool includeArticlePicture,boolincludeCommentWithUserId,boolincludeCommentWithoutUserId)
119119
{
120120
IQueryable<Article> query = DbContext.Set<Article>();
121121
var article = await query.AsNoTracking().SingleOrDefaultAsync(a => a.Id == articleId);
122122
if (article == null)
123123
throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir makale bulunamadı", "Id"));
124124
if (includeArticlePicture) query = query.AsNoTracking().Include(a => a.ArticlePictures);
125+
if (includeCommentWithoutUserId) query = query.AsNoTracking().Include(a => a.CommentWithoutUsers);
126+
if (includeCommentWithUserId) query = query.AsNoTracking().Include(a => a.CommentWithUsers);
125127

126-
return new DataResult(ResultStatus.Success, article);
128+
return new DataResult(ResultStatus.Success, query);
127129
}
128130

129131
public async Task<IResult> HardDeleteAsync(int articleId)

‎src/v2/CmnSoftwareBackend.Services/Concrete/CategoryManager.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task<IDataResult> AddAsync(CategoryAddDto categoryAddDto)
8181
await DbContext.AddAsync(category);
8282
await DbContext.SaveChangesAsync();
8383
return new DataResult(ResultStatus.Success, $"{category.Name} adlı kategori başarıyla eklendi",
84-
categoryAddDto);
84+
category);
8585
}
8686

8787
public async Task<IDataResult> UpdateAsync(CategoryUpdateDto categoryUpdateDto)

‎src/v2/CmnSoftwareBackend.Services/Concrete/CommentWithUserManager.cs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,15 @@ public async Task<IDataResult> GetAllAsync(bool? isActive, bool? isDeleted, bool
8989
});
9090
}
9191

92-
public async Task<IDataResult> GetByIdAsync(int commentWithUserId, bool includeArticle)
92+
public async Task<IDataResult> GetByIdAsync(int commentWithUserId, bool includeArticle,boolincludeUser)
9393
{
9494
IQueryable<CommentWithUser> query = DbContext.Set<CommentWithUser>();
9595
var comment =await query.AsNoTracking().SingleOrDefaultAsync(a => a.Id == commentWithUserId);
9696
if (comment == null)
9797
throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir yorum bulunamadı", "Id"));
9898
if (includeArticle) query = query.AsNoTracking().Include(a => a.Article);
99-
return new DataResult(ResultStatus.Success,comment);
99+
if (includeUser) query = query.AsNoTracking().Include(a => a.User);
100+
return new DataResult(ResultStatus.Success,query);
100101
}
101102
//test
102103
public async Task<IDataResult> GetAllCommentByUserId(Guid userId, bool includeArticle)
@@ -107,8 +108,8 @@ public async Task<IDataResult> GetAllCommentByUserId(Guid userId, bool includeAr
107108
throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("böyle bir kullanıcı bulunamadı", "userId"));
108109
if (includeArticle) query = query.AsNoTracking().Include(a => a.Article);
109110

110-
var comment = query.AsNoTracking().Where(a => a.UserId == userId);
111-
return new DataResult(ResultStatus.Success, comment);
111+
var comment = query.AsNoTracking().Include(a=>a.User).Where(a => a.UserId == userId);
112+
return new DataResult(ResultStatus.Success, query);
112113
}
113114

114115
public async Task<IResult> HardDeleteAsync(int commentWithUserId)

‎src/v2/CmnSoftwareBackend.Services/Concrete/CommentWithoutUserManager.cs‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ public async Task<IDataResult> AddAsync(CommentWithoutUserAddDto commentWithoutU
3737

3838
public async Task<IDataResult> DeleteAsync(int commentWithoutUserId)
3939
{
40-
var comment = await DbContext.CommentWithoutUsers.Include(a => a.Article).AsNoTracking().SingleOrDefaultAsync(cwu => cwu.Id == commentWithoutUserId);
41-
if (comment == null && comment.Article == null)
42-
throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir comment bulunamadı", "Id"));
40+
var comment = await DbContext.CommentWithoutUsers.Include(a => a.Article).SingleOrDefaultAsync(cwu => cwu.Id == commentWithoutUserId);
41+
if (comment == null)
42+
throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir yorum bulunamadı", "Id"));
43+
if (comment.Article == null)
44+
throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Bu yoruma ait bir makale bulunamadı", "Id"));
4345

4446
comment.IsActive = false;
4547
comment.IsDeleted = true;
@@ -53,14 +55,14 @@ public async Task<IDataResult> GetAllAsync(bool? isActive, bool? isDeleted, bool
5355
IQueryable<CommentWithoutUser> query = DbContext.Set<CommentWithoutUser>();
5456
if (isActive.HasValue) query = query.Where(a => a.IsActive == isActive);
5557
if (isDeleted.HasValue) query = query.Where(a => a.IsDeleted == isDeleted);
56-
if (includeArticle) query = query.AsNoTracking().Include(a=>a.Article);
58+
if (includeArticle) query = query.AsNoTracking().Include(a=>a.Article);
5759

58-
var commentCount =await query.AsNoTracking().CountAsync();
60+
var commentCount =await query.AsNoTracking().CountAsync();
5961
pageSize = pageSize > 100 ? 100 : pageSize;
6062
switch (orderBy)
6163
{
6264
case OrderBy.Id:
63-
query = isAscending ? query.OrderBy(a => a.Id) : query.OrderByDescending(a => a.Id);
65+
query = isAscending ? query.OrderBy(a => a.Id) : query.OrderByDescending(a => a.Id);
6466
break;
6567
case OrderBy.Az:
6668
query = isAscending ? query.OrderBy(a => a.UserName) : query.OrderByDescending(a => a.UserName);
@@ -69,14 +71,14 @@ public async Task<IDataResult> GetAllAsync(bool? isActive, bool? isDeleted, bool
6971
query = isAscending ? query.OrderBy(a => a.CreatedDate) : query.OrderByDescending(a => a.CreatedDate);
7072
break;
7173
}
72-
return new DataResult(ResultStatus.Success,new CommentWithoutUserListDto
74+
return new DataResult(ResultStatus.Success,new CommentWithoutUserListDto
7375
{
7476
// ArticlePictures = await query.Skip((currentPage - 1) * pageSize).Take(pageSize).Select(ap => Mapper.Map<ArticlePictureDto>(ap)).ToListAsync(),
75-
CommentWithoutUsers =await query.Skip((currentPage-1)*pageSize).Take(pageSize).Select(a=>Mapper.Map<CommentWithoutUser>(a)).ToListAsync(),
76-
CurrentPage=currentPage,
77-
TotalCount=commentCount,
78-
PageSize=pageSize,
79-
IsAscending=isAscending
77+
CommentWithoutUsers =await query.Skip((currentPage-1)*pageSize).Take(pageSize).Select(a=>Mapper.Map<CommentWithoutUser>(a)).ToListAsync(),
78+
CurrentPage=currentPage,
79+
TotalCount=commentCount,
80+
PageSize=pageSize,
81+
IsAscending=isAscending
8082
});
8183
}
8284

@@ -88,7 +90,7 @@ public async Task<IDataResult> GetByIdAsync(int commentWithoutUserId, bool inclu
8890
throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir yorum bulunamadı", "Id"));
8991
if (includeArticle) query = query.AsNoTracking().Include(a => a.Article);
9092

91-
return new DataResult(ResultStatus.Success, comment);
93+
return new DataResult(ResultStatus.Success, query);
9294
}
9395

9496
public async Task<IResult> HardDeleteAsync(int commentWithoutUserId)
@@ -104,16 +106,19 @@ public async Task<IResult> HardDeleteAsync(int commentWithoutUserId)
104106

105107
public async Task<IDataResult> UpdateAsync(CommentWithoutUserUpdateDto commentWithoutUserUpdateDto)
106108
{
107-
var article = await DbContext.Articles.SingleOrDefaultAsync(cwu => cwu.Id == commentWithoutUserUpdateDto.ArticleId);
109+
var article = await DbContext.Articles.AsNoTracking().SingleOrDefaultAsync(cwu => cwu.Id == commentWithoutUserUpdateDto.ArticleId);
110+
var oldComment= await DbContext.CommentWithoutUsers.SingleOrDefaultAsync(a => a.Id == commentWithoutUserUpdateDto.Id);
108111
if (article == null)
109112
throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir makale bulunamadı", "ArticleId"));
110113
if (article.Id != commentWithoutUserUpdateDto.ArticleId)
111114
throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Bu yorum bu makaleye ait değil", "ArticleId"));
115+
if (commentWithoutUserUpdateDto.UserName != oldComment.UserName)
116+
throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Bu yorum bu kullanıcıya ait değil", "UserName"));
112117

113-
var newComment = Mapper.Map<CommentWithoutUserUpdateDto, CommentWithoutUser>(commentWithoutUserUpdateDto);
118+
var newComment = Mapper.Map<CommentWithoutUserUpdateDto, CommentWithoutUser>(commentWithoutUserUpdateDto,oldComment);
114119
DbContext.CommentWithoutUsers.Update(newComment);
115120
await DbContext.SaveChangesAsync();
116-
return new DataResult(ResultStatus.Success, commentWithoutUserUpdateDto);
121+
return new DataResult(ResultStatus.Success, newComment);
117122

118123
}
119124
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /