예제 #1
0
 public void Update(SendMail.Model.RubricaMapping.RubricaContatti entity)
 {
     using (var dbcontext = new FAXPECContext())
     {
         using (var transaction = dbcontext.Database.Connection.BeginTransaction())
             try
             {
                 var rubrOld = dbcontext.RUBR_CONTATTI.Where(x => x.ID_CONTACT == entity.IdContact).First();
                 var rubrNew = DaoSQLServerDBHelper.MapToRubrContatti(entity, false);
                 dbcontext.RUBR_CONTATTI.Remove(rubrOld);
                 dbcontext.RUBR_CONTATTI.Add(rubrNew);
                 int res = dbcontext.SaveChanges();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 if (!ex.GetType().Equals(typeof(ManagedException)))
                 {
                     ManagedException mEx = new ManagedException("Errore nell'inserimento del contatto per il contatto " + entity.Mail + " >> ERR_C012 >> Dettagli Errore: " + ex.Message,
                                                                 "SQL_ERR_C012", string.Empty, string.Empty, ex.InnerException);
                     ErrorLogInfo err = new ErrorLogInfo(mEx);
                     _log.Error(err);
                     throw mEx;
                 }
                 else
                 {
                     throw ex;
                 }
             }
     }
 }
예제 #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;
                 }
             }
         }
     }
 }