Ejemplo n.º 1
0
 public void Insert(SendMail.Model.RubricaMapping.RubricaEntita entity)
 {
     using (var dbcontext = new FAXPECContext())
     {
         try
         {
             var rubr = DaoSQLServerDBHelper.MapToRubrEntita(entity, true);
             dbcontext.RUBR_ENTITA.Add(rubr);
             int r = dbcontext.SaveChanges();
             if (r == 1)
             {
                 entity.IdReferral = (long)rubr.ID_REFERRAL;
             }
             else
             {
                 //Allineamento log - Ciro
                 ManagedException mEx = new ManagedException("Errore inserimento ",
                                                             "RUB_ORA003",
                                                             string.Empty,
                                                             string.Empty,
                                                             null);
                 ErrorLogInfo er = new ErrorLogInfo(mEx);
                 log.Error(er);
                 throw mEx;
             }
         }
         catch
         {
             throw;
         }
     }
 }
Ejemplo n.º 2
0
 public void Insert(SendMail.Model.RubricaMapping.RubricaContatti entity)
 {
     using (var dbcontext = new FAXPECContext())
     {
         using (var dbContextTransaction = dbcontext.Database.BeginTransaction())
         {
             try
             {
                 if (entity.Entita != null)
                 {
                     RUBR_ENTITA e = DaoSQLServerDBHelper.MapToRubrEntita(entity.Entita, true);
                     dbcontext.RUBR_ENTITA.Add(e);
                     entity.Entita.IdReferral = (long)e.ID_REFERRAL;
                     entity.RefIdReferral     = (long)e.ID_REFERRAL;
                     RUBR_CONTATTI c = DaoSQLServerDBHelper.MapToRubrContatti(entity, true);
                     entity.IdContact = (long)c.ID_CONTACT;
                     dbcontext.RUBR_CONTATTI.Add(c);
                     dbcontext.SaveChanges();
                     dbContextTransaction.Commit();
                 }
                 else if (entity.Entita == null && entity.RefIdReferral != null)
                 {
                     RUBR_CONTATTI c = DaoSQLServerDBHelper.MapToRubrContatti(entity, true);
                     entity.IdContact = (long)c.ID_CONTACT;
                     dbcontext.RUBR_CONTATTI.Add(c);
                     int righe = dbcontext.SaveChanges();
                     dbContextTransaction.Commit();
                 }
                 else if (entity.Entita == null && entity.RefIdReferral == null)
                 {
                     dbContextTransaction.Rollback();
                     ManagedException mEx = new ManagedException("Errore nell'inserimento del contatto per il contatto " + entity.Mail + " >> ERR_C014 >> Dettagli Errore:  Mancano riferimenti entità",
                                                                 "SQL_ERR_C014", string.Empty, string.Empty, null);
                     ErrorLogInfo err = new ErrorLogInfo(mEx);
                     _log.Error(err);
                     throw mEx;
                 }
             }
             catch (Exception ex)
             {
                 dbContextTransaction.Rollback();
                 if (!ex.GetType().Equals(typeof(ManagedException)))
                 {
                     ManagedException mEx = new ManagedException(ex.Message,
                                                                 "SQL_ERR_C013", string.Empty, string.Empty, ex);
                     ErrorLogInfo err = new ErrorLogInfo(mEx);
                     _log.Error(err);
                     throw mEx;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
     }
 }