summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.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/ItemRepository.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.cs')
-rw-r--r--Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.cs1450
1 files changed, 1450 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.cs
new file mode 100644
index 0000000..0d8590f
--- /dev/null
+++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ItemRepository.cs
@@ -0,0 +1,1450 @@
+using AutoMapper;
+using Gestor.Infrastructure.Entities.Generic;
+using Gestor.Infrastructure.Entities.Seguros;
+using Gestor.Infrastructure.Helpers;
+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.Common;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using NHibernate;
+using NHibernate.Connection;
+using NHibernate.Impl;
+using NHibernate.Util;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.Common;
+using System.Data.SqlClient;
+using System.Diagnostics;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+
+namespace Gestor.Infrastructure.Repository.Logic
+{
+ public class ItemRepository : GenericRepository<ItemDb>, IItemRepository, IGenericRepository<ItemDb>
+ {
+ private readonly GenericUnitOfWork _unitOfWork;
+
+ public ItemRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
+ {
+ this._unitOfWork = unitOfWork;
+ }
+
+ public async Task<List<PesquisaAvancada>> BuscaItensPorObs(string pesquisa, FiltroStatusDocumento status, List<VendedorUsuario> vendedorVinculado, TipoPesquisa tipo, bool tipobusca = false)
+ {
+ List<PesquisaAvancada> pesquisaAvancadas;
+ object connection;
+ object obj;
+ DateTime dateTime;
+ List<PesquisaAvancada> pesquisaAvancadas1 = new List<PesquisaAvancada>();
+ DateTime date = Funcoes.GetNetworkTime().Date;
+ List<Condicao> condicaos = new List<Condicao>();
+ Condicao condicao = new Condicao()
+ {
+ Campo = "d.excluido",
+ Valores = null,
+ Grupo = 1,
+ Operacao = Operacao.Or
+ };
+ condicaos.Add(condicao);
+ Condicao condicao1 = new Condicao()
+ {
+ Campo = "d.excluido",
+ Valores = "0".CriarValor<string>(),
+ Grupo = 1,
+ Operacao = Operacao.Or
+ };
+ condicaos.Add(condicao1);
+ List<Condicao> condicaos1 = condicaos;
+ if (vendedorVinculado.Count > 0)
+ {
+ Condicao condicao2 = new Condicao()
+ {
+ Campo = "vp.IdVendedor",
+ Valores = vendedorVinculado.CriarValor<VendedorUsuario>()
+ };
+ condicaos1.Add(condicao2);
+ }
+ switch (status)
+ {
+ case FiltroStatusDocumento.Vencidos:
+ {
+ List<Condicao> condicaos2 = new List<Condicao>();
+ Condicao condicao3 = new Condicao()
+ {
+ Campo = "d.situacao",
+ Valores = new List<object>()
+ {
+ 3,
+ 7
+ },
+ Operador = Operador.Diferente
+ };
+ condicaos2.Add(condicao3);
+ Condicao condicao4 = new Condicao()
+ {
+ Campo = "d.vigencia2",
+ Valores = date.AddDays(-5).CriarValor<DateTime>(),
+ Operador = Operador.Menor
+ };
+ condicaos2.Add(condicao4);
+ condicaos1.AddRange(condicaos2);
+ goto Label0;
+ }
+ case FiltroStatusDocumento.Cancelados:
+ {
+ Condicao condicao5 = new Condicao()
+ {
+ Campo = "d.situacao",
+ Valores = 3.CriarValor<int>()
+ };
+ condicaos1.Add(condicao5);
+ goto Label0;
+ }
+ case FiltroStatusDocumento.Recusados:
+ {
+ Condicao condicao6 = new Condicao()
+ {
+ Campo = "d.situacao",
+ Valores = 7.CriarValor<int>()
+ };
+ condicaos1.Add(condicao6);
+ goto Label0;
+ }
+ case FiltroStatusDocumento.Todos:
+ {
+ using (SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl)
+ {
+ SessionFactoryImpl sessionFactoryImpl = sessionFactory;
+ if (sessionFactoryImpl != null)
+ {
+ connection = sessionFactoryImpl.ConnectionProvider.GetConnection();
+ }
+ else
+ {
+ connection = null;
+ }
+ using (SqlConnection sqlConnection = connection as SqlConnection)
+ {
+ using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
+ {
+ List<Condicao> condicaos3 = condicaos1;
+ Condicao condicao7 = new Condicao()
+ {
+ Campo = "a.obs",
+ Valores = pesquisa.CriarValor<string>(),
+ Grupo = 3,
+ Operacao = Operacao.Or,
+ Operador = (tipobusca ? Operador.Igual : Operador.Like)
+ };
+ condicaos3.Add(condicao7);
+ List<Condicao> condicaos4 = condicaos1;
+ Condicao condicao8 = new Condicao()
+ {
+ Campo = "r.obs",
+ Valores = pesquisa.CriarValor<string>(),
+ Grupo = 3,
+ Operacao = Operacao.Or,
+ Operador = (tipobusca ? Operador.Igual : Operador.Like)
+ };
+ condicaos4.Add(condicao8);
+ List<Condicao> condicaos5 = condicaos1;
+ Condicao condicao9 = new Condicao()
+ {
+ Campo = "aero.obs",
+ Valores = pesquisa.CriarValor<string>(),
+ Grupo = 3,
+ Operacao = Operacao.Or,
+ Operador = (tipobusca ? Operador.Igual : Operador.Like)
+ };
+ condicaos5.Add(condicao9);
+ List<Condicao> condicaos6 = condicaos1;
+ Condicao condicao10 = new Condicao()
+ {
+ Campo = "g.obs",
+ Valores = pesquisa.CriarValor<string>(),
+ Grupo = 3,
+ Operacao = Operacao.Or,
+ Operador = (tipobusca ? Operador.Igual : Operador.Like)
+ };
+ condicaos6.Add(condicao10);
+ List<Condicao> condicaos7 = condicaos1;
+ Condicao condicao11 = new Condicao()
+ {
+ Campo = "v.obs",
+ Valores = pesquisa.CriarValor<string>(),
+ Grupo = 3,
+ Operacao = Operacao.Or,
+ Operador = (tipobusca ? Operador.Igual : Operador.Like)
+ };
+ condicaos7.Add(condicao11);
+ List<Condicao> condicaos8 = condicaos1;
+ Condicao condicao12 = new Condicao()
+ {
+ Campo = "rd.obs",
+ Valores = pesquisa.CriarValor<string>(),
+ Grupo = 3,
+ Operacao = Operacao.Or,
+ Operador = (tipobusca ? Operador.Igual : Operador.Like)
+ };
+ condicaos8.Add(condicao12);
+ List<Condicao> condicaos9 = condicaos1;
+ Condicao condicao13 = new Condicao()
+ {
+ Campo = "re.bens",
+ Valores = pesquisa.CriarValor<string>(),
+ Grupo = 3,
+ Operacao = Operacao.Or,
+ Operador = (tipobusca ? Operador.Igual : Operador.Like)
+ };
+ condicaos9.Add(condicao13);
+ SqlQueryCondition sqlQueryCondition = condicaos1.CreateParameters(0);
+ sqlCommand.CommandText = string.Concat("SELECT DISTINCT TOP 1000 c.IdControle,d.IdDocumento,d.Proposta,d.Contrato Apolice,d.Aditamento Endosso,d.Vigencia1 VigenciaInicial,c.IdCliente,d.Tipo Tipo,i.IdItem,i.Descricao,cli.Nome,vp.IdVendedor FROM documento d INNER JOIN controle c ON d.IdControle = c.idControle INNER JOIN cliente cli ON cli.IdCliente = c.IdCliente INNER JOIN item i ON d.IdDocumento = i.IdDocumento LEFT JOIN auto a ON i.IdItem = a.IdItem LEFT JOIN resempco r ON i.IdItem = r.IdItem LEFT JOIN aeronautico aero ON i.IdItem = aero.IdItem LEFT JOIN granizo g ON i.IdItem = g.IdItem LEFT JOIN vida v ON i.IdItem = v.IdItem LEFT JOIN riscosdiversos rd ON i.IdItem = rd.IdItem LEFT JOIN vendedorparcela vp ON d.IdDocumento = vp.IdDocumento LEFT JOIN resempco re ON i.IdItem = re.IdItem WHERE ", sqlQueryCondition.Condicao);
+ sqlCommand.Parameters.AddRange(sqlQueryCondition.Parametros.ToArray());
+ using (SqlDataReader sqlDataReader = await sqlCommand.ExecuteReaderAsync())
+ {
+ while (true)
+ {
+ if (!await sqlDataReader.ReadAsync())
+ {
+ break;
+ }
+ object[] fieldValue = new object[] { sqlDataReader.GetFieldValue<string>("Descricao", true, true), sqlDataReader.GetFieldValue<string>("Apolice", true, true), null, null, null };
+ obj = (sqlDataReader.GetFieldValue<int>("Tipo", true, true) == 0 ? "" : string.Concat(" - ENDOSSO: ", sqlDataReader.GetFieldValue<string>("Endosso", true, true)));
+ fieldValue[2] = obj;
+ fieldValue[3] = sqlDataReader.GetFieldValue<string>("Proposta", true, true);
+ DateTime? nullable = sqlDataReader.GetFieldValue<DateTime?>("VigenciaInicial", true, true);
+ dateTime = (nullable.HasValue ? nullable.GetValueOrDefault() : DateTime.Now);
+ fieldValue[4] = dateTime;
+ string str = string.Format("ITEM: {0} - APÓLICE: {1}{2} - PROPOSTA: {3} - VIGÊNCIA INICIAL: {4:d}", fieldValue);
+ PesquisaAvancada pesquisaAvancada = new PesquisaAvancada()
+ {
+ IdCliente = sqlDataReader.GetFieldValue<long>("IdCliente", true, true),
+ IdDocumento = sqlDataReader.GetFieldValue<long>("IdDocumento", true, true),
+ IdItem = sqlDataReader.GetFieldValue<long>("IdItem", true, true),
+ Nome = sqlDataReader.GetFieldValue<string>("Nome", true, true).ToUpper(),
+ Pesquisa = str.ToUpper()
+ };
+ pesquisaAvancadas1.Add(pesquisaAvancada);
+ }
+ }
+ sqlDataReader = null;
+ }
+ sqlCommand = null;
+ }
+ sqlConnection = null;
+ }
+ sessionFactory = null;
+ pesquisaAvancadas = pesquisaAvancadas1;
+ break;
+ }
+ default:
+ {
+ List<Condicao> condicaos10 = new List<Condicao>();
+ Condicao condicao14 = new Condicao()
+ {
+ Campo = "d.situacao"
+ };
+ List<object> objs = new List<object>()
+ {
+ 1,
+ 2,
+ 4
+ };
+ condicao14.Valores = objs;
+ condicaos10.Add(condicao14);
+ Condicao condicao15 = new Condicao()
+ {
+ Campo = "d.vigencia2",
+ Valores = null,
+ Grupo = 2,
+ Operacao = Operacao.Or
+ };
+ condicaos10.Add(condicao15);
+ Condicao condicao16 = new Condicao()
+ {
+ Campo = "d.vigencia2",
+ Valores = date.AddDays(-5).CriarValor<DateTime>(),
+ Grupo = 2,
+ Operacao = Operacao.Or,
+ Operador = Operador.Maior
+ };
+ condicaos10.Add(condicao16);
+ condicaos1.AddRange(condicaos10);
+ goto Label0;
+ }
+ }
+ pesquisaAvancadas1 = null;
+ return pesquisaAvancadas;
+ }
+
+ public Cliente BuscarCliente(long id)
+ {
+ return this.FindById(id).Documento.Controle.Cliente;
+ }
+
+ public int ChecarQuantidade(long idDocumento)
+ {
+ return base.All().Count<ItemDb>((ItemDb x) => x.Documento.Id == idDocumento);
+ }
+
+ public void Delete(long id)
+ {
+ ItemDb itemDb = base.FindEntityById(id);
+ if (itemDb == null)
+ {
+ return;
+ }
+ base.Delete(itemDb);
+ }
+
+ public void DeleteRange(List<long> ids)
+ {
+ List<ItemDb> list = (
+ from x in base.All()
+ where ids.Contains(x.Id)
+ select x).ToList<ItemDb>();
+ base.DeleteRange(list);
+ }
+
+ public List<Item> FindByDocumentsIds(long id, StatusItem status = 0, bool sinistroCompleto = false)
+ {
+ List<Condicao> condicaos;
+ DataTable dataTable1;
+ int length;
+ Item granizo;
+ long? nullable;
+ long? nullable1;
+ long? nullable2;
+ string str;
+ string str1;
+ string str2;
+ string str3;
+ string str4;
+ string str5;
+ string str6;
+ string str7;
+ object fabricante;
+ string str8;
+ string str9;
+ string str10;
+ string str11;
+ string str12;
+ string str13;
+ string str14;
+ string str15;
+ string str16;
+ int? nullable3;
+ TabelaReferencia tabelaReferencium;
+ string str17;
+ string str18;
+ Cor cor;
+ string str19;
+ string str20;
+ Action<DataRow> action = null;
+ List<Condicao> condicaos1 = new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "d.idcontrole",
+ Valores = id.CriarValor<long>()
+ }
+ };
+ switch (status)
+ {
+ case StatusItem.Ativos:
+ {
+ condicaos1.AddRange(new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "idsubstituido",
+ Valores = null
+ },
+ new Condicao()
+ {
+ Campo = "cancelado",
+ Valores = null,
+ Grupo = 1,
+ Operacao = Operacao.Or
+ },
+ new Condicao()
+ {
+ Campo = "cancelado",
+ Valores = "1".CriarValor<string>(),
+ Grupo = 1,
+ Operacao = Operacao.Or,
+ Operador = Operador.Diferente
+ }
+ });
+ break;
+ }
+ case StatusItem.Inativos:
+ {
+ condicaos1.AddRange(new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "idsubstituido",
+ Valores = null,
+ Grupo = 1,
+ Operacao = Operacao.Or,
+ Operador = Operador.Diferente
+ },
+ new Condicao()
+ {
+ Campo = "cancelado",
+ Valores = "1".CriarValor<string>(),
+ Grupo = 1
+ }
+ });
+ break;
+ }
+ case StatusItem.Documento:
+ {
+ condicaos1 = new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "d.iddocumento",
+ Valores = id.CriarValor<long>()
+ }
+ };
+ break;
+ }
+ }
+ DataTable dataTable2 = this._unitOfWork.Select(condicaos1.CreateParameters(0), "SELECT i.iditem, c.idramo, i.iddocumento, i.descricao, i.sinistrado, i.status, i.statusinc, i.idsubstituido, i.iddocumentocancelado, i.ordem FROM item i INNER JOIN documento d on d.iddocumento = i.iddocumento INNER JOIN controle c on c.idcontrole = d.idcontrole WHERE ", "ORDER BY i.ordem");
+ if (dataTable2.Rows.Count == 0)
+ {
+ return new List<Item>();
+ }
+ string str21 = dataTable2.AsEnumerable().First<DataRow>().Field<object>("idramo").ToString();
+ List<long> list = dataTable2.AsEnumerable().Select<DataRow, long>((DataRow x) => x.Field<long>("iditem")).ToList<long>();
+ DataTable dataTable3 = new DataTable();
+ DataTable dataTable4 = new DataTable();
+ DataTable dataTable5 = new DataTable();
+ DataTable dataTable6 = new DataTable();
+ DataTable dataTable7 = new DataTable();
+ DataTable dataTable8 = new DataTable();
+ DataTable dataTable9 = new DataTable();
+ DataTable dataTable10 = new DataTable();
+ DataTable dataTable11 = new DataTable();
+ DataTable dataTable12 = new DataTable();
+ while (list.Count > 0)
+ {
+ List<long> nums = list.Take<long>(1500).ToList<long>();
+ condicaos = new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "iditem",
+ Valores = nums.CriarValor<long>()
+ }
+ };
+ dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT idcobertura, iditem, observacao, franquia, premio, lmi FROM cobertura WHERE ", "");
+ dataTable12.Merge(dataTable1);
+ if (str21 != null)
+ {
+ length = str21.Length;
+ if (length == 1)
+ {
+ switch (str21[0])
+ {
+ case '1':
+ case '2':
+ case '3':
+ {
+ goto Label1;
+ }
+ case '4':
+ case '8':
+ {
+ break;
+ }
+ case '5':
+ {
+ dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT a.*, f.descricao AS fabricante FROM auto a LEFT OUTER JOIN fabricante f ON f.idfabricante = a.IDFABRICANTE WHERE ", "");
+ dataTable3.Merge(dataTable1);
+ goto Label0;
+ }
+ default:
+ {
+ goto Label0;
+ }
+ }
+ }
+ else if (length == 2)
+ {
+ switch (str21[1])
+ {
+ case '0':
+ {
+ if (str21 == "10")
+ {
+ goto Label0;
+ }
+ if (str21 == "20")
+ {
+ dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT iditem, obs FROM granizo WHERE ", "");
+ dataTable11.Merge(dataTable1);
+ goto Label0;
+ }
+ else
+ {
+ goto Label0;
+ }
+ }
+ case '1':
+ {
+ if (str21 == "31" || str21 == "41")
+ {
+ break;
+ }
+ goto Label0;
+ }
+ case '3':
+ {
+ if (str21 == "23" || str21 == "33")
+ {
+ break;
+ }
+ if (str21 == "13")
+ {
+ dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT iditem, obs FROM aeronautico WHERE ", "");
+ dataTable10.Merge(dataTable1);
+ goto Label0;
+ }
+ else
+ {
+ if (str21 == "53")
+ {
+ goto Label0;
+ }
+ goto Label0;
+ }
+ }
+ case '5':
+ {
+ if (str21 == "15")
+ {
+ goto Label1;
+ }
+ goto Label0;
+ }
+ case '6':
+ {
+ if (str21 == "16" || str21 == "26")
+ {
+ break;
+ }
+ goto Label0;
+ }
+ case '7':
+ {
+ if (str21 == "17")
+ {
+ break;
+ }
+ goto Label0;
+ }
+ case '8':
+ {
+ if (str21 == "18")
+ {
+ goto Label1;
+ }
+ if (str21 == "28")
+ {
+ break;
+ }
+ goto Label0;
+ }
+ case '9':
+ {
+ if (str21 == "19" || str21 == "39" || str21 == "59")
+ {
+ break;
+ }
+ goto Label0;
+ }
+ default:
+ {
+ goto Label0;
+ }
+ }
+ }
+ else
+ {
+ goto Label0;
+ }
+ dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT iditem, obs FROM riscosdiversos WHERE ", "");
+ dataTable9.Merge(dataTable1);
+ }
+ Label0:
+ dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT * FROM controlesinistro WHERE ", "");
+ dataTable5.Merge(dataTable1);
+ if (dataTable1.Rows.Count > 0)
+ {
+ List<Condicao> condicaos2 = new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "idcontrolesinistro",
+ Valores = dataTable5.AsEnumerable().Select<DataRow, long>((DataRow x) => x.Field<long>("idcontrolesinistro")).ToList<long>().CriarValor<long>()
+ }
+ };
+ dataTable1 = this._unitOfWork.Select(condicaos2.CreateParameters(0), "SELECT * FROM sinistro WHERE ", "");
+ dataTable6.Merge(dataTable1);
+ List<Condicao> condicaos3 = new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "idsinistro",
+ Valores = dataTable6.AsEnumerable().Select<DataRow, long>((DataRow x) => x.Field<long>("idsinistro")).ToList<long>().CriarValor<long>()
+ }
+ };
+ dataTable1 = this._unitOfWork.Select(condicaos3.CreateParameters(0), "SELECT * FROM sinistrovida WHERE ", "");
+ dataTable8.Merge(dataTable1);
+ dataTable1 = this._unitOfWork.Select(condicaos3.CreateParameters(0), "SELECT * FROM sinistroauto WHERE ", "");
+ dataTable7.Merge(dataTable1);
+ }
+ list = (nums.Count < 1500 ? new List<long>() : list.Except<long>(nums).ToList<long>());
+ }
+ List<Item> items = new List<Item>();
+ Label4:
+ foreach (DataRow row in dataTable2.Rows)
+ {
+ Item item = new Item()
+ {
+ Id = long.Parse(row["iditem"].ToString()),
+ Documento = new Documento()
+ {
+ Id = long.Parse(row["iddocumento"].ToString())
+ },
+ Sinistrado = row["sinistrado"].ToString() == "1",
+ Descricao = row["descricao"].ToString(),
+ Status = row["status"].ToString(),
+ Ordem = new int?(int.Parse(row["ordem"].ToString())),
+ StatusInclusao = row["statusinc"].ToString()
+ };
+ if (string.IsNullOrEmpty(row["iddocumentocancelado"].ToString()))
+ {
+ nullable = null;
+ nullable1 = nullable;
+ }
+ else
+ {
+ nullable1 = new long?(long.Parse(row["iddocumentocancelado"].ToString()));
+ }
+ item.IdDocumentoCancelado = nullable1;
+ if (string.IsNullOrEmpty(row["idsubstituido"].ToString()))
+ {
+ nullable = null;
+ nullable2 = nullable;
+ }
+ else
+ {
+ nullable2 = new long?(long.Parse(row["idsubstituido"].ToString()));
+ }
+ item.Substituido = nullable2;
+ item.Coberturas = (
+ from x in dataTable12.AsEnumerable().Where<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString())).ToList<DataRow>()
+ select new Cobertura()
+ {
+ Id = x.Field<long>("idcobertura"),
+ Observacao = x.Field<string>("observacao"),
+ Franquia = (x.Field<object>("franquia") == null ? decimal.Zero : x.Field<decimal>("franquia")),
+ Lmi = (x.Field<object>("lmi") == null ? decimal.Zero : x.Field<decimal>("lmi")),
+ Premio = (x.Field<object>("premio") == null ? decimal.Zero : x.Field<decimal>("premio"))
+ }).ToList<Cobertura>();
+ granizo = item;
+ string str22 = row["idramo"].ToString();
+ if (str22 != null)
+ {
+ length = str22.Length;
+ if (length == 1)
+ {
+ switch (str22[0])
+ {
+ case '1':
+ case '2':
+ case '3':
+ {
+ goto Label3;
+ }
+ case '4':
+ case '8':
+ {
+ break;
+ }
+ case '5':
+ {
+ if (dataTable3.AsEnumerable().Where<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString())).ToList<DataRow>().Count == 0)
+ {
+ continue;
+ }
+ DataRow dataRow4 = dataTable3.AsEnumerable().FirstOrDefault<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString()));
+ Item item1 = granizo;
+ Auto auto = new Auto();
+ if (dataRow4 != null)
+ {
+ str7 = dataRow4["IDFABRICANTE"].ToString();
+ }
+ else
+ {
+ str7 = null;
+ }
+ if (string.IsNullOrEmpty(str7))
+ {
+ fabricante = null;
+ }
+ else
+ {
+ fabricante = new Fabricante();
+ if (dataRow4 != null)
+ {
+ str19 = dataRow4["IDFABRICANTE"].ToString();
+ }
+ else
+ {
+ str19 = null;
+ }
+ ((Fabricante)fabricante).Id = int.Parse(str19);
+ if (dataRow4 != null)
+ {
+ str20 = dataRow4["fabricante"].ToString();
+ }
+ else
+ {
+ str20 = null;
+ }
+ ((Fabricante)fabricante).Descricao = str20;
+ }
+ auto.Fabricante = (Fabricante)fabricante;
+ if (dataRow4 != null)
+ {
+ str8 = dataRow4["modelo"].ToString();
+ }
+ else
+ {
+ str8 = null;
+ }
+ auto.Modelo = str8;
+ if (dataRow4 != null)
+ {
+ str9 = dataRow4["anofab"].ToString();
+ }
+ else
+ {
+ str9 = null;
+ }
+ auto.AnoFabricacao = str9;
+ if (dataRow4 != null)
+ {
+ str10 = dataRow4["anomod"].ToString();
+ }
+ else
+ {
+ str10 = null;
+ }
+ auto.AnoModelo = str10;
+ if (dataRow4 != null)
+ {
+ str11 = dataRow4["placa"].ToString();
+ }
+ else
+ {
+ str11 = null;
+ }
+ auto.Placa = str11;
+ if (dataRow4 != null)
+ {
+ str12 = dataRow4["chassi"].ToString();
+ }
+ else
+ {
+ str12 = null;
+ }
+ auto.Chassi = str12;
+ if (dataRow4 != null)
+ {
+ str13 = dataRow4["ci"].ToString();
+ }
+ else
+ {
+ str13 = null;
+ }
+ auto.Ci = str13;
+ if (dataRow4 != null)
+ {
+ str14 = dataRow4["renavam"].ToString();
+ }
+ else
+ {
+ str14 = null;
+ }
+ auto.Renavam = str14;
+ if (dataRow4 != null)
+ {
+ str15 = dataRow4["CEPpernoite"].ToString();
+ }
+ else
+ {
+ str15 = null;
+ }
+ auto.CepPernoite = str15;
+ if (dataRow4 != null)
+ {
+ str16 = dataRow4["financiado"].ToString();
+ }
+ else
+ {
+ str16 = null;
+ }
+ auto.Financiado = new bool?(str16 == "1");
+ auto.TipoCobertura = (!string.IsNullOrEmpty(dataRow4["idtipocobertura"].ToString()) ? new TipoCobertura?((TipoCobertura)int.Parse(dataRow4["idtipocobertura"].ToString())) : new TipoCobertura?(0));
+ if (string.IsNullOrEmpty(dataRow4["bonus"].ToString()))
+ {
+ nullable3 = null;
+ }
+ else
+ {
+ nullable3 = new int?(int.Parse(dataRow4["bonus"].ToString()));
+ }
+ auto.Bonus = nullable3;
+ auto.RegiaoCirculacao = dataRow4["regiaocirculacao"].ToString();
+ if (!string.IsNullOrEmpty(dataRow4["idtabelareferencia"].ToString()))
+ {
+ tabelaReferencium = (TabelaReferencia)int.Parse(dataRow4["idtabelareferencia"].ToString());
+ }
+ else
+ {
+ tabelaReferencium = TabelaReferencia.Molicar;
+ }
+ auto.TabelaReferencia = new TabelaReferencia?(tabelaReferencium);
+ auto.PorcentagemReferencia = (string.IsNullOrEmpty(dataRow4["porcentagemreferencia"].ToString()) ? decimal.Zero : decimal.Parse(dataRow4["porcentagemreferencia"].ToString()));
+ auto.Fipe = dataRow4["CODFIPE"].ToString();
+ if (dataRow4 != null)
+ {
+ str17 = dataRow4["idcor"].ToString();
+ }
+ else
+ {
+ str17 = null;
+ }
+ if (!string.IsNullOrEmpty(str17))
+ {
+ if (dataRow4 != null)
+ {
+ str18 = dataRow4["idcor"].ToString();
+ }
+ else
+ {
+ str18 = null;
+ }
+ cor = (Cor)int.Parse(str18);
+ }
+ else
+ {
+ cor = Cor.OutrosNull;
+ }
+ auto.Cor = new Cor?(cor);
+ item1.Auto = auto;
+ goto Label2;
+ }
+ default:
+ {
+ goto Label2;
+ }
+ }
+ }
+ else if (length == 2)
+ {
+ switch (str22[1])
+ {
+ case '0':
+ {
+ if (str22 == "10")
+ {
+ goto Label2;
+ }
+ if (str22 == "20")
+ {
+ if (dataTable11.AsEnumerable().Where<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString())).ToList<DataRow>().Count <= 0)
+ {
+ goto Label2;
+ }
+ granizo.Granizo = new Granizo()
+ {
+ Observacao = dataTable11.AsEnumerable().FirstOrDefault<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString()))["obs"].ToString()
+ };
+ goto Label2;
+ }
+ else
+ {
+ goto Label2;
+ }
+ }
+ case '1':
+ {
+ if (str22 == "31" || str22 == "41")
+ {
+ break;
+ }
+ goto Label2;
+ }
+ case '3':
+ {
+ if (str22 == "53")
+ {
+ goto Label2;
+ }
+ if (str22 == "23" || str22 == "33")
+ {
+ break;
+ }
+ if (str22 == "13")
+ {
+ if (dataTable10.AsEnumerable().Where<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString())).ToList<DataRow>().Count <= 0)
+ {
+ goto Label2;
+ }
+ granizo.Aeronautico = new Aeronautico()
+ {
+ Observacao = dataTable10.AsEnumerable().FirstOrDefault<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString()))["obs"].ToString()
+ };
+ goto Label2;
+ }
+ else
+ {
+ goto Label2;
+ }
+ }
+ case '5':
+ {
+ if (str22 == "15")
+ {
+ goto Label3;
+ }
+ goto Label2;
+ }
+ case '6':
+ {
+ if (str22 == "16" || str22 == "26")
+ {
+ break;
+ }
+ goto Label2;
+ }
+ case '7':
+ {
+ if (str22 == "17")
+ {
+ break;
+ }
+ goto Label2;
+ }
+ case '8':
+ {
+ if (str22 == "18")
+ {
+ goto Label3;
+ }
+ if (str22 == "28")
+ {
+ break;
+ }
+ goto Label2;
+ }
+ case '9':
+ {
+ if (str22 == "19" || str22 == "39" || str22 == "59")
+ {
+ break;
+ }
+ goto Label2;
+ }
+ default:
+ {
+ goto Label2;
+ }
+ }
+ }
+ else
+ {
+ goto Label2;
+ }
+ if (dataTable9.AsEnumerable().Where<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString())).ToList<DataRow>().Count > 0)
+ {
+ granizo.RiscosDiversos = new RiscosDiversos()
+ {
+ Observacao = dataTable9.AsEnumerable().FirstOrDefault<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString()))["obs"].ToString()
+ };
+ }
+ }
+ Label2:
+ List<Sinistro> sinistros = new List<Sinistro>();
+ granizo.Sinistros = new List<ControleSinistro>();
+ foreach (DataRow row1 in dataTable5.Rows)
+ {
+ if (row1["iditem"].ToString() != row["iditem"].ToString())
+ {
+ continue;
+ }
+ long num = long.Parse(row1["idcontrolesinistro"].ToString());
+ EnumerableRowCollection<DataRow> dataRows = dataTable6.AsEnumerable().Where<DataRow>((DataRow x) => x.Field<long>("idcontrolesinistro") == num);
+ Action<DataRow> action1 = action;
+ if (action1 == null)
+ {
+ Action<DataRow> action2 = (DataRow x) => {
+ DataRow dataRow;
+ DataRow dataRow1;
+ object sinistroVida;
+ object sinistroAuto;
+ DataTable cSu0024u003cu003e8_locals1 = dataTable8;
+ if (cSu0024u003cu003e8_locals1 != null)
+ {
+ dataRow = cSu0024u003cu003e8_locals1.AsEnumerable().FirstOrDefault<DataRow>((DataRow s) => s.Field<long>("idsinistro") == x.Field<long>("idsinistro"));
+ }
+ else
+ {
+ dataRow = null;
+ }
+ DataRow dataRow2 = dataRow;
+ DataTable dataTable = dataTable7;
+ if (dataTable != null)
+ {
+ dataRow1 = dataTable.AsEnumerable().FirstOrDefault<DataRow>((DataRow s) => s.Field<long>("idsinistro") == x.Field<long>("idsinistro"));
+ }
+ else
+ {
+ dataRow1 = null;
+ }
+ DataRow dataRow3 = dataRow1;
+ if (dataRow2 == null)
+ {
+ sinistroVida = null;
+ }
+ else
+ {
+ sinistroVida = new SinistroVida();
+ ((DomainBase)sinistroVida).Id = dataRow2.Field<long>("idsinistrovida");
+ ((SinistroVida)sinistroVida).Beneficiario = dataRow2.Field<string>("beneficiario");
+ }
+ SinistroVida sinistroVida1 = (SinistroVida)sinistroVida;
+ if (dataRow3 == null)
+ {
+ sinistroAuto = null;
+ }
+ else
+ {
+ sinistroAuto = new SinistroAuto();
+ ((DomainBase)sinistroAuto).Id = dataRow3.Field<long>("idsinistroauto");
+ }
+ SinistroAuto sinistroAuto1 = (SinistroAuto)sinistroAuto;
+ sinistros.Add(new Sinistro()
+ {
+ Id = x.Field<long>("idsinistro"),
+ Numero = x.Field<string>("numsinistro"),
+ DataReclamacao = x.Field<DateTime?>("datareclamacao"),
+ StatusSinistro = (x.Field<object>("idstatussinistro") != null ? new StatusSinistro?((StatusSinistro)int.Parse(x.Field<object>("idstatussinistro").ToString())) : null),
+ DataLiquidacao = x.Field<DateTime?>("dataliquidacao"),
+ ItemSinistrado = x.Field<string>("itemsinistrado"),
+ Motivo = x.Field<string>("motivo"),
+ Valor = x.Field<decimal?>("valor").GetValueOrDefault(),
+ SinistroVida = sinistroVida1,
+ SinistroAuto = sinistroAuto1
+ });
+ };
+ Action<DataRow> action3 = action2;
+ action = action2;
+ action1 = action3;
+ }
+ dataRows.ForEach<DataRow>(action1);
+ granizo.Sinistros.Add(new ControleSinistro()
+ {
+ Id = num,
+ DataSinistro = row1.Field<DateTime?>("datasinistro"),
+ Item = new Item()
+ {
+ Id = long.Parse(row["iditem"].ToString())
+ },
+ Sinistros = sinistros
+ });
+ }
+ items.Add(granizo);
+ }
+ return items;
+ Label1:
+ dataTable1 = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT * FROM resempco WHERE ", "");
+ dataTable4.Merge(dataTable1);
+ goto Label0;
+ Label3:
+ if (dataTable4.AsEnumerable().Where<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString())).ToList<DataRow>().Count == 0)
+ {
+ goto Label4;
+ }
+ DataRow dataRow5 = dataTable4.AsEnumerable().FirstOrDefault<DataRow>((DataRow x) => x.Field<long>("iditem") == long.Parse(this.i["iditem"].ToString()));
+ Item item2 = granizo;
+ Patrimonial patrimonial = new Patrimonial();
+ if (dataRow5 != null)
+ {
+ str = dataRow5["endereco"].ToString();
+ }
+ else
+ {
+ str = null;
+ }
+ patrimonial.Endereco = str;
+ if (dataRow5 != null)
+ {
+ str1 = dataRow5["numero"].ToString();
+ }
+ else
+ {
+ str1 = null;
+ }
+ patrimonial.Numero = str1;
+ if (dataRow5 != null)
+ {
+ str2 = dataRow5["complemento"].ToString();
+ }
+ else
+ {
+ str2 = null;
+ }
+ patrimonial.Complemento = str2;
+ if (dataRow5 != null)
+ {
+ str3 = dataRow5["bairro"].ToString();
+ }
+ else
+ {
+ str3 = null;
+ }
+ patrimonial.Bairro = str3;
+ if (dataRow5 != null)
+ {
+ str4 = dataRow5["cidade"].ToString();
+ }
+ else
+ {
+ str4 = null;
+ }
+ patrimonial.Cidade = str4;
+ if (dataRow5 != null)
+ {
+ str5 = dataRow5["uf"].ToString();
+ }
+ else
+ {
+ str5 = null;
+ }
+ patrimonial.Estado = str5;
+ if (dataRow5 != null)
+ {
+ str6 = dataRow5["cep"].ToString();
+ }
+ else
+ {
+ str6 = null;
+ }
+ patrimonial.Cep = str6;
+ item2.Patrimonial = patrimonial;
+ goto Label2;
+ }
+
+ public Item FindById(long id)
+ {
+ ItemDb itemDb = base.FindEntityById(id);
+ return ApplicationMapper.Mapper.Map<ItemDb, Item>(itemDb);
+ }
+
+ public List<Item> FindByIds(List<long> ids)
+ {
+ List<ItemDb> list = (
+ from x in base.All()
+ where ids.Contains(x.Id)
+ select x).ToList<ItemDb>();
+ return ApplicationMapper.Mapper.Map<List<ItemDb>, List<Item>>(list);
+ }
+
+ public List<Item> FindItens(List<long> ids)
+ {
+ List<ItemDb> list = (
+ from x in base.All()
+ where ids.Contains(x.Id)
+ select x).ToList<ItemDb>();
+ return ApplicationMapper.Mapper.Map<List<ItemDb>, List<Item>>(list);
+ }
+
+ public List<Item> FindItens(long id, StatusItem status)
+ {
+ List<Item> items;
+ object connection;
+ SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
+ string str = "";
+ switch (status)
+ {
+ case StatusItem.Ativos:
+ {
+ str = string.Format("AND d.idcontrole = {0} AND (cancelado IS NULL OR cancelado != '1') AND idsubstituido IS NULL", id);
+ break;
+ }
+ case StatusItem.Inativos:
+ {
+ str = string.Format("AND d.idcontrole = {0} AND (cancelado IS NOT NULL AND cancelado = '1' OR idsubstituido IS NOT NULL)", id);
+ break;
+ }
+ case StatusItem.Documento:
+ {
+ str = string.Format("AND d.iddocumento = {0}", id);
+ break;
+ }
+ case StatusItem.Controle:
+ {
+ str = string.Format("AND d.idcontrole = {0}", id);
+ break;
+ }
+ }
+ DataTable dataTable = new DataTable();
+ DataTable dataTable1 = new DataTable();
+ if (sessionFactory != null)
+ {
+ connection = sessionFactory.ConnectionProvider.GetConnection();
+ }
+ else
+ {
+ connection = null;
+ }
+ using (SqlConnection sqlConnection = connection as SqlConnection)
+ {
+ using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
+ {
+ sqlCommand.CommandText = string.Concat("SELECT i.* FROM item i INNER JOIN documento d on d.iddocumento = i.iddocumento WHERE 1=1 ", str);
+ using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
+ {
+ sqlDataAdapter.SelectCommand = sqlCommand;
+ sqlDataAdapter.Fill(dataTable);
+ }
+ if (dataTable.Rows.Count != 0)
+ {
+ string str1 = string.Concat(" AND iditem IN (", string.Join<long>(",", (
+ from x in dataTable.AsEnumerable().ToList<DataRow>()
+ select x.Field<long>("iditem")).ToList<long>()), ")");
+ sqlCommand.CommandText = string.Concat("SELECT iditem, idcontrolesinistro, datasinistro FROM controlesinistro WHERE 1=1 ", str1);
+ using (SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter())
+ {
+ sqlDataAdapter1.SelectCommand = sqlCommand;
+ sqlDataAdapter1.Fill(dataTable1);
+ return dataTable.AsEnumerable().ToList<DataRow>().Select<DataRow, Item>((DataRow x) => {
+ Item item = new Item()
+ {
+ Id = x.Field<long>("iditem"),
+ Descricao = x.Field<string>("descricao"),
+ Ordem = x.Field<int?>("ordem"),
+ Sinistrado = (x.Field<object>("sinistrado") == null ? false : x.Field<string>("sinistrado") == "1"),
+ Cancelado = (x.Field<object>("cancelado") == null ? false : x.Field<string>("cancelado") == "1"),
+ Substituicao = x.Field<long?>("idsubstituicao"),
+ Substituido = x.Field<long?>("idsubstituido"),
+ Status = x.Field<string>("status"),
+ StatusInclusao = x.Field<string>("statusinc")
+ };
+ IEnumerable<DataRow> list =
+ from s in dataTable1.AsEnumerable().ToList<DataRow>()
+ where s.Field<long>("iditem") == x.Field<long>("iditem")
+ select s;
+ Func<DataRow, ControleSinistro> u003cu003e9_104 = ItemRepository.u003cu003ec.u003cu003e9__10_4;
+ if (u003cu003e9_104 == null)
+ {
+ u003cu003e9_104 = (DataRow s) => {
+ ControleSinistro controleSinistro = new ControleSinistro()
+ {
+ Id = s.Field<long>("idcontrolesinistro")
+ };
+ DateTime? nullable = s.Field<DateTime?>("datasinistro");
+ controleSinistro.DataSinistro = new DateTime?((nullable.HasValue ? nullable.GetValueOrDefault() : DateTime.MinValue));
+ return controleSinistro;
+ };
+ ItemRepository.u003cu003ec.u003cu003e9__10_4 = u003cu003e9_104;
+ }
+ item.Sinistros = list.Select<DataRow, ControleSinistro>(u003cu003e9_104).ToList<ControleSinistro>();
+ return item;
+ }).OrderBy<Item, int?>((Item x) => x.Ordem).ToList<Item>();
+ }
+ }
+ else
+ {
+ items = new List<Item>();
+ }
+ }
+ }
+ return items;
+ }
+
+ public List<Item> FindItens(List<Documento> documento)
+ {
+ List<Item> items;
+ object connection;
+ SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
+ DataTable dataTable = new DataTable();
+ if (sessionFactory != null)
+ {
+ connection = sessionFactory.ConnectionProvider.GetConnection();
+ }
+ else
+ {
+ connection = null;
+ }
+ using (SqlConnection sqlConnection = connection as SqlConnection)
+ {
+ using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
+ {
+ sqlCommand.CommandText = string.Concat("SELECT * FROM item WHERE iddocumento IN (", string.Join<long>(",",
+ from x in documento
+ select x.Id), ")");
+ using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
+ {
+ sqlDataAdapter.SelectCommand = sqlCommand;
+ sqlDataAdapter.Fill(dataTable);
+ }
+ if (dataTable.Rows.Count != 0)
+ {
+ return (
+ from x in dataTable.AsEnumerable().ToList<DataRow>()
+ select new Item()
+ {
+ Id = x.Field<long>("iditem"),
+ Descricao = x.Field<string>("descricao"),
+ Ordem = x.Field<int?>("ordem"),
+ Documento = new Documento()
+ {
+ Id = x.Field<long>("iddocumento")
+ }
+ } into x
+ orderby x.Ordem
+ select x).ToList<Item>();
+ }
+ else
+ {
+ items = new List<Item>();
+ }
+ }
+ }
+ return items;
+ }
+
+ public List<Item> FindItens(long id)
+ {
+ List<ItemDb> list = (
+ from x in base.All()
+ where x.Documento.Id == id
+ select x).ToList<ItemDb>();
+ return ApplicationMapper.Mapper.Map<List<ItemDb>, List<Item>>(list);
+ }
+
+ public int FindNextItem(long id)
+ {
+ int? nullable;
+ int? nullable1;
+ int? ordem;
+ int? nullable2;
+ List<Item> items = this.FindItens(id, StatusItem.Ativos);
+ if (items != null)
+ {
+ Item item = items.LastOrDefault<Item>();
+ if (item != null)
+ {
+ ordem = item.Ordem;
+ }
+ else
+ {
+ nullable1 = null;
+ ordem = nullable1;
+ }
+ nullable = ordem;
+ if (nullable.HasValue)
+ {
+ nullable2 = new int?(nullable.GetValueOrDefault() + 1);
+ }
+ else
+ {
+ nullable1 = null;
+ nullable2 = nullable1;
+ }
+ }
+ else
+ {
+ nullable = null;
+ nullable2 = nullable;
+ }
+ nullable = nullable2;
+ return nullable.GetValueOrDefault(1);
+ }
+
+ public Item Merge(Item item)
+ {
+ bool count;
+ List<CoberturaDb> list;
+ ItemDb itemDb = ApplicationMapper.Mapper.Map<Item, ItemDb>(item);
+ IList<CoberturaDb> coberturaDbs = itemDb.Coberturas;
+ if (coberturaDbs != null)
+ {
+ count = coberturaDbs.Count == 0;
+ }
+ else
+ {
+ count = false;
+ }
+ bool flag = count;
+ List<CoberturaDb> list1 = (
+ from x in this._unitOfWork.Query<CoberturaDb>()
+ where x.Item.Id == itemDb.Id
+ select x).ToList<CoberturaDb>();
+ if (list1 != null)
+ {
+ list = list1.Where<CoberturaDb>((CoberturaDb x) => {
+ IList<CoberturaDb> coberturas = itemDb.Coberturas;
+ Func<CoberturaDb, long> u003cu003e9_42 = ItemRepository.u003cu003ec.u003cu003e9__4_2;
+ if (u003cu003e9_42 == null)
+ {
+ u003cu003e9_42 = (CoberturaDb c) => c.Id;
+ ItemRepository.u003cu003ec.u003cu003e9__4_2 = u003cu003e9_42;
+ }
+ return !coberturas.Select<CoberturaDb, long>(u003cu003e9_42).ToList<long>().Contains(x.Id);
+ }).ToList<CoberturaDb>();
+ }
+ else
+ {
+ list = null;
+ }
+ List<CoberturaDb> coberturaDbs1 = list;
+ itemDb.Coberturas = list1;
+ base.Merge(itemDb);
+ if (coberturaDbs1 != null && coberturaDbs1.Count > 0)
+ {
+ this._unitOfWork.Repository<CoberturaDb>().DeleteRange(coberturaDbs1);
+ }
+ if (flag)
+ {
+ this._unitOfWork.Repository<CoberturaDb>().DeleteRange(itemDb.Coberturas);
+ }
+ itemDb.Coberturas = null;
+ return ApplicationMapper.Mapper.Map<ItemDb, Item>(itemDb);
+ }
+
+ public Item SaveOrUpdate(Item item)
+ {
+ ItemDb itemDb = ApplicationMapper.Mapper.Map<Item, ItemDb>(item);
+ this.SaveOrUpdate(itemDb);
+ return ApplicationMapper.Mapper.Map<ItemDb, Item>(itemDb);
+ }
+ }
+} \ No newline at end of file