summaryrefslogtreecommitdiff
path: root/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/SocioRepository.cs
blob: 0bacb702b5ca1d91ac1dd76709463fba299f3a19 (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
using AutoMapper;
using Gestor.Infrastructure.Entities.Common;
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.Common;
using NHibernate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;

namespace Gestor.Infrastructure.Repository.Logic
{
	public class SocioRepository : GenericRepository<SocioDb>, ISocioRepository, IGenericRepository<SocioDb>
	{
		private readonly GenericUnitOfWork _unitOfWork;

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

		public void Delete(long id)
		{
			base.Delete(base.FindEntityById(id));
		}

		public List<Socio> Find()
		{
			return (
				from x in base.All()
				select new Socio()
				{
					Id = x.Id,
					Nome = x.Nome,
					Email = x.Email,
					Prefixo = x.Prefixo,
					Telefone = x.Telefone
				}).ToList<Socio>();
		}

		public List<Socio> FindByEmpresa(long id)
		{
			List<SocioDb> list = (
				from x in this._unitOfWork.Session.CreateQuery("FROM SocioDb WHERE (excluido IS NULL OR excluido != '1')").List<SocioDb>()
				where x.IdEmpresa == id
				select x).ToList<SocioDb>();
			return ApplicationMapper.Mapper.Map<List<SocioDb>, List<Socio>>(list);
		}

		public Socio FindById(long id)
		{
			SocioDb socioDb = base.FindEntityById(id);
			return ApplicationMapper.Mapper.Map<SocioDb, Socio>(socioDb);
		}

		public Socio Merge(Socio socio)
		{
			SocioDb socioDb = ApplicationMapper.Mapper.Map<Socio, SocioDb>(socio);
			base.Merge(socioDb);
			return ApplicationMapper.Mapper.Map<SocioDb, Socio>(socioDb);
		}

		public Socio SaveOrUpdate(Socio socio)
		{
			SocioDb socioDb = ApplicationMapper.Mapper.Map<Socio, SocioDb>(socio);
			this.SaveOrUpdate(socioDb);
			return ApplicationMapper.Mapper.Map<SocioDb, Socio>(socioDb);
		}
	}
}