summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/DetalheExtratoRepository.cs
blob: 54af1745dd313ab5ee2836bbb04dc80efef74a00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using AutoMapper;
using Gestor.Infrastructure.Entities.Generic;
using Gestor.Infrastructure.Entities.Seguros;
using Gestor.Infrastructure.Mappers;
using Gestor.Infrastructure.Repository.Generic;
using Gestor.Infrastructure.Repository.Interface;
using Gestor.Infrastructure.UnitOfWork.Generic;
using Gestor.Model.Common;
using Gestor.Model.Domain.Seguros;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;

namespace Gestor.Infrastructure.Repository.Logic
{
	public class DetalheExtratoRepository : GenericRepository<DetalheExtratoDb>, IDetalheExtratoRepository, IGenericRepository<DetalheExtratoDb>
	{
		private readonly GenericUnitOfWork _unitOfWork;

		public DetalheExtratoRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
		{
			this._unitOfWork = unitOfWork;
		}

		public bool Completo(long id)
		{
			List<StatusParcela> statusParcelas = new List<StatusParcela>()
			{
				StatusParcela.BaixadaCritica,
				StatusParcela.Baixada,
				StatusParcela.BaixadaDiferencaPercentual,
				StatusParcela.BaixadaAnteriormente,
				StatusParcela.BaixadaManualmente,
				StatusParcela.DesconsideradaUsuario,
				StatusParcela.DesconsideradaSistema
			};
			return (
				from x in base.All()
				where x.Extrato.Id == id
				select x).All<DetalheExtratoDb>((DetalheExtratoDb x) => statusParcelas.Contains(x.Status.Value));
		}

		public void Delete(long id)
		{
			DetalheExtratoDb detalheExtratoDb = base.FindEntityById(id);
			if (detalheExtratoDb == null)
			{
				return;
			}
			base.Delete(detalheExtratoDb);
		}

		public List<DetalheExtrato> Find(long id)
		{
			List<DetalheExtratoDb> list = (
				from x in base.All()
				where x.Extrato.Id == id
				select x).ToList<DetalheExtratoDb>();
			return ApplicationMapper.Mapper.Map<List<DetalheExtratoDb>, List<DetalheExtrato>>(list);
		}

		public DetalheExtrato FindById(long id)
		{
			DetalheExtratoDb detalheExtratoDb = base.FindEntityById(id);
			return ApplicationMapper.Mapper.Map<DetalheExtratoDb, DetalheExtrato>(detalheExtratoDb);
		}

		public List<DetalheExtrato> FindByLongId(long? id)
		{
			List<DetalheExtratoDb> list = (
				from x in base.All()
				where (long?)x.Extrato.Id == id
				select x).ToList<DetalheExtratoDb>();
			return ApplicationMapper.Mapper.Map<List<DetalheExtratoDb>, List<DetalheExtrato>>(list);
		}

		public DetalheExtrato FindByParcelaId(long id)
		{
			DetalheExtratoDb detalheExtratoDb = base.All().FirstOrDefault<DetalheExtratoDb>((DetalheExtratoDb x) => x.Parcela == (long?)id);
			return ApplicationMapper.Mapper.Map<DetalheExtratoDb, DetalheExtrato>(detalheExtratoDb);
		}

		public DetalheExtrato Merge(DetalheExtrato parcela)
		{
			DetalheExtratoDb detalheExtratoDb = ApplicationMapper.Mapper.Map<DetalheExtrato, DetalheExtratoDb>(parcela);
			base.Merge(detalheExtratoDb);
			return ApplicationMapper.Mapper.Map<DetalheExtratoDb, DetalheExtrato>(detalheExtratoDb);
		}

		public DetalheExtrato SaveOrUpdate(DetalheExtrato parcela)
		{
			DetalheExtratoDb detalheExtratoDb = ApplicationMapper.Mapper.Map<DetalheExtrato, DetalheExtratoDb>(parcela);
			this.SaveOrUpdate(detalheExtratoDb);
			return ApplicationMapper.Mapper.Map<DetalheExtratoDb, DetalheExtrato>(detalheExtratoDb);
		}
	}
}