public ContactsBackendMap GetById(int id)
        {
            ContactsBackendMap m = null;

            try
            {
                using (FAXPECContext dbcontext = new FAXPECContext())
                {
                    var r = dbcontext.RUBR_CONTATTI_BACKEND.Where(x => x.ID_MAP == id).OrderBy(x => x.REF_ID_BACKEND).OrderBy(x => x.REF_ID_TITOLO).FirstOrDefault();
                    if (r != null)
                    {
                        var ListTitoli = (from t in dbcontext.RUBR_CONTATTI_BACKEND
                                          where t.REF_ID_CONTATTO == r.REF_ID_CONTATTO
                                          select t.COMUNICAZIONI_TITOLI.ID_TITOLO).ToList();
                        var rubrcontatti = dbcontext.RUBR_CONTATTI.Where(x => x.ID_CONTACT == r.REF_ID_CONTATTO).First();
                        var rubrentita   = dbcontext.RUBR_ENTITA.Where(x => x.ID_REFERRAL == r.REF_ID_ENTITA).First();
                        m = AutoMapperConfiguration.MapToContactsBackendMap(r, rubrcontatti, rubrentita, ListTitoli);
                    }
                }
            }
            catch
            {
                throw;
            }
            return(m);
        }
 private static OracleParameter[] MapToParams(ContactsBackendMap c)
 {
     OracleParameter[] pars = new OracleParameter[4];
     pars[0] = new OracleParameter("pID_CANALE", OracleDbType.Decimal, System.Data.ParameterDirection.Input);
     if (c.Canale != SendMail.Model.TipoCanale.UNKNOWN)
     {
         pars[0].Value = (int)c.Canale;
     }
     pars[1] = new OracleParameter("pID_BACKEND", OracleDbType.Decimal, System.Data.ParameterDirection.Input);
     if (c.Backend.Id != -1)
     {
         pars[1].Value = c.Backend.Id;
     }
     pars[2] = new OracleParameter("pID_CONTATTO", OracleDbType.Decimal, System.Data.ParameterDirection.Input);
     if (c.Contatto.IdContact.Value != -1)
     {
         pars[2].Value = c.Contatto.IdContact.Value;
     }
     pars[3] = new OracleParameter("pID_TITOLO", OracleDbType.Decimal, System.Data.ParameterDirection.Input);
     if (c.Titolo.Id != -1)
     {
         pars[3].Value = c.Titolo.Id;
     }
     return(pars);
 }
        public ContactsBackendMap GetById(int id)
        {
            StringBuilder sb = new StringBuilder(selectCmdBase);

            sb.Append(" WHERE ID_MAP = :pID_MAP");
            try
            {
                using (OracleCommand cmd = CurrentConnection.CreateCommand())
                {
                    cmd.CommandText = sb.ToString();
                    cmd.BindByName  = true;
                    cmd.Parameters.Add("pID_MAP", OracleDbType.Decimal, id, System.Data.ParameterDirection.Input);

                    ContactsBackendMap contact = DaoOracleDbHelper <ContactsBackendMap> .ExecSelectCommand(cmd,
                                                                                                           DaoOracleDbHelper.MapToContactsBackendMap).FirstOrDefault();

                    if (contact != null)
                    {
                        Complete(contact);
                    }
                    return(contact);
                }
            }
            catch
            {
                throw;
            }
        }
 private void Complete(ContactsBackendMap contact)
 {
     if (contact == null)
     {
         return;
     }
     if (contact.Backend != null)
     {
         contact.Backend = Context.DaoImpl.BackEndCodeDao.GetById(contact.Backend.Id);
     }
     if (contact.Contatto != null)
     {
         contact.Contatto = Context.DaoImpl.ContattoDao.GetById(contact.Contatto.IdContact.Value);
     }
     if (contact.Titolo != null)
     {
         contact.Titolo = Context.DaoImpl.TitoloDao.GetById(contact.Titolo.Id);
     }
 }
Example #5
0
        internal static ContactsBackendMap MapToContactsBackendMap(IDataRecord dr)
        {
            ContactsBackendMap cbm = new ContactsBackendMap();

            if (dr.IsDBNull("ID_MAP") == false)
            {
                cbm.Id = (int)dr.GetDecimal("ID_MAP");
            }
            else
            {
                cbm.Id = -1;
            }
            cbm.Canale = TipoCanale.UNKNOWN;
            if (dr.IsDBNull("REF_ID_CANALE") == false)
            {
                cbm.Canale = (TipoCanale)(int)dr.GetDecimal("REF_ID_CANALE");
            }
            if (dr.IsDBNull("REF_ID_BACKEND") == false)
            {
                cbm.Backend = new BackEndRefCode {
                    Id = dr.GetDecimal("REF_ID_BACKEND")
                }
            }
            ;
            cbm.Contatto = new RubricaContatti();
            if (dr.IsDBNull("REF_ID_CONTATTO") == false)
            {
                cbm.Contatto.IdContact = (long)dr.GetDecimal("REF_ID_CONTATTO");
            }
            else
            {
                cbm.Contatto.IdContact = -1;
            }
            if (dr.IsDBNull("REF_ID_TITOLO") == false)
            {
                cbm.Titolo = new Titolo {
                    Id = dr.GetDecimal("REF_ID_TITOLO")
                }
            }
            ;
            return(cbm);
        }
 public void Insert(ContactsBackendMap entity)
 {
     try
     {
         using (FAXPECContext dbcontext = new FAXPECContext())
         {
             RUBR_CONTATTI_BACKEND b = DaoSQLServerDBHelper.MapToRubrContattiBackend(entity);
             dbcontext.RUBR_CONTATTI_BACKEND.Add(b);
             int risp = dbcontext.SaveChanges();
             if (risp == 1)
             {
                 entity.Id = (int)b.ID_MAP;
             }
         }
     }
     catch
     {
         throw;
     }
 }
