Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="utente"></param>
        /// <returns></returns>
        private static Utente InternalUpdate(Utente utente)
        {
            Dpa.DataAccess.Database db = RubricaDatabase.CreateDatabase();

            DateTime dataUltimaModifica = DateTime.Now;

            using (IDbConnection connection = db.GetConnection())
            {
                connection.Open();

                using (IDbTransaction transaction = connection.BeginTransaction())
                {
                    using (Dpa.DataAccess.DBCommandWrapper cw = db.GetStoredProcCommandWrapper(RubricaDatabase.GetSpNameForPackage(SP_UPDATE)))
                    {
                        cw.AddInParameter("pId", DbType.Int32, utente.Id);
                        cw.AddInParameter("pAmministratore", DbType.AnsiStringFixedLength, (utente.Amministratore ? "1" : "0"));
                        cw.AddInParameter("pDataUltimaModifica", DbType.DateTime, dataUltimaModifica);
                        cw.AddInParameter("pOldDataUltimaModifica", DbType.DateTime, utente.DataUltimaModifica);

                        db.ExecuteNonQuery(cw);

                        if (cw.RowsAffected == 0)
                        {
                            throw new RubricaException(Properties.Resources.ConcurrencyException);
                        }
                        else
                        {
                            utente.DataUltimaModifica = dataUltimaModifica;

                            transaction.Commit();
                        }
                    }
                }
            }

            return(utente);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Repreimento oggetto DataObject
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private static ElementoRubrica InternalGet(int id)
        {
            ElementoRubrica elemento = null;

            try
            {
                Dpa.DataAccess.Database db = RubricaDatabase.CreateDatabase();

                using (Dpa.DataAccess.DBCommandWrapper cw = db.GetStoredProcCommandWrapper(RubricaDatabase.GetSpNameForPackage(SP_GET)))
                {
                    cw.AddInParameter("pId", DbType.Int32, id);

                    Utils.Log.Write(cw.Command);

                    using (IDataReader reader = db.ExecuteReader(cw))
                        if (reader.Read())
                        {
                            elemento = CreateElementoRubrica(reader, true);
                        }
                }

                if (elemento == null)
                {
                    throw new ApplicationException(Properties.Resources.DataNotFoundException);
                }
            }
            catch (Exception ex)
            {
                RubricaException exception = new RubricaException(string.Format(Properties.Resources.GetElementoRubricaException, id), ex);

                Utils.Log.Write(exception);

                throw exception;
            }

            return(elemento);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Aggiornamento oggetto in tabella ElementiRubrica
        /// </summary>
        /// <param name="elemento"></param>
        /// <param name="multicasella">
        ///     Flag utilizzato per indicare se bisogna gestire il corrispondente come corrispondente multicasella.
        ///     Se un corrispondente è multicasella, la gestione avviene esclusivamente prendendo in considerazione
        ///     la lista delle caselle email altrimenti viene considerata come casella quella passata attraverso
        ///     la valorizzazione della proprietà Email.
        ///     Nel caso monocasella, se l'attributo Mail dell'oggetto ElementoRubrica è valorizzato, viene aggiunta
        ///     (se non esiste) una nuova casella preferita al corrispondente, se viene passato nullo, viene cancellata
        ///     la casella preferita e, se presenti altre email associate al corrispondente, viene impostata
        ///     come preferita la prima casella disponibile.
        /// </param>
        /// <returns></returns>
        private static ElementoRubrica InternalUpdate(ElementoRubrica elemento, bool multicasella)
        {
            Dpa.DataAccess.Database db = RubricaDatabase.CreateDatabase();

            DateTime dataUltimaModifica = DateTime.Now;

            using (IDbConnection connection = db.GetConnection())
            {
                connection.Open();

                using (IDbTransaction transaction = connection.BeginTransaction())
                {
                    using (Dpa.DataAccess.DBCommandWrapper cw = db.GetStoredProcCommandWrapper(RubricaDatabase.GetSpNameForPackage(SP_UPDATE)))
                    {
                        cw.AddInParameter("pId", DbType.Int32, elemento.Id);
                        cw.AddInParameter("pDescrizione", DbType.String, elemento.Descrizione);
                        cw.AddInParameter("pIndirizzo", DbType.String, elemento.Indirizzo);
                        cw.AddInParameter("pCitta", DbType.String, elemento.Citta);
                        cw.AddInParameter("pCap", DbType.String, elemento.Cap);
                        cw.AddInParameter("pProvincia", DbType.String, elemento.Provincia);
                        cw.AddInParameter("pNazione", DbType.String, elemento.Nazione);
                        cw.AddInParameter("pTelefono", DbType.String, elemento.Telefono);
                        cw.AddInParameter("pFax", DbType.String, elemento.Fax);
                        //cw.AddInParameter("pEmail", DbType.String, elemento.Email);
                        cw.AddInParameter("pAOO", DbType.String, elemento.AOO);
                        cw.AddInParameter("pDataUltimaModifica", DbType.DateTime, dataUltimaModifica);
                        cw.AddInParameter("pOldDataUltimaModifica", DbType.DateTime, elemento.DataUltimaModifica);
                        cw.AddInParameter("pTipoCorrispondente", DbType.String, elemento.TipoCorrispondente.ToString());
                        cw.AddInParameter("pAmministrazione", DbType.String, elemento.Amministrazione);

                        if (elemento.Urls.Count > 0)
                        {
                            cw.AddInParameter("pUrl", DbType.String, elemento.Urls[0].Url);
                        }
                        else
                        {
                            cw.AddInParameter("pUrl", DbType.String, String.Empty);
                        }

                        if (string.IsNullOrEmpty(elemento.CHA_Pubblicato))
                        {
                            elemento.CHA_Pubblicato = "0";
                        }
                        cw.AddInParameter("pChaPubblica", DbType.String, elemento.CHA_Pubblicato);

                        //Emanuela: aggiunta campi partita iva e codice fiscale
                        cw.AddInParameter("pCodiceFiscale", DbType.String, elemento.CodiceFiscale);
                        cw.AddInParameter("pPartitaIva", DbType.String, elemento.PartitaIva);


                        Utils.Log.Write(cw.Command);

                        db.ExecuteNonQuery(cw);

                        if (cw.RowsAffected == 0)
                        {
                            throw new RubricaException(Properties.Resources.ConcurrencyException);
                        }
                        else
                        {
                            elemento.DataUltimaModifica = dataUltimaModifica;

                            // Aggiornamento delle emails
                            UpdateEmails(elemento, multicasella);

                            transaction.Commit();
                        }
                    }
                }
            }

            return(elemento);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Inserimento nuovo oggetto in tabella ElementiRubrica
        /// </summary>
        /// <param name="elemento"></param>
        /// <returns></returns>
        private static ElementoRubrica InternalInsert(ElementoRubrica elemento)
        {
            Dpa.DataAccess.Database db = RubricaDatabase.CreateDatabase();

            using (IDbConnection connection = db.GetConnection())
            {
                connection.Open();

                using (IDbTransaction transaction = connection.BeginTransaction())
                {
                    using (Dpa.DataAccess.DBCommandWrapper cw = db.GetStoredProcCommandWrapper(RubricaDatabase.GetSpNameForPackage(SP_INSERT)))
                    {
                        elemento.DataCreazione      = DateTime.Now;
                        elemento.DataUltimaModifica = DateTime.Now;

                        cw.AddInParameter("pCodice", DbType.String, elemento.Codice);
                        cw.AddInParameter("pDescrizione", DbType.String, elemento.Descrizione);
                        cw.AddInParameter("pIndirizzo", DbType.String, elemento.Indirizzo);
                        cw.AddInParameter("pCitta", DbType.String, elemento.Citta);
                        cw.AddInParameter("pCap", DbType.String, elemento.Cap);
                        cw.AddInParameter("pProvincia", DbType.String, elemento.Provincia);
                        cw.AddInParameter("pNazione", DbType.String, elemento.Nazione);
                        cw.AddInParameter("pTelefono", DbType.String, elemento.Telefono);
                        cw.AddInParameter("pFax", DbType.String, elemento.Fax);
                        //cw.AddInParameter("pEmail", DbType.String, elemento.Email);
                        cw.AddInParameter("pAOO", DbType.String, elemento.AOO);
                        cw.AddInParameter("pDataCreazione", DbType.DateTime, elemento.DataCreazione);
                        cw.AddInParameter("pDataUltimaModifica", DbType.DateTime, elemento.DataUltimaModifica);
                        cw.AddInParameter("pUtenteCreatore", DbType.String, Security.RubricaPrincipal.Current.Identity.Name);
                        cw.AddInParameter("pTipoCorrispondente", DbType.String, elemento.TipoCorrispondente.ToString());
                        cw.AddInParameter("pAmministrazione", DbType.String, elemento.Amministrazione);
                        if (elemento.Urls.Count > 0)
                        {
                            cw.AddInParameter("pUrl", DbType.String, elemento.Urls[0].Url);
                        }
                        else
                        {
                            cw.AddInParameter("pUrl", DbType.String, String.Empty);
                        }
                        if (string.IsNullOrEmpty(elemento.CHA_Pubblicato))
                        {
                            elemento.CHA_Pubblicato = "0";
                        }
                        cw.AddInParameter("pChaPubblica", DbType.String, elemento.CHA_Pubblicato);
                        cw.AddOutParameter("pId", DbType.Int32, 0);

                        //Emanuela: aggiunta campi partita iva e codice fiscale
                        cw.AddInParameter("pCodiceFiscale", DbType.String, elemento.CodiceFiscale);
                        cw.AddInParameter("pPartitaIva", DbType.String, elemento.PartitaIva);

                        Utils.Log.Write(cw.Command);

                        db.ExecuteNonQuery(cw);

                        if (cw.RowsAffected > 0)
                        {
                            elemento.Id = Convert.ToInt32(cw.GetParameterValue("pId"));

                            // Rimozione delle email e associazione delle nuove
                            if (!String.IsNullOrEmpty(elemento.Email) && elemento.Emails.Count(m => m.Email == elemento.Email) == 0)
                            {
                                elemento.Emails.Add(new EmailInfo(elemento.Email, true));
                            }

                            elemento.Emails.ForEach(d => InternalInsertEmail(d, elemento.Id));

                            // Commit transazione
                            transaction.Commit();
                        }
                    }
                }
            }

            return(elemento);
        }