internal static COMUNICAZIONI_SOTTOTITOLI MapToComunicazioniSottotitolo(SottoTitolo sottoTitolo, bool isInsert) { COMUNICAZIONI_SOTTOTITOLI s = new COMUNICAZIONI_SOTTOTITOLI() { REF_ID_TITOLO = sottoTitolo.RefIdTitolo, ACTIVE = Convert.ToDecimal(!sottoTitolo.Deleted), COM_CODE = sottoTitolo.ComCode, NOTE = sottoTitolo.Note, PROT_CODE = sottoTitolo.ProtocolloCode }; s.PROT_MANAGED = Convert.ToDecimal(sottoTitolo.UsaProtocollo); s.PROT_PWD = sottoTitolo.ProtocolloPassword; s.PROT_SUBCODE = sottoTitolo.ProtocolloSubCode; s.SOTTOTITOLO = sottoTitolo.Nome; if (sottoTitolo.TipiProcollo != null) { s.PROT_TIPI_AMMESSI = String.Join(";", sottoTitolo.TipiProcollo.Cast <string>().ToArray()); } if (sottoTitolo.ProtocolloLoadAllegati != null) { s.PROT_LOAD_ALLEGATI = Convert.ToDecimal(sottoTitolo.ProtocolloLoadAllegati); } if (!isInsert) { s.ID_SOTTOTITOLO = sottoTitolo.Id; } return(s); }
public void Update(SottoTitolo sottoTitolo) { using (var dbcontext = new FAXPECContext()) { try { COMUNICAZIONI_SOTTOTITOLI s = DaoSQLServerDBHelper.MapToComunicazioniSottotitolo(sottoTitolo, false); var olds = dbcontext.COMUNICAZIONI_SOTTOTITOLI.Where(x => x.ID_SOTTOTITOLO == sottoTitolo.Id).First(); dbcontext.COMUNICAZIONI_SOTTOTITOLI.Remove(olds); dbcontext.COMUNICAZIONI_SOTTOTITOLI.Add(s); int rowAff = dbcontext.SaveChanges(); if (rowAff == 0) { ManagedException mEx = new ManagedException(DalExMessages.NESSUNA_RIGA_MODIFICATA, "DAL_TIT_009", string.Empty, string.Empty, null); ErrorLogInfo err = new ErrorLogInfo(mEx); log.Error(mEx); throw mEx; } } catch (InvalidOperationException ex) { ManagedException mEx = new ManagedException(DalExMessages.RUBRICA_NON_AGGIORNATA, "DAL_UNIQUE_CODE", string.Empty, string.Empty, ex); ErrorLogInfo err = new ErrorLogInfo(mEx); log.Error(mEx); throw mEx; } } }
internal static SottoTitolo MapToSottotitolo(COMUNICAZIONI_SOTTOTITOLI s) { SottoTitolo st = new SottoTitolo(); st.Id = (Int32)s.ID_SOTTOTITOLO; st.Titolo.Id = (Int32)s.REF_ID_TITOLO; st.Nome = s.SOTTOTITOLO; st.ComCode = s.COM_CODE; st.Note = s.NOTE; if (s.ACTIVE != 1) { st.Deleted = false; } else { st.Deleted = !Convert.ToBoolean(s.ACTIVE); } st.ProtocolloCode = s.PROT_CODE; if (s.PROT_LOAD_ALLEGATI == 0) { st.ProtocolloLoadAllegati = false; } else { st.ProtocolloLoadAllegati = Convert.ToBoolean(s.PROT_LOAD_ALLEGATI); } st.ProtocolloPassword = s.PROT_PWD; st.ProtocolloSubCode = s.PROT_SUBCODE; st.TipiProcollo = null; if (!String.IsNullOrEmpty(s.PROT_TIPI_AMMESSI)) { st.TipiProcollo = (from t in s.PROT_TIPI_AMMESSI.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries) let exist = Enum.GetNames(typeof(ProtocolloTypes)).Contains(t) select((exist) ? (ProtocolloTypes)Enum.Parse(typeof(ProtocolloTypes), t) : ProtocolloTypes.UNKNOWN)).ToList(); } if (s.PROT_MANAGED == 0) { st.UsaProtocollo = false; } else { st.UsaProtocollo = Convert.ToBoolean(s.PROT_MANAGED); } return(st); }
public void Insert(SottoTitolo sottoTitolo) { using (var dbcontext = new FAXPECContext()) { try { COMUNICAZIONI_SOTTOTITOLI s = DaoSQLServerDBHelper.MapToComunicazioniSottotitolo(sottoTitolo, true); dbcontext.COMUNICAZIONI_SOTTOTITOLI.Add(s); var resp = dbcontext.SaveChanges(); if (resp == 0) { throw new Exception(DalExMessages.ID_NON_RESTITUITO); } } catch (InvalidOperationException ioex) { ManagedException mEx = new ManagedException(DalExMessages.RUBRICA_NON_INSERITA, "DAL_RUB_002", string.Empty, string.Empty, ioex); ErrorLogInfo err = new ErrorLogInfo(mEx); log.Error(mEx); throw mEx; } catch (SqlException oex) { ManagedException mEx = new ManagedException(DalExMessages.RUBRICA_NON_INSERITA, "DAL_RUB_001", string.Empty, string.Empty, oex); ErrorLogInfo err = new ErrorLogInfo(mEx); log.Error(mEx); throw mEx; } } }