Example #7
0
        public HttpResponseMessage PutMapping(EntiMappings mapping)
        {
            Response <EntiMappings> response = new Response <EntiMappings>();

            try
            {
                ContactsBackendMap bMap = (ContactsBackendMap)mapping;
                s.UpdateMapping(bMap);
                List <EntiMappings> list = new List <EntiMappings>();
                list.Add(mapping);
                response.Totale  = 1;
                response.Message = "Operazione effettuata";
                response.Data    = list;
            }
            catch
            {
                response.Totale  = 0;
                response.Message = "Errore nell'aggiornamento del contatto";
            }
            return(this.Request.CreateResponse <Response <EntiMappings> >(HttpStatusCode.OK, response));
        }
Example #8
0
        public HttpResponseMessage CreateMapping(EntiMappings mapping)
        {
            Response <EntiMappings> resp = new Response <EntiMappings>();

            try
            {
                ContactsBackendMap bMap = (ContactsBackendMap)mapping;
                s.CreateMapping(bMap);
                mapping.EnteMapping.ElementAt(0).Mapping.ElementAt(0).Id = bMap.Id;
                List <EntiMappings> list = new List <EntiMappings>();
                list.Add(mapping);
                resp.Totale  = 1;
                resp.Message = "Operazione effettuata";
                resp.Data    = list;
            }
            catch
            {
                resp.Totale  = 0;
                resp.Message = "Errore nell'inserimento del contatto";
            }
            return(this.Request.CreateResponse <Response <EntiMappings> >(HttpStatusCode.OK, resp));
        }
 public void Update(ContactsBackendMap entity)
 {
     try
     {
         using (FAXPECContext dbcontext = new FAXPECContext())
         {
             var oldentities = dbcontext.RUBR_CONTATTI_BACKEND.Where(x => x.ID_MAP == entity.Id).First();
             if (oldentities != null)
             {
                 oldentities.REF_ID_CANALE   = (int)entity.Canale;
                 oldentities.REF_ID_CONTATTO = (int)entity.Contatto.IdContact;
                 oldentities.REF_ID_BACKEND  = (int)entity.Backend.Id;
                 oldentities.REF_ID_TITOLO   = (int)entity.Titolo.Id;
                 int risp = dbcontext.SaveChanges();
                 if (risp != 1)
                 {
                     throw new InvalidOperationException("Errore nell'aggiornamento");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (!ex.GetType().Equals(typeof(ManagedException)))
         {
             ManagedException mEx = new ManagedException(ex.Message,
                                                         "ORA_ERR009", string.Empty, string.Empty, ex);
             ErrorLogInfo err = new ErrorLogInfo(mEx);
             err.objectID = Convert.ToString(entity.Id);
             _log.Error(err);
             throw mEx;
         }
         else
         {
             throw ex;
         }
     }
 }
        public void Insert(ContactsBackendMap entity)
        {
            try
            {
                using (OracleCommand cmd = CurrentConnection.CreateCommand())
                {
                    cmd.CommandText = insertCmdBase;
                    cmd.BindByName  = true;
                    cmd.Parameters.AddRange(MapToParams(entity));
                    cmd.Parameters.Add("pID_MAP", OracleDbType.Decimal, System.Data.ParameterDirection.Output);

                    int risp = cmd.ExecuteNonQuery();
                    if (risp == 1)
                    {
                        entity.Id = Convert.ToInt32(cmd.Parameters["pID_MAP"].Value.ToString());
                    }
                }
            }
            catch
            {
                throw;
            }
        }
        public void Update(ContactsBackendMap entity)
        {
            try
            {
                using (OracleCommand cmd = CurrentConnection.CreateCommand())
                {
                    cmd.CommandText = updateCmdBase;
                    cmd.BindByName  = true;
                    cmd.Parameters.AddRange(MapToParams(entity));
                    cmd.Parameters.Add("pID_MAP", OracleDbType.Decimal, entity.Id, System.Data.ParameterDirection.InputOutput);

                    int risp = cmd.ExecuteNonQuery();
                    if (risp != 1)
                    {
                        throw new InvalidOperationException("Errore nell'aggiornamento");
                    }
                }
            }
            catch (Exception ex)
            {
                //TASK: Allineamento log - Ciro
                if (!ex.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException(ex.Message,
                                                                "ORA_ERR009", string.Empty, string.Empty, ex);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    err.objectID = Convert.ToString(entity.Id);
                    _log.Error(err);
                    throw mEx;
                }
                else
                {
                    throw ex;
                }
            }
        }