Skip to content

Commit

Permalink
Automapper and Change tracking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-atharva committed May 2, 2023
1 parent dd9704d commit b433d86
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public DeleteProductTypeCommandHandler(ICommandUnitOfWork<int> command, IMapper

public async Task<IResponse> Handle(UpdateProductTypeCommandRequest request, CancellationToken cancellationToken)
{
var productType = await _query.ProductTypeQuery.GetByIdAsync(p => p.Id == request.productType.Id);
var productType = await _query.ProductTypeQuery.GetAsync(p => p.Id == request.productType.Id);
if (productType == null)
{
return new DataResponse<string?>(null, HttpStatusCodes.NotFound, String.Format(Messages.NotFound, "Product Type"), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public class CategoryProfile : Profile
{
public CategoryProfile()
{
CreateMap<Category, CategoryDto>();
CreateMap<Category, CategoryDto>().ReverseMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class OrderProfile : Profile
{
public OrderProfile()
{
CreateMap<Order, OrderDto>();
CreateMap<OrderItem, OrderItemDto>();
CreateMap<Order, OrderDto>().ReverseMap();
CreateMap<OrderItem, OrderItemDto>().ReverseMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class ProductProfile : Profile
{
public ProductProfile()
{
CreateMap<Product, ProductDto>();
CreateMap<ProductVariant, ProductVariantDto>();
CreateMap<Product, ProductDto>().ReverseMap();
CreateMap<ProductVariant, ProductVariantDto>().ReverseMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class ProductTypeProfile : Profile
{
public ProductTypeProfile()
{
CreateMap<ProductType, ProductTypeDto>();
CreateMap<ProductType, ProductTypeDto>().ReverseMap();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using BlazorEcommerce.Application.Repositories.Commands.Base;
using BlazorEcommerce.Domain.Common;
using BlazorEcommerce.Server.Contexts;
using Microsoft.EntityFrameworkCore;

namespace BlazorEcommerce.Persistence.Repositories.Commands.Base;

Expand Down Expand Up @@ -38,7 +36,6 @@ public void RemoveRange(IEnumerable<T> entities)
public T Update(T entity)
{
context.Set<T>().Update(entity);
context.Entry(entity).State = EntityState.Modified;
return entity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public async Task<IQueryable<T>> GetAllAsync(bool isChangeTracking = false, bool
IQueryable<T> query = context.Set<T>();
if (ignoreQueryFilters)
{
if (isChangeTracking)
if (!isChangeTracking)
{
return query = query.IgnoreQueryFilters().AsNoTracking().AsQueryable();
}
return await Task.Run(() => query.IgnoreQueryFilters().AsQueryable());
}
else
{
if (isChangeTracking)
if (!isChangeTracking)
{
return query = query.AsNoTracking().AsQueryable();
}
Expand All @@ -53,7 +53,7 @@ public async Task<IEnumerable<T>> GetAllWithIncludeAsync(bool isChangeTracking =

if (ignoreQueryFilters)
{
if (isChangeTracking)
if (!isChangeTracking)
{
query = predicate is null ? query.IgnoreQueryFilters().AsNoTracking()
: query.IgnoreQueryFilters().Where(predicate).AsNoTracking();
Expand All @@ -80,7 +80,7 @@ public async Task<IEnumerable<T>> GetAllWithIncludeAsync(bool isChangeTracking =
}
else
{
if (isChangeTracking)
if (!isChangeTracking)
{
query = predicate is null ? query.AsNoTracking()
: query.Where(predicate).AsNoTracking();
Expand Down Expand Up @@ -114,7 +114,7 @@ public async Task<T> GetAsync(Expression<Func<T, bool>> predicate, bool isChange
IQueryable<T> query = context.Set<T>();
if (ignoreQueryFilters)
{
if (isChangeTracking)
if (!isChangeTracking)
{
query = query.IgnoreQueryFilters().Where(predicate).AsNoTracking();
}
Expand All @@ -125,7 +125,7 @@ public async Task<T> GetAsync(Expression<Func<T, bool>> predicate, bool isChange
}
else
{
if (isChangeTracking)
if (!isChangeTracking)
{
query = query.Where(predicate).AsNoTracking();
}
Expand All @@ -143,7 +143,7 @@ public async Task<T> GetByIdAsync(Expression<Func<T, bool>> predicate, bool isCh
IQueryable<T> query = context.Set<T>();
if (ignoreQueryFilters)
{
if (isChangeTracking)
if (!isChangeTracking)
{
query = query.IgnoreQueryFilters().Where(predicate).AsNoTracking();
}
Expand All @@ -154,7 +154,7 @@ public async Task<T> GetByIdAsync(Expression<Func<T, bool>> predicate, bool isCh
}
else
{
if (isChangeTracking)
if (!isChangeTracking)
{
query = query.Where(predicate).AsNoTracking();
}
Expand All @@ -172,7 +172,7 @@ public async Task<T> GetWithIncludeAsync(bool isChangeTracking, Expression<Func<
IQueryable<T> query = context.Set<T>();
if (ignoreQueryFilters)
{
if (isChangeTracking)
if (!isChangeTracking)
{
query = query.IgnoreQueryFilters().Where(predicate);
if (includes is not null)
Expand All @@ -197,7 +197,7 @@ public async Task<T> GetWithIncludeAsync(bool isChangeTracking, Expression<Func<
}
else
{
if (isChangeTracking)
if (!isChangeTracking)
{
query = query.Where(predicate);
if (includes is not null)
Expand Down

0 comments on commit b433d86

Please sign in to comment.