예제 #1
0
        public int Save(MailRefs entity)
        {
            int ins = 0;

            try
            {
                using (FAXPECContext dbcontext = new FAXPECContext())
                {
                    MAIL_REFS_NEW refs = AutoMapperConfiguration.FromMailRefsNewToDto(entity);
                    dbcontext.MAIL_REFS_NEW.Add(refs);
                    ins = dbcontext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(ManagedException))
                {
                    ManagedException mEx = new ManagedException(ex.Message, "ERR_INS002", string.Empty, string.Empty, ex);
                    ErrorLogInfo     er  = new ErrorLogInfo(mEx);
                    er.objectID = entity.IdRef.ToString();
                    log.Error(er);
                    throw mEx;
                }
                else
                {
                    throw ex;
                }
            }
            return(ins);
        }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="entity"></param>
 public void Insert(Model.MailRefs entity)
 {
     try
     {
         using (FAXPECContext dbcontext = new FAXPECContext())
         {
             MAIL_REFS_NEW refs = AutoMapperConfiguration.FromMailRefsNewToDto(entity);
             dbcontext.MAIL_REFS_NEW.Add(refs);
             dbcontext.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         //Allineamento log - Ciro
         if (ex.GetType() != typeof(ManagedException))
         {
             ManagedException mEx = new ManagedException(ex.Message, "ERR_INS001", string.Empty, string.Empty, ex);
             ErrorLogInfo     er  = new ErrorLogInfo(mEx);
             er.objectID = entity.IdRef.ToString();
             log.Error(er);
             throw mEx;
         }
         else
         {
             throw ex;
         }
     }
 }
예제 #3
0
        public void Insert(Model.ComunicazioniMapping.Comunicazioni entity)
        {
            using (var dbcontext = new FAXPECContext())
            {
                using (var dbContextTransaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        AutoMapperConfiguration.Configure();
                        //   COMUNICAZIONI comunicazione = AutoMapperConfiguration.fromComunicazioniToDto(entity,false,false);
                        COMUNICAZIONI comunicazione = AutoMapperConfiguration.fromComunicazioniToSimpleDto(entity);
                        decimal       idComOld      = 0;
                        string        v_cod_app     = string.Empty;
                        if (entity.MailComunicazione.Follows != null)
                        {
                            MAIL_CONTENT oldcontent = dbcontext.MAIL_CONTENT.Where(x => x.ID_MAIL == entity.MailComunicazione.Follows).FirstOrDefault();
                            idComOld = (oldcontent == null) ? 0 : oldcontent.REF_ID_COM;
                        }
                        if (idComOld == 0)
                        {
                            v_cod_app = dbcontext.COMUNICAZIONI_SOTTOTITOLI.Where(x => x.ID_SOTTOTITOLO == entity.RefIdSottotitolo).First().COMUNICAZIONI_TITOLI.APP_CODE;
                            entity.CodAppInserimento = v_cod_app;
                        }
                        else
                        {
                            COMUNICAZIONI old_comunicazione = dbcontext.COMUNICAZIONI.Where(x => x.ID_COM == idComOld).First();
                            entity.CodAppInserimento = old_comunicazione.COD_APP_INS;
                            entity.RefIdSottotitolo  = long.Parse(old_comunicazione.REF_ID_SOTTOTITOLO.ToString());
                        }
                        dbcontext.COMUNICAZIONI.Add(comunicazione);
                        dbcontext.SaveChanges();
                        decimal idcomnew = dbcontext.COMUNICAZIONI.Max(x => x.ID_COM);
                        entity.IdComunicazione = (long)idcomnew;
                        MAIL_CONTENT content = AutoMapperConfiguration.FromComunicazioniToMailContent(entity);
                        dbcontext.MAIL_CONTENT.Add(content);
                        dbcontext.SaveChanges();
                        decimal newidmail = dbcontext.MAIL_CONTENT.Select(c => c.ID_MAIL).DefaultIfEmpty(0).Max();
                        if (entity.ComFlussi != null && entity.ComFlussi.Count > 0)
                        {
                            var list = entity.ComFlussi.Where(x => x.Key == TipoCanale.MAIL).SelectMany(z => z.Value);
                            foreach (ComFlusso comFlusso in list)
                            {
                                COMUNICAZIONI_FLUSSO flusso = new COMUNICAZIONI_FLUSSO
                                {
                                    CANALE                  = comFlusso.Canale.ToString(),
                                    DATA_OPERAZIONE         = (comFlusso.DataOperazione == null ? DateTime.Now : Convert.ToDateTime(comFlusso.DataOperazione)),
                                    STATO_COMUNICAZIONE_NEW = ((int)comFlusso.StatoComunicazioneNew).ToString(),
                                    STATO_COMUNICAZIONE_OLD = ((int)comFlusso.StatoComunicazioneOld).ToString(),
                                    UTE_OPE                 = comFlusso.UtenteOperazione
                                };

                                if (entity.IdComunicazione.HasValue)
                                {
                                    flusso.REF_ID_COM = LinqExtensions.TryParseInt(entity.IdComunicazione);
                                }
                                else
                                {
                                    flusso.REF_ID_COM = idcomnew;
                                }
                                if (comFlusso.IdFlusso.HasValue)
                                {
                                    flusso.ID_FLUSSO = LinqExtensions.TryParseDouble(comFlusso.IdFlusso);
                                }
                                dbcontext.COMUNICAZIONI_FLUSSO.Add(flusso);
                                dbcontext.SaveChanges();
                            }
                        }
                        else
                        {
                            COMUNICAZIONI_FLUSSO flusso = new COMUNICAZIONI_FLUSSO
                            {
                                CANALE                  = TipoCanale.MAIL.ToString(),
                                DATA_OPERAZIONE         = System.DateTime.Now,
                                STATO_COMUNICAZIONE_NEW = ((int)(MailStatus.INSERTED)).ToString(),
                                STATO_COMUNICAZIONE_OLD = null,
                                UTE_OPE                 = entity.UtenteInserimento
                            };
                            flusso.REF_ID_COM = idcomnew;
                            dbcontext.COMUNICAZIONI_FLUSSO.Add(flusso);
                            dbcontext.SaveChanges();
                        }
                        if (entity.ComFlussiProtocollo != null && entity.ComFlussiProtocollo.Count > 0)
                        {
                            foreach (ComFlussoProtocollo comFlussoProtocollo in entity.ComFlussiProtocollo)
                            {
                                COMUNICAZIONI_FLUSSO_PROT flussoprotocollo = new COMUNICAZIONI_FLUSSO_PROT
                                {
                                    DATA_OPERAZIONE = (DateTime)comFlussoProtocollo.DataOperazione,
                                    STATO_NEW       = LinqExtensions.TryParseByte(comFlussoProtocollo.StatoNew.ToString()),
                                    STATO_OLD       = LinqExtensions.TryParseByte(comFlussoProtocollo.StatoOld.ToString()),
                                    UTE_OPE         = comFlussoProtocollo.UtenteOperazione
                                };
                                if (entity.IdComunicazione.HasValue)
                                {
                                    flussoprotocollo.REF_ID_COM = LinqExtensions.TryParseInt(entity.IdComunicazione);
                                }
                                else
                                {
                                    flussoprotocollo.REF_ID_COM = idcomnew;
                                }
                                dbcontext.COMUNICAZIONI_FLUSSO_PROT.Add(flussoprotocollo);
                            }
                        }
                        // gestione rubrica
                        if (entity.RubricaEntitaUsed != null && entity.RubricaEntitaUsed.Count > 0)
                        {
                            foreach (RubrEntitaUsed entitaused in entity.RubricaEntitaUsed)
                            {
                                // se ho usato la rubrica
                                if (entitaused.IdEntUsed != null && entitaused.IdEntUsed != 0)
                                {
                                    V_RUBR_CONTATTI v_rubr_contatti = dbcontext.V_RUBR_CONTATTI.Where(x => x.ID_CONTACT == entitaused.IdEntUsed).First();
                                    MAIL_REFS_NEW   mailrefsnew     = new MAIL_REFS_NEW()
                                    {
                                        REF_ID_MAIL       = comunicazione.MAIL_CONTENT.First().ID_MAIL,
                                        TIPO_REF          = entitaused.TipoContatto.ToString(),
                                        MAIL_DESTINATARIO = v_rubr_contatti.MAIL
                                    };
                                    dbcontext.MAIL_REFS_NEW.Add(mailrefsnew);
                                    COMUNICAZIONI_DESTINATARI destinatari = dbcontext.COMUNICAZIONI_DESTINATARI.Where(x => x.CAP == v_rubr_contatti.CAP &&
                                                                                                                      x.CIVICO == v_rubr_contatti.CIVICO && x.COD_FIS == v_rubr_contatti.COD_FIS &&
                                                                                                                      x.COD_ISO_STATO == v_rubr_contatti.COD_ISO_STATO && x.COGNOME == v_rubr_contatti.COGNOME &&
                                                                                                                      x.COMUNE == v_rubr_contatti.COMUNE && x.CONTACT_REF == v_rubr_contatti.CONTACT_REF &&
                                                                                                                      x.FAX == v_rubr_contatti.FAX && x.ID_REFERRAL == v_rubr_contatti.REF_ID_REFERRAL &&
                                                                                                                      x.INDIRIZZO == v_rubr_contatti.INDIRIZZO && x.MAIL == v_rubr_contatti.MAIL &&
                                                                                                                      x.NOME == v_rubr_contatti.NOME && x.P_IVA == v_rubr_contatti.P_IVA && x.RAGIONE_SOCIALE == v_rubr_contatti.RAGIONE_SOCIALE &&
                                                                                                                      x.REFERRAL_TYPE == v_rubr_contatti.REFERRAL_TYPE && x.SIGLA_PROV == v_rubr_contatti.SIGLA_PROV &&
                                                                                                                      x.TELEFONO == v_rubr_contatti.TELEFONO && x.UFFICIO == v_rubr_contatti.UFFICIO).FirstOrDefault();
                                    if (destinatari.ID_REFERRAL > 0)
                                    {
                                        COMUNICAZIONI_ENTITA_USED comunicazioni_entita_used = new COMUNICAZIONI_ENTITA_USED()
                                        {
                                            REF_ID_COMUNICAZIONE = comunicazione.ID_COM,
                                            REF_ID_ENTITA        = destinatari.ID_REFERRAL,
                                            REF_ID_ENT_USED      = destinatari.ID_COM_DEST
                                        };
                                        dbcontext.COMUNICAZIONI_ENTITA_USED.Add(comunicazioni_entita_used);
                                    }
                                    else
                                    {
                                        COMUNICAZIONI_DESTINATARI destinatari_new = AutoMapperConfiguration.fromRubrContattiToComunicazioniDestinatari(v_rubr_contatti);
                                        dbcontext.COMUNICAZIONI_DESTINATARI.Add(destinatari);
                                    }
                                }
                                // se ho il contatto custom
                                else
                                {
                                    MAIL_REFS_NEW mailrefsnew = new MAIL_REFS_NEW()
                                    {
                                        REF_ID_MAIL       = newidmail,
                                        TIPO_REF          = entitaused.TipoContatto.ToString(),
                                        MAIL_DESTINATARIO = entitaused.Mail
                                    };
                                    dbcontext.MAIL_REFS_NEW.Add(mailrefsnew);
                                    dbcontext.SaveChanges();
                                }
                            }
                        }
                        // fine rubrica
                        //inizio allegati
                        if (entity.ComAllegati != null && entity.ComAllegati.Count > 0)
                        {
                            foreach (ComAllegato a in entity.ComAllegati)
                            {
                                COMUNICAZIONI_ALLEGATI all = AutoMapperConfiguration.FromComAllegatoToDto(a);
                                all.REF_ID_COM = idcomnew;
                                dbcontext.COMUNICAZIONI_ALLEGATI.Add(all);
                            }
                            dbcontext.SaveChanges();
                        }
                        dbContextTransaction.Commit();
                    }
                    // fine try
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        if (!ex.GetType().Equals(typeof(ManagedException)))
                        {
                            ManagedException mEx = new ManagedException("Errore inserimento comunicazione. Dettaglio: " + ex.Message,
                                                                        "ERR_COM_032",
                                                                        string.Empty,
                                                                        string.Empty,
                                                                        ex.InnerException);
                            ErrorLogInfo err = new ErrorLogInfo(mEx);
                            err.objectID = (entity.IdComunicazione != null) ? entity.IdComunicazione.ToString() : "";
                            _log.Error(err);
                            throw mEx;
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                    // fine using  transaction
                } // fine using
            }
        }