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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
using AutoMapper;
using Gestor.Infrastructure.Entities.Ferramentas;
using Gestor.Infrastructure.Entities.Generic;
using Gestor.Infrastructure.Mappers;
using Gestor.Infrastructure.Repository.Generic;
using Gestor.Infrastructure.Repository.Interface;
using Gestor.Infrastructure.UnitOfWork.Generic;
using Gestor.Model.Domain.Ferramentas;
using Gestor.Model.Domain.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
namespace Gestor.Infrastructure.Repository.Logic
{
public class AgendaTelefoneRepository : GenericRepository<AgendaTelefoneDb>, IAgendaTelefoneRepository, IGenericRepository<AgendaTelefoneDb>
{
private readonly GenericUnitOfWork _unitOfWork;
public AgendaTelefoneRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
{
this._unitOfWork = unitOfWork;
}
public void Delete(long id)
{
base.Delete(base.FindEntityById(id));
}
public void DeleteRange(long id)
{
IQueryable<AgendaTelefoneDb> agendaTelefoneDbs =
from x in base.All()
where x.Agenda.Id == id
select x;
if (!agendaTelefoneDbs.Any<AgendaTelefoneDb>())
{
return;
}
base.DeleteRange(agendaTelefoneDbs);
}
public List<AgendaTelefone> Find(string telefone)
{
List<AgendaTelefoneDb> list = (
from x in base.All()
where x.Numero.Contains(telefone)
select x).ToList<AgendaTelefoneDb>();
return ApplicationMapper.Mapper.Map<List<AgendaTelefoneDb>, List<AgendaTelefone>>(list);
}
private List<AgendaTelefone> FindByAgenda(long id)
{
return (
from x in base.All()
where x.Agenda.Id == id
select new AgendaTelefone()
{
Id = x.Id,
Agenda = ApplicationMapper.Mapper.Map<AgendaDb, Agenda>(x.Agenda),
Prefixo = x.Prefixo,
Numero = x.Numero,
Tipo = x.Tipo,
Observacao = x.Observacao
}).ToList<AgendaTelefone>();
}
public List<AgendaTelefone> FindByAgendaId(long id)
{
return this.FindByAgenda(id);
}
public AgendaTelefone FindById(long id)
{
AgendaTelefoneDb agendaTelefoneDb = base.FindEntityById(id);
return ApplicationMapper.Mapper.Map<AgendaTelefoneDb, AgendaTelefone>(agendaTelefoneDb);
}
public List<AgendaTelefone> Inserir(List<AgendaTelefone> telefones)
{
List<AgendaTelefoneDb> agendaTelefoneDbs = ApplicationMapper.Mapper.Map<List<AgendaTelefone>, List<AgendaTelefoneDb>>(telefones);
agendaTelefoneDbs.ForEach((AgendaTelefoneDb x) => {
if (x.Id == 0)
{
this.SaveOrUpdate(x);
return;
}
base.Merge(x);
});
return ApplicationMapper.Mapper.Map<List<AgendaTelefoneDb>, List<AgendaTelefone>>(agendaTelefoneDbs);
}
public List<AgendaTelefone> Inserir(List<AgendaTelefone> telefones, Agenda agenda)
{
telefones.ForEach((AgendaTelefone x) => x.Agenda = agenda);
List<AgendaTelefoneDb> agendaTelefoneDbs = ApplicationMapper.Mapper.Map<List<AgendaTelefone>, List<AgendaTelefoneDb>>(telefones);
base.AddRange(agendaTelefoneDbs);
return ApplicationMapper.Mapper.Map<List<AgendaTelefoneDb>, List<AgendaTelefone>>(agendaTelefoneDbs);
}
public AgendaTelefone Merge(AgendaTelefone telefone)
{
AgendaTelefoneDb agendaTelefoneDb = ApplicationMapper.Mapper.Map<AgendaTelefone, AgendaTelefoneDb>(telefone);
base.Merge(agendaTelefoneDb);
return ApplicationMapper.Mapper.Map<AgendaTelefoneDb, AgendaTelefone>(agendaTelefoneDb);
}
public List<AgendaTelefone> Merge(List<AgendaTelefone> telefones, Agenda agenda)
{
IQueryable<AgendaTelefoneDb> agendaTelefoneDbs =
from x in base.All()
where x.Agenda.Id == agenda.Id
select x;
AgendaTelefoneRepository agendaTelefoneRepository = this;
(
from x in agendaTelefoneDbs
select x.Id).ToList<long>().Where<long>((long x) => {
List<AgendaTelefone> agendaTelefones = telefones;
Func<AgendaTelefone, long> u003cu003e9_114 = AgendaTelefoneRepository.u003cu003ec.u003cu003e9__11_4;
if (u003cu003e9_114 == null)
{
u003cu003e9_114 = (AgendaTelefone t) => t.Id;
AgendaTelefoneRepository.u003cu003ec.u003cu003e9__11_4 = u003cu003e9_114;
}
return !agendaTelefones.Select<AgendaTelefone, long>(u003cu003e9_114).Contains<long>(x);
}).ToList<long>().ForEach(new Action<long>(agendaTelefoneRepository.Delete));
List<AgendaTelefoneDb> agendaTelefoneDbs1 = ApplicationMapper.Mapper.Map<List<AgendaTelefone>, List<AgendaTelefoneDb>>(telefones);
agendaTelefoneDbs1.ForEach((AgendaTelefoneDb x) => {
if (x.Id != 0)
{
base.Merge(x);
return;
}
x.Agenda = ApplicationMapper.Mapper.Map<Agenda, AgendaDb>(agenda);
this.SaveOrUpdate(x);
});
return ApplicationMapper.Mapper.Map<List<AgendaTelefoneDb>, List<AgendaTelefone>>(agendaTelefoneDbs1);
}
public AgendaTelefone SaveOrUpdate(AgendaTelefone telefone)
{
AgendaTelefoneDb agendaTelefoneDb = ApplicationMapper.Mapper.Map<AgendaTelefone, AgendaTelefoneDb>(telefone);
this.SaveOrUpdate(agendaTelefoneDb);
return ApplicationMapper.Mapper.Map<AgendaTelefoneDb, AgendaTelefone>(agendaTelefoneDb);
}
}
}
|