Skip to content

Commit b433d86

Browse files
committed
Automapper and Change tracking changes
1 parent dd9704d commit b433d86

File tree

7 files changed

+17
-20
lines changed

7 files changed

+17
-20
lines changed

src/BlazorEcommerce.Application/Features/ProductType/Command/UpdateProductType/UpdateProductTypeCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public DeleteProductTypeCommandHandler(ICommandUnitOfWork<int> command, IMapper
1919

2020
public async Task<IResponse> Handle(UpdateProductTypeCommandRequest request, CancellationToken cancellationToken)
2121
{
22-
var productType = await _query.ProductTypeQuery.GetByIdAsync(p => p.Id == request.productType.Id);
22+
var productType = await _query.ProductTypeQuery.GetAsync(p => p.Id == request.productType.Id);
2323
if (productType == null)
2424
{
2525
return new DataResponse<string?>(null, HttpStatusCodes.NotFound, String.Format(Messages.NotFound, "Product Type"), false);

src/BlazorEcommerce.Application/MappingProfıles/CategoryProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public class CategoryProfile : Profile
66
{
77
public CategoryProfile()
88
{
9-
CreateMap<Category, CategoryDto>();
9+
CreateMap<Category, CategoryDto>().ReverseMap();
1010
}
1111
}

src/BlazorEcommerce.Application/MappingProfıles/OrderProfile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class OrderProfile : Profile
66
{
77
public OrderProfile()
88
{
9-
CreateMap<Order, OrderDto>();
10-
CreateMap<OrderItem, OrderItemDto>();
9+
CreateMap<Order, OrderDto>().ReverseMap();
10+
CreateMap<OrderItem, OrderItemDto>().ReverseMap();
1111
}
1212
}

src/BlazorEcommerce.Application/MappingProfıles/ProductProfile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class ProductProfile : Profile
66
{
77
public ProductProfile()
88
{
9-
CreateMap<Product, ProductDto>();
10-
CreateMap<ProductVariant, ProductVariantDto>();
9+
CreateMap<Product, ProductDto>().ReverseMap();
10+
CreateMap<ProductVariant, ProductVariantDto>().ReverseMap();
1111
}
1212
}

src/BlazorEcommerce.Application/MappingProfıles/ProductTypeProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public class ProductTypeProfile : Profile
44
{
55
public ProductTypeProfile()
66
{
7-
CreateMap<ProductType, ProductTypeDto>();
7+
CreateMap<ProductType, ProductTypeDto>().ReverseMap();
88
}
99
}

src/BlazorEcommerce.Persistence/Repositories/Commands/Base/CommandRepository.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using BlazorEcommerce.Application.Repositories.Commands.Base;
22
using BlazorEcommerce.Domain.Common;
3-
using BlazorEcommerce.Server.Contexts;
4-
using Microsoft.EntityFrameworkCore;
53

64
namespace BlazorEcommerce.Persistence.Repositories.Commands.Base;
75

@@ -38,7 +36,6 @@ public void RemoveRange(IEnumerable<T> entities)
3836
public T Update(T entity)
3937
{
4038
context.Set<T>().Update(entity);
41-
context.Entry(entity).State = EntityState.Modified;
4239
return entity;
4340
}
4441
}

src/BlazorEcommerce.Persistence/Repositories/Queries/Base/QueryRepository.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ public async Task<IQueryable<T>> GetAllAsync(bool isChangeTracking = false, bool
3131
IQueryable<T> query = context.Set<T>();
3232
if (ignoreQueryFilters)
3333
{
34-
if (isChangeTracking)
34+
if (!isChangeTracking)
3535
{
3636
return query = query.IgnoreQueryFilters().AsNoTracking().AsQueryable();
3737
}
3838
return await Task.Run(() => query.IgnoreQueryFilters().AsQueryable());
3939
}
4040
else
4141
{
42-
if (isChangeTracking)
42+
if (!isChangeTracking)
4343
{
4444
return query = query.AsNoTracking().AsQueryable();
4545
}
@@ -53,7 +53,7 @@ public async Task<IEnumerable<T>> GetAllWithIncludeAsync(bool isChangeTracking =
5353

5454
if (ignoreQueryFilters)
5555
{
56-
if (isChangeTracking)
56+
if (!isChangeTracking)
5757
{
5858
query = predicate is null ? query.IgnoreQueryFilters().AsNoTracking()
5959
: query.IgnoreQueryFilters().Where(predicate).AsNoTracking();
@@ -80,7 +80,7 @@ public async Task<IEnumerable<T>> GetAllWithIncludeAsync(bool isChangeTracking =
8080
}
8181
else
8282
{
83-
if (isChangeTracking)
83+
if (!isChangeTracking)
8484
{
8585
query = predicate is null ? query.AsNoTracking()
8686
: query.Where(predicate).AsNoTracking();
@@ -114,7 +114,7 @@ public async Task<T> GetAsync(Expression<Func<T, bool>> predicate, bool isChange
114114
IQueryable<T> query = context.Set<T>();
115115
if (ignoreQueryFilters)
116116
{
117-
if (isChangeTracking)
117+
if (!isChangeTracking)
118118
{
119119
query = query.IgnoreQueryFilters().Where(predicate).AsNoTracking();
120120
}
@@ -125,7 +125,7 @@ public async Task<T> GetAsync(Expression<Func<T, bool>> predicate, bool isChange
125125
}
126126
else
127127
{
128-
if (isChangeTracking)
128+
if (!isChangeTracking)
129129
{
130130
query = query.Where(predicate).AsNoTracking();
131131
}
@@ -143,7 +143,7 @@ public async Task<T> GetByIdAsync(Expression<Func<T, bool>> predicate, bool isCh
143143
IQueryable<T> query = context.Set<T>();
144144
if (ignoreQueryFilters)
145145
{
146-
if (isChangeTracking)
146+
if (!isChangeTracking)
147147
{
148148
query = query.IgnoreQueryFilters().Where(predicate).AsNoTracking();
149149
}
@@ -154,7 +154,7 @@ public async Task<T> GetByIdAsync(Expression<Func<T, bool>> predicate, bool isCh
154154
}
155155
else
156156
{
157-
if (isChangeTracking)
157+
if (!isChangeTracking)
158158
{
159159
query = query.Where(predicate).AsNoTracking();
160160
}
@@ -172,7 +172,7 @@ public async Task<T> GetWithIncludeAsync(bool isChangeTracking, Expression<Func<
172172
IQueryable<T> query = context.Set<T>();
173173
if (ignoreQueryFilters)
174174
{
175-
if (isChangeTracking)
175+
if (!isChangeTracking)
176176
{
177177
query = query.IgnoreQueryFilters().Where(predicate);
178178
if (includes is not null)
@@ -197,7 +197,7 @@ public async Task<T> GetWithIncludeAsync(bool isChangeTracking, Expression<Func<
197197
}
198198
else
199199
{
200-
if (isChangeTracking)
200+
if (!isChangeTracking)
201201
{
202202
query = query.Where(predicate);
203203
if (includes is not null)

0 commit comments

Comments
 (0)