summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaEmailRepository.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaEmailRepository.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaEmailRepository.cs')
-rw-r--r--Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaEmailRepository.cs151
1 files changed, 151 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaEmailRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaEmailRepository.cs
new file mode 100644
index 0000000..9131660
--- /dev/null
+++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaEmailRepository.cs
@@ -0,0 +1,151 @@
+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 AgendaEmailRepository : GenericRepository<AgendaEmailDb>, IAgendaEmailRepository, IGenericRepository<AgendaEmailDb>
+ {
+ private readonly GenericUnitOfWork _unitOfWork;
+
+ public AgendaEmailRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
+ {
+ this._unitOfWork = unitOfWork;
+ }
+
+ public void Delete(long id)
+ {
+ base.Delete(base.FindEntityById(id));
+ }
+
+ public void DeleteRange(long id)
+ {
+ IQueryable<AgendaEmailDb> agendaEmailDbs =
+ from x in base.All()
+ where x.Agenda.Id == id
+ select x;
+ if (!agendaEmailDbs.Any<AgendaEmailDb>())
+ {
+ return;
+ }
+ base.DeleteRange(agendaEmailDbs);
+ }
+
+ private List<AgendaEmail> FindByAgenda(long id)
+ {
+ List<AgendaEmailDb> list = (
+ from x in base.All()
+ where x.Agenda.Id == id
+ select x).ToList<AgendaEmailDb>();
+ return ApplicationMapper.Mapper.Map<List<AgendaEmailDb>, List<AgendaEmail>>(list);
+ }
+
+ public List<AgendaEmail> FindByAgenda(List<long> ids)
+ {
+ List<AgendaEmailDb> list = (
+ from x in base.All()
+ where ids.Contains(x.Agenda.Id)
+ select x).ToList<AgendaEmailDb>();
+ return ApplicationMapper.Mapper.Map<List<AgendaEmailDb>, List<AgendaEmail>>(list);
+ }
+
+ public List<AgendaEmail> FindByAgendaId(long id)
+ {
+ return this.FindByAgenda(id);
+ }
+
+ public AgendaEmail FindById(long id)
+ {
+ AgendaEmailDb agendaEmailDb = base.FindEntityById(id);
+ return ApplicationMapper.Mapper.Map<AgendaEmailDb, AgendaEmail>(agendaEmailDb);
+ }
+
+ public List<AgendaEmail> FindEmailAgenda(string email)
+ {
+ List<AgendaEmailDb> list = (
+ from x in base.All()
+ where x.Email.Contains(email)
+ select x).ToList<AgendaEmailDb>();
+ return ApplicationMapper.Mapper.Map<List<AgendaEmailDb>, List<AgendaEmail>>(list);
+ }
+
+ public List<AgendaEmail> Inserir(List<AgendaEmail> emails, Agenda agenda)
+ {
+ emails.ForEach((AgendaEmail x) => x.Agenda = agenda);
+ List<AgendaEmailDb> agendaEmailDbs = ApplicationMapper.Mapper.Map<List<AgendaEmail>, List<AgendaEmailDb>>(emails);
+ base.AddRange(agendaEmailDbs);
+ return ApplicationMapper.Mapper.Map<List<AgendaEmailDb>, List<AgendaEmail>>(agendaEmailDbs);
+ }
+
+ public List<AgendaEmail> Inserir(List<AgendaEmail> emails)
+ {
+ List<AgendaEmailDb> agendaEmailDbs = ApplicationMapper.Mapper.Map<List<AgendaEmail>, List<AgendaEmailDb>>(emails);
+ agendaEmailDbs.ForEach((AgendaEmailDb x) => {
+ if (x.Id == 0)
+ {
+ this.SaveOrUpdate(x);
+ return;
+ }
+ base.Merge(x);
+ });
+ return ApplicationMapper.Mapper.Map<List<AgendaEmailDb>, List<AgendaEmail>>(agendaEmailDbs);
+ }
+
+ public AgendaEmail Merge(AgendaEmail agendaEmail)
+ {
+ AgendaEmailDb agendaEmailDb = ApplicationMapper.Mapper.Map<AgendaEmail, AgendaEmailDb>(agendaEmail);
+ base.Merge(agendaEmailDb);
+ return ApplicationMapper.Mapper.Map<AgendaEmailDb, AgendaEmail>(agendaEmailDb);
+ }
+
+ public List<AgendaEmail> Merge(List<AgendaEmail> emails, Agenda agenda)
+ {
+ IQueryable<AgendaEmailDb> agendaEmailDbs =
+ from x in base.All()
+ where x.Agenda.Id == agenda.Id
+ select x;
+ AgendaEmailRepository agendaEmailRepository = this;
+ (
+ from x in agendaEmailDbs
+ select x.Id).ToList<long>().Where<long>((long x) => {
+ List<AgendaEmail> agendaEmails = emails;
+ Func<AgendaEmail, long> u003cu003e9_114 = AgendaEmailRepository.u003cu003ec.u003cu003e9__11_4;
+ if (u003cu003e9_114 == null)
+ {
+ u003cu003e9_114 = (AgendaEmail t) => t.Id;
+ AgendaEmailRepository.u003cu003ec.u003cu003e9__11_4 = u003cu003e9_114;
+ }
+ return !agendaEmails.Select<AgendaEmail, long>(u003cu003e9_114).Contains<long>(x);
+ }).ToList<long>().ForEach(new Action<long>(agendaEmailRepository.Delete));
+ List<AgendaEmailDb> agendaEmailDbs1 = ApplicationMapper.Mapper.Map<List<AgendaEmail>, List<AgendaEmailDb>>(emails);
+ agendaEmailDbs1.ForEach((AgendaEmailDb 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<AgendaEmailDb>, List<AgendaEmail>>(agendaEmailDbs1);
+ }
+
+ public AgendaEmail SaveOrUpdate(AgendaEmail agendaEmail)
+ {
+ AgendaEmailDb agendaEmailDb = ApplicationMapper.Mapper.Map<AgendaEmail, AgendaEmailDb>(agendaEmail);
+ this.SaveOrUpdate(agendaEmailDb);
+ return ApplicationMapper.Mapper.Map<AgendaEmailDb, AgendaEmail>(agendaEmailDb);
+ }
+ }
+} \ No newline at end of file