| | 1 | | using Domain.Core.ValueObject; |
| | 2 | | using Domain.Entities; |
| | 3 | | using Microsoft.EntityFrameworkCore; |
| | 4 | | using Repository.Persistency.Abstractions; |
| | 5 | | using System.Collections.Immutable; |
| | 6 | | using System.Data; |
| | 7 | |
|
| | 8 | | namespace Repository.Persistency.Implementations; |
| | 9 | | public class LancamentoRepositorioImpl : ILancamentoRepositorio |
| | 10 | | { |
| 6 | 11 | | public RegisterContext Context { get; } |
| 5 | 12 | | public LancamentoRepositorioImpl(RegisterContext context) |
| 5 | 13 | | { |
| 5 | 14 | | Context = context; |
| 5 | 15 | | } |
| | 16 | |
|
| | 17 | | public async Task<ICollection<Lancamento>> FindByMesAno(DateTime data, Guid idUsuario) |
| 3 | 18 | | { |
| 3 | 19 | | int mes = data.Month; |
| 3 | 20 | | int ano = data.Year; |
| 3 | 21 | | var despesas = await Context.Despesa |
| 3 | 22 | | .Include(d => d.Categoria) |
| 3 | 23 | | .Include(tc => tc.Categoria.TipoCategoria) |
| 3 | 24 | | .Where(d => d.Data.Month == mes && d.Data.Year == ano && d.UsuarioId == idUsuario && d.Categoria.TipoCategor |
| 3 | 25 | | .Select(d => new Lancamento |
| 3 | 26 | | { |
| 3 | 27 | | Id = d.Id, |
| 3 | 28 | | Categoria = d.Categoria, |
| 3 | 29 | | CategoriaId = d.CategoriaId, |
| 3 | 30 | | DespesaId = d.Id, |
| 3 | 31 | | UsuarioId = d.UsuarioId, |
| 3 | 32 | | Data = d.Data, |
| 3 | 33 | | DataCriacao = DateTime.Now, |
| 3 | 34 | | Valor = d.Valor, |
| 3 | 35 | | Despesa = new Despesa { Id = d.Id, Descricao = d.Descricao }, |
| 3 | 36 | | Receita = null, |
| 3 | 37 | | ReceitaId = null |
| 3 | 38 | | }) |
| 3 | 39 | | .ToListAsync(); |
| | 40 | |
|
| 3 | 41 | | var receitas = await Context.Receita |
| 3 | 42 | | .Include(r => r.Categoria) |
| 3 | 43 | | .Include(tc => tc.Categoria.TipoCategoria) |
| 3 | 44 | | .Where(r => r.Data.Month == mes && r.Data.Year == ano && r.UsuarioId == idUsuario && r.Categoria.TipoCategor |
| 3 | 45 | | .Select(r => new Lancamento |
| 3 | 46 | | { |
| 3 | 47 | | Id = r.Id, |
| 3 | 48 | | Categoria = r.Categoria, |
| 3 | 49 | | CategoriaId = r.CategoriaId, |
| 3 | 50 | | ReceitaId = r.Id, |
| 3 | 51 | | UsuarioId = r.UsuarioId, |
| 3 | 52 | | Data = r.Data, |
| 3 | 53 | | DataCriacao = DateTime.Now, |
| 3 | 54 | | Valor = r.Valor, |
| 3 | 55 | | Despesa = null, |
| 3 | 56 | | Receita = new Receita { Id = r.Id, Descricao = r.Descricao }, |
| 3 | 57 | | DespesaId = null |
| 3 | 58 | | }) |
| 3 | 59 | | .ToListAsync(); |
| | 60 | |
|
| 21 | 61 | | var lancamentos = despesas.Concat(receitas).OrderBy(l => l.Data).ToImmutableArray(); |
| 1 | 62 | | return lancamentos; |
| 1 | 63 | | } |
| | 64 | | } |