Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Application.Exceptions;
using Application.Interfaces.Repositories;
using Application.Wrappers;
using AutoMapper;
using Domain.Entities;
using MediatR;
using System;
using System.Collections.Generic;
Expand All @@ -19,9 +21,11 @@ public class UpdateProductCommand : IRequest<Response<int>>
public class UpdateProductCommandHandler : IRequestHandler<UpdateProductCommand, Response<int>>
{
private readonly IProductRepositoryAsync _productRepository;
public UpdateProductCommandHandler(IProductRepositoryAsync productRepository)
private readonly IMapper _mapper;
public UpdateProductCommandHandler(IProductRepositoryAsync productRepository, IMapper mapper)
{
_productRepository = productRepository;
_mapper = mapper;
}
public async Task<Response<int>> Handle(UpdateProductCommand command, CancellationToken cancellationToken)
{
Expand All @@ -33,9 +37,11 @@ public async Task<Response<int>> Handle(UpdateProductCommand command, Cancellati
}
else
{
product.Name = command.Name;
product.Rate = command.Rate;
product.Description = command.Description;
//product.Name = command.Name;
//product.Rate = command.Rate;
//product.Description = command.Description;

product = _mapper.Map<Product>(command);
await _productRepository.UpdateAsync(product);
return new Response<int>(product.Id);
}
Expand Down
2 changes: 2 additions & 0 deletions Application/Mappings/GeneralProfile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Application.Features.Products.Commands.CreateProduct;
using Application.Features.Products.Commands.UpdateProduct;
using Application.Features.Products.Queries.GetAllProducts;
using AutoMapper;
using Domain.Entities;
Expand All @@ -15,6 +16,7 @@ public GeneralProfile()
CreateMap<Product, GetAllProductsViewModel>().ReverseMap();
CreateMap<CreateProductCommand, Product>();
CreateMap<GetAllProductsQuery, GetAllProductsParameter>();
CreateMap<UpdateProductCommand, Product>();
}
}
}