Exemplo n.º 1
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;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public SendMail.Model.RubricaMapping.RubricaContatti GetById(long id)
        {
            RubricaContatti c = null;

            using (var dbcontext = new FAXPECContext())
            {
                try
                {
                    RUBR_CONTATTI v          = dbcontext.RUBR_CONTATTI.Where(x => x.ID_CONTACT == id).First();
                    var           ListTitoli = (from t in dbcontext.RUBR_CONTATTI_BACKEND
                                                where t.REF_ID_CONTATTO == v.ID_CONTACT
                                                select t.COMUNICAZIONI_TITOLI.ID_TITOLO).ToList();
                    c = AutoMapperConfiguration.MapToRubrContatti(v, ListTitoli);
                } catch (Exception e)
                {
                    throw e;
                }
            }
            return(c);
        }
Exemplo n.º 3
0
        internal static RUBR_CONTATTI MapToRubrContatti(RubricaContatti entity, bool isInsert)
        {
            RUBR_CONTATTI oparams = new RUBR_CONTATTI
            {
                MAIL            = entity.Mail,
                TELEFONO        = entity.Telefono,
                FAX             = entity.Fax,
                FLG_PEC         = Convert.ToInt64(entity.IsPec),
                SOURCE          = entity.Source,
                NOTE            = entity.Note,
                CONTACT_REF     = entity.ContactRef,
                REF_ID_REFERRAL = (decimal)entity.RefIdReferral,
                FLG_IPA         = (entity.AffIPA == null) ? "0" : entity.AffIPA.ToString()
            };

            if (!isInsert)
            {
                oparams.ID_CONTACT = (decimal)entity.IdContact;
            }

            return(oparams);
        }