Skip to content

Commit

Permalink
fix: edit produto
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunobento1990 committed Mar 15, 2024
1 parent a809f6f commit 790ad5d
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 0 deletions.
14 changes: 14 additions & 0 deletions OpenAdm.Api/Controllers/ItemTabelaDePrecoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ public async Task<IActionResult> CreateItemTabelaDePreco(CreateItensTabelaDePrec
}
}

[HttpPost("create-list")]
public async Task<IActionResult> CreateListItemTabelaDePreco(IList<CreateItensTabelaDePrecoDto> createItensTabelaDePrecoDto)
{
try
{
await _itemTabelaDePrecoService.CreateListItemTabelaDePrecoAsync(createItensTabelaDePrecoDto);
return Ok();
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}

[HttpDelete("delete")]
public async Task<IActionResult> DeleteItem([FromQuery] Guid id)
{
Expand Down
14 changes: 14 additions & 0 deletions OpenAdm.Api/Controllers/TabelaDePrecoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ public async Task<IActionResult> TabelaViewModel([FromQuery] Guid id)
}
}

[HttpGet("get-tabela-by-produtoId")]
public async Task<IActionResult> TabelaViewModelByProdutoId([FromQuery] Guid produtoId)
{
try
{
var tabelaDePrecoViewModel = await _tabelaDePrecoService.GetTabelaViewModelByProdutoIdAsync(produtoId);
return Ok(tabelaDePrecoViewModel);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}

[HttpGet("list")]
public async Task<IActionResult> TabelasViewModel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace OpenAdm.Application.Interfaces;
public interface IItemTabelaDePrecoService
{
Task CreateItemTabelaDePrecoAsync(CreateItensTabelaDePrecoDto createItensTabelaDePrecoDto);
Task CreateListItemTabelaDePrecoAsync(IList<CreateItensTabelaDePrecoDto> createItensTabelaDePrecoDto);
Task DeleteItemAsync(Guid id);
}
1 change: 1 addition & 0 deletions OpenAdm.Application/Interfaces/ITabelaDePrecoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface ITabelaDePrecoService
{
Task<PaginacaoViewModel<TabelaDePrecoViewModel>> GetPaginacaoTabelaViewModelAsync(PaginacaoTabelaDePrecoDto paginacaoTabelaDePrecoDto);
Task<TabelaDePrecoViewModel> GetPrecoTabelaViewModelAsync(Guid id);
Task<TabelaDePrecoViewModel> GetTabelaViewModelByProdutoIdAsync(Guid produtoId);
Task<TabelaDePrecoViewModel> UpdateTabelaDePrecoAsync(UpdateTabelaDePrecoDto updateTabelaDePrecoDto);
Task<TabelaDePrecoViewModel> CreateTabelaDePrecoAsync(CreateTabelaDePrecoDto createTabelaDePrecoDto);
Task DeleteTabelaDePrecoAsync(Guid id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public TabelaDePrecoViewModel ToModel(TabelaDePreco tabelaDePreco)
Descricao = tabelaDePreco.Descricao;
AtivaEcommerce = tabelaDePreco.AtivaEcommerce;

if(tabelaDePreco.ItensTabelaDePreco != null && tabelaDePreco.ItensTabelaDePreco.Count > 0)
{
ItensTabelaDePreco = tabelaDePreco.ItensTabelaDePreco.Select(x => new ItensTabelaDePrecoViewModel().ToModel(x, new List<Peso>(), new List<Tamanho>())).ToList();
}

return this;
}
}
11 changes: 11 additions & 0 deletions OpenAdm.Application/Services/ItemTabelaDePrecoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ public async Task CreateItemTabelaDePrecoAsync(CreateItensTabelaDePrecoDto creat
await _itemTabelaDePrecoRepository.AddAsync(itemTabelaDePreco);
}

public async Task CreateListItemTabelaDePrecoAsync(IList<CreateItensTabelaDePrecoDto> createItensTabelaDePrecoDto)
{
if (createItensTabelaDePrecoDto.Count == 0) return;

var itensTabelaDePreco = createItensTabelaDePrecoDto.Select(x => x.ToEntity()).ToList();

await _itemTabelaDePrecoRepository.DeleteItensTabelaDePrecoByProdutoIdAsync(createItensTabelaDePrecoDto.First().ProdutoId);

await _itemTabelaDePrecoRepository.AddRangeAsync(itensTabelaDePreco);
}

public async Task DeleteItemAsync(Guid id)
{
var item = await _itemTabelaDePrecoRepository.GetItemTabelaDePrecoByIdAsync(id)
Expand Down
9 changes: 9 additions & 0 deletions OpenAdm.Application/Services/TabelaDePrecoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ public async Task<TabelaDePrecoViewModel> GetPrecoTabelaViewModelAsync(Guid id)
return tabelaDePrecoViewModel;
}

public async Task<TabelaDePrecoViewModel> GetTabelaViewModelByProdutoIdAsync(Guid produtoId)
{
var tabelaDePreco = await _tabelaDePrecoRepository.GetTabelaDePrecoAtivaByProdutoIdAsync(produtoId);

if (tabelaDePreco == null) return new TabelaDePrecoViewModel();

return new TabelaDePrecoViewModel().ToModel(tabelaDePreco);
}

public async Task<TabelaDePrecoViewModel> UpdateTabelaDePrecoAsync(UpdateTabelaDePrecoDto updateTabelaDePrecoDto)
{
var tabelaDePreco = await _tabelaDePrecoRepository.GetTabelaDePrecoByIdUpdateAsync(updateTabelaDePrecoDto.Id)
Expand Down
1 change: 1 addition & 0 deletions OpenAdm.Domain/Interfaces/IItemTabelaDePrecoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public interface IItemTabelaDePrecoRepository : IGenericRepository<ItensTabelaDe
Task<ItensTabelaDePreco?> GetItemTabelaDePrecoByIdAsync(Guid id);
Task<IList<ItensTabelaDePreco>> GetItensTabelaDePrecoByIdProdutosAsync(IList<Guid> produtosIds);
Task AddRangeAsync(IList<ItensTabelaDePreco> itensTabelaDePrecos);
Task DeleteItensTabelaDePrecoByProdutoIdAsync(Guid produtoId);
}
1 change: 1 addition & 0 deletions OpenAdm.Domain/Interfaces/ITabelaDePrecoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace OpenAdm.Domain.Interfaces;
public interface ITabelaDePrecoRepository : IGenericRepository<TabelaDePreco>
{
Task<TabelaDePreco?> GetTabelaDePrecoAtivaAsync();
Task<TabelaDePreco?> GetTabelaDePrecoAtivaByProdutoIdAsync(Guid produtoId);
Task<TabelaDePreco?> GetTabelaDePrecoByIdAsync(Guid id);
Task<TabelaDePreco?> GetTabelaDePrecoByIdUpdateAsync(Guid id);
Task<PaginacaoViewModel<TabelaDePreco>> GetPaginacaoAsync(FilterModel<TabelaDePreco> filterModel);
Expand Down
5 changes: 5 additions & 0 deletions OpenAdm.Infra/Cached/Cached/ItemTabelaDePrecoCached.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public async Task<bool> DeleteAsync(ItensTabelaDePreco entity)
return await _itemTabelaDePrecoRepository.DeleteAsync(entity);
}

public async Task DeleteItensTabelaDePrecoByProdutoIdAsync(Guid produtoId)
{
await _itemTabelaDePrecoRepository.DeleteItensTabelaDePrecoByProdutoIdAsync(produtoId);
}

public async Task<ItensTabelaDePreco?> GetItemTabelaDePrecoByIdAsync(Guid id)
{
var key = id.ToString();
Expand Down
12 changes: 12 additions & 0 deletions OpenAdm.Infra/Repositories/ItemTabelaDePrecoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public async Task AddRangeAsync(IList<ItensTabelaDePreco> itensTabelaDePrecos)
await _parceiroContext.SaveChangesAsync();
}

public async Task DeleteItensTabelaDePrecoByProdutoIdAsync(Guid produtoId)
{
var itensTabelaDePreco = await _parceiroContext
.ItensTabelaDePreco
.Where(x => x.ProdutoId == produtoId)
.ToListAsync();

_parceiroContext.RemoveRange(itensTabelaDePreco);

await _parceiroContext.SaveChangesAsync();
}

public async Task<ItensTabelaDePreco?> GetItemTabelaDePrecoByIdAsync(Guid id)
{
return await _parceiroContext
Expand Down
1 change: 1 addition & 0 deletions OpenAdm.Infra/Repositories/PesoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public async Task<IList<Peso>> GetPesosAsync()
return await _parceiroContext
.Pesos
.AsNoTracking()
.OrderByDescending(x => x.Numero)
.ToListAsync();
}

Expand Down
18 changes: 18 additions & 0 deletions OpenAdm.Infra/Repositories/TabelaDePrecoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ public async Task<PaginacaoViewModel<TabelaDePreco>> GetPaginacaoAsync(FilterMod
.FirstOrDefaultAsync(x => x.AtivaEcommerce);
}

public async Task<TabelaDePreco?> GetTabelaDePrecoAtivaByProdutoIdAsync(Guid produtoId)
{
var tabelaDePreco = await _parceiroContext
.TabelaDePreco
.AsNoTracking()
.FirstOrDefaultAsync(x => x.AtivaEcommerce);

if(tabelaDePreco != null)
{
tabelaDePreco.ItensTabelaDePreco = await _parceiroContext
.ItensTabelaDePreco
.Where(x => x.ProdutoId == produtoId)
.ToListAsync();
}

return tabelaDePreco;
}

public async Task<TabelaDePreco?> GetTabelaDePrecoByIdAsync(Guid id)
{
var tabelaDePreco = await _parceiroContext
Expand Down
1 change: 1 addition & 0 deletions OpenAdm.Infra/Repositories/TamanhoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public async Task<IList<Tamanho>> GetTamanhosAsync()
return await _parceiroContext
.Tamanhos
.AsNoTracking()
.OrderByDescending(x => x.Numero)
.ToListAsync();
}

Expand Down

0 comments on commit 790ad5d

Please sign in to comment.