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
|
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.Domain.Generic;
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 SeguradoraEnderecoRepository : GenericRepository<SeguradoraEnderecoDb>, ISeguradoraEnderecoRepository, IGenericRepository<SeguradoraEnderecoDb>
{
private readonly GenericUnitOfWork _unitOfWork;
public SeguradoraEnderecoRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
{
this._unitOfWork = unitOfWork;
}
public void Delete(long id)
{
SeguradoraEnderecoDb seguradoraEnderecoDb = base.FindEntityById(id);
if (seguradoraEnderecoDb == null)
{
return;
}
base.Delete(seguradoraEnderecoDb);
}
public SeguradoraEndereco FindById(long id)
{
SeguradoraEnderecoDb seguradoraEnderecoDb = base.FindEntityById(id);
return ApplicationMapper.Mapper.Map<SeguradoraEnderecoDb, SeguradoraEndereco>(seguradoraEnderecoDb);
}
public List<SeguradoraEndereco> FindBySeguradora(long empresa, long id)
{
List<SeguradoraEnderecoDb> list = (
from x in base.All()
where x.Empresa.Id == empresa && x.Seguradora.Id == id
select x).ToList<SeguradoraEnderecoDb>();
return ApplicationMapper.Mapper.Map<List<SeguradoraEnderecoDb>, List<SeguradoraEndereco>>(list);
}
public SeguradoraEndereco Merge(SeguradoraEndereco endereco)
{
SeguradoraEnderecoDb seguradoraEnderecoDb = ApplicationMapper.Mapper.Map<SeguradoraEndereco, SeguradoraEnderecoDb>(endereco);
base.Merge(seguradoraEnderecoDb);
return ApplicationMapper.Mapper.Map<SeguradoraEnderecoDb, SeguradoraEndereco>(seguradoraEnderecoDb);
}
public List<SeguradoraEndereco> Merge(List<SeguradoraEndereco> enderecos, Seguradora seguradora, long empresa)
{
IQueryable<SeguradoraEnderecoDb> seguradoraEnderecoDbs =
from x in base.All()
where x.Seguradora.Id == seguradora.Id && x.Empresa.Id == empresa
select x;
SeguradoraEnderecoRepository seguradoraEnderecoRepository = this;
(
from x in seguradoraEnderecoDbs
select x.Id).ToList<long>().Where<long>((long x) => {
List<SeguradoraEndereco> seguradoraEnderecos = enderecos;
Func<SeguradoraEndereco, long> u003cu003e9_64 = SeguradoraEnderecoRepository.u003cu003ec.u003cu003e9__6_4;
if (u003cu003e9_64 == null)
{
u003cu003e9_64 = (SeguradoraEndereco t) => t.Id;
SeguradoraEnderecoRepository.u003cu003ec.u003cu003e9__6_4 = u003cu003e9_64;
}
return !seguradoraEnderecos.Select<SeguradoraEndereco, long>(u003cu003e9_64).Contains<long>(x);
}).ToList<long>().ForEach(new Action<long>(seguradoraEnderecoRepository.Delete));
List<SeguradoraEnderecoDb> seguradoraEnderecoDbs1 = ApplicationMapper.Mapper.Map<List<SeguradoraEndereco>, List<SeguradoraEnderecoDb>>(enderecos);
seguradoraEnderecoDbs1.ForEach((SeguradoraEnderecoDb x) => {
if (x.Id == 0)
{
this.SaveOrUpdate(x);
return;
}
base.Merge(x);
});
return ApplicationMapper.Mapper.Map<List<SeguradoraEnderecoDb>, List<SeguradoraEndereco>>(seguradoraEnderecoDbs1);
}
public SeguradoraEndereco SaveOrUpdate(SeguradoraEndereco endereco)
{
SeguradoraEnderecoDb seguradoraEnderecoDb = ApplicationMapper.Mapper.Map<SeguradoraEndereco, SeguradoraEnderecoDb>(endereco);
this.SaveOrUpdate(seguradoraEnderecoDb);
return ApplicationMapper.Mapper.Map<SeguradoraEnderecoDb, SeguradoraEndereco>(seguradoraEnderecoDb);
}
}
}
|