public void Insert(Comunicazioni entity) { try { using (OracleCommand oCmd = base.CurrentConnection.CreateCommand()) { oCmd.CommandText = cmdInsertComunicazione; oCmd.BindByName = true; oCmd.CommandType = System.Data.CommandType.StoredProcedure; if (entity.RefIdSottotitolo.HasValue) { oCmd.Parameters.Add("v_ref_id_sottotitolo", entity.RefIdSottotitolo.Value); } else { oCmd.Parameters.Add("v_ref_id_sottotitolo", null); } if (entity.ComFlussi == null) { oCmd.Parameters.Add("v_ref_id_canale", ((int)(SendMail.Model.TipoCanale.MAIL))); } else { oCmd.Parameters.Add("v_ref_id_canale", ((int)(entity.ComFlussi.Last().Key))); } oCmd.Parameters.Add("v_flg_notifica", Convert.ToInt32(entity.IsToNotify).ToString()); oCmd.Parameters.Add("v_mail_notifica", entity.MailNotifica); oCmd.Parameters.Add("v_ute_ins", entity.UtenteInserimento); oCmd.Parameters.Add("v_orig_uid", entity.OrigUID); oCmd.Parameters.Add("v_unique_id_mapper", entity.UniqueId); OracleParameter pAllegati = new OracleParameter("v_allegati", OracleDbType.Object); pAllegati.UdtTypeName = "COM_ALLEGATO_LIST_TYPE"; oCmd.Parameters.Add(pAllegati); // aggiunta gestione protocollo OracleParameter pProtocollo = new OracleParameter("V_PROT_LIST", OracleDbType.Object); pProtocollo.UdtTypeName = "COM_PROTOCOLLO_LIST_TYPE"; ComProtocolloListTypeFactory protFac = new ComProtocolloListTypeFactory(); ComProtocolloListType protList = null; if (entity.ComunicazioniProtocollo == null) { protList = ComProtocolloListType.Null; } else { protList = (ComProtocolloListType)protFac.CreateObject(); List <ComProtocolloType> l = new List <ComProtocolloType>(); l.Add(new ComProtocolloType(entity.ComunicazioniProtocollo)); protList.ComProtocolli = l.ToArray(); } pProtocollo.Value = protList; oCmd.Parameters.Add(pProtocollo); // fine aggiunta if (entity is ComunicazioniType) { pAllegati.Value = ((ComunicazioniType)entity).COM_ALLEGATI; } else { ComAllegatoListType allList = null; if (entity.ComAllegati == null || entity.ComAllegati.Count == 0) { allList = ComAllegatoListType.Null; } else { ComAllegatoListTypeFactory allFac = new ComAllegatoListTypeFactory(); allList = (ComAllegatoListType)allFac.CreateObject(); if (entity.ComAllegati.All(x => x is ComAllegatoType)) { allList.ComAllegati = entity.ComAllegati.Cast <ComAllegatoType>().ToArray(); } else { allList.ComAllegati = entity.ComAllegati .Select <ComAllegato, ComAllegatoType>(x => new ComAllegatoType(x)).ToArray(); } } pAllegati.Value = allList; } if (entity.MailComunicazione == null) { oCmd.Parameters.Add("v_mail_sender", null); oCmd.Parameters.Add("v_mail_subject", null); oCmd.Parameters.Add("v_mail_text", null); } else { oCmd.Parameters.Add("v_mail_sender", entity.MailComunicazione.MailSender); oCmd.Parameters.Add("v_mail_subject", entity.MailComunicazione.MailSubject); oCmd.Parameters.Add("v_mail_text", OracleDbType.Clob, entity.MailComunicazione.MailText, System.Data.ParameterDirection.Input); } oCmd.Parameters.Add("v_follows", entity.MailComunicazione.Follows); oCmd.Parameters.Add("V_FOLDERID", entity.FolderId); oCmd.Parameters.Add("V_FOLDERTIPO", entity.FolderTipo); OracleParameter pContatti = new OracleParameter("v_rubrica_contatti_list", OracleDbType.Object); pContatti.UdtTypeName = "FAXPEC.RUBR_CONTATTI_LIST_TYPE"; oCmd.Parameters.Add(pContatti); RubricaContattiListTypeFactory contFac = new RubricaContattiListTypeFactory(); RubricaContattiListType contList = null; if (entity.RubricaEntitaUsed == null || entity.RubricaEntitaUsed.Count == 0) { contList = RubricaContattiListType.Null; } else { contList = (RubricaContattiListType)contFac.CreateObject(); contList.RubricaContatti = (from r in entity.RubricaEntitaUsed select new RubricaContattiType() { IdContact = r.IdEntUsed, Mail = r.Mail, TIPO_REF = r.TipoContatto.ToString() }).ToArray(); } pContatti.Value = contList; oCmd.BindByName = true; oCmd.ExecuteNonQuery(); } } catch (Exception ex) { //TASK: Allineamento log - Ciro 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; } //ErrorLogInfo error = new ErrorLogInfo(); //error.freeTextDetails = ex.Message; //error.logCode = "ERR_COM_032"; //_log.Error(error); } }
public void Insert(long idSottotitolo, long idCanale, bool isToNotify, string mailNotifica, string utenteInserimento, IList <ComAllegato> allegati, string mailSender, string oggetto, string testo, IList <SendMail.Model.RubricaMapping.RubricaContatti> refs) { try { using (OracleCommand oCmd = base.CurrentConnection.CreateCommand()) { oCmd.CommandText = cmdInsertComunicazione; oCmd.CommandType = System.Data.CommandType.StoredProcedure; oCmd.Parameters.Add("V_REF_ID_SOTTOTITOLO", idSottotitolo); oCmd.Parameters.Add("V_REF_ID_CANALE", idCanale); oCmd.Parameters.Add("V_FLG_NOTIFICA", Convert.ToInt32(isToNotify).ToString()); oCmd.Parameters.Add("V_MAIL_NOTIFICA", mailNotifica); oCmd.Parameters.Add("V_UTE_INS", utenteInserimento); OracleParameter pAll = new OracleParameter("V_ALLEGATI", OracleDbType.Object); pAll.UdtTypeName = "COM_ALLEGATO_LIST_TYPE"; oCmd.Parameters.Add(pAll); if (allegati == null || allegati.Count == 0) { pAll.Value = ComAllegatoListType.Null; } else { ComAllegatoListTypeFactory allFac = new ComAllegatoListTypeFactory(); ComAllegatoListType allT = (ComAllegatoListType)allFac.CreateObject(); pAll.Value = allT; if (allegati.All(a => a is ComAllegatoType)) { allT.ComAllegati = allegati.Cast <ComAllegatoType>().ToArray(); } else { allT.ComAllegati = allegati.Select(a => new ComAllegatoType(a)).ToArray(); } } oCmd.Parameters.Add("V_MAIL_SENDER", mailSender); oCmd.Parameters.Add("V_MAIL_SUBJECT", oggetto); oCmd.Parameters.Add("V_MAIL_TEXT", testo); oCmd.Parameters.Add("V_FOLLOWS", null); OracleParameter pRefs = new OracleParameter("V_RUBRICA_CONTATTI_LIST", OracleDbType.Object); pRefs.UdtTypeName = "RUBR_CONTATTI_LIST_TYPE"; oCmd.Parameters.Add(pRefs); if (refs == null || refs.Count == 0) { pRefs.Value = RubricaContattiListType.Null; } else { RubricaContattiListTypeFactory rubFac = new RubricaContattiListTypeFactory(); RubricaContattiListType rubLis = (RubricaContattiListType)rubFac.CreateObject(); pRefs.Value = rubLis; if (refs.All(a => a is RubricaContattiType)) { rubLis.RubricaContatti = refs.Cast <RubricaContattiType>().ToArray(); } else { rubLis.RubricaContatti = refs.Select(a => new RubricaContattiType(a)).ToArray(); } } oCmd.ExecuteNonQuery(); } } catch (Exception ex) { //TASK: Allineamento log - Ciro if (!ex.GetType().Equals(typeof(ManagedException))) { ManagedException mEx = new ManagedException("Errore inserimento mail. Dettaglio: " + ex.Message, "ERR_COM_002", string.Empty, string.Empty, ex.InnerException); ErrorLogInfo err = new ErrorLogInfo(mEx); err.objectID = idCanale.ToString(); _log.Error(err); throw mEx; } else { throw ex; } //ErrorLogInfo error = new ErrorLogInfo(); //error.freeTextDetails = ex.Message; //error.logCode = "ERR_COM_002"; //_log.Error(error); } }