Example #1
0
        /// <summary>
        /// Add a batch of asuntos
        /// </summary>
        /// <param name="lstA"></param>
        public void Add(List <Entidades.Asunto> lstA)
        {
            try {
                // Validates if the list is sented with data. If the list have one value, the petition is rejected because this method is for a batch of asuntos
                if (lstA == null || lstA.Count <= 1)
                {
                    throw new Exception("La lista de asuntos recibida esta vacía, es nula o es menor al minimo");
                }
                using (SQLiteConnection c = new SQLiteConnection(Conexion.Cadena)) {
                    c.Open();
                    using (SQLiteTransaction t = c.BeginTransaction()) {
                        string strInsertAsuntoOnDatabase = "INSERT INTO asuntos VALUES (@Number, @Operator, @ShortDescription, @DerivedGroup, @ForReport)";
                        using (SQLiteCommand cmdInsertAsuntoOnDatabase = new SQLiteCommand(strInsertAsuntoOnDatabase, c, t)) {
                            foreach (var asuntoToSave in lstA)
                            {
                                cmdInsertAsuntoOnDatabase.Parameters.Agregar("@Number", asuntoToSave.Numero);
                                cmdInsertAsuntoOnDatabase.Parameters.Agregar("@Operator", asuntoToSave.Oper.UserName);
                                cmdInsertAsuntoOnDatabase.Parameters.Agregar("@ShortDescription", asuntoToSave.DescripcionBreve);
                                cmdInsertAsuntoOnDatabase.Parameters.Agregar("@DerivedGroup", asuntoToSave.GrupoDerivado != null ? asuntoToSave.GrupoDerivado.Id : 0);
                                cmdInsertAsuntoOnDatabase.Parameters.Agregar("@ForReport", asuntoToSave.Reportable);

                                if (asuntoToSave.Estados != null)
                                {
                                    EstadoAsunto.AddAllFromAsunto(asuntoToSave, c, t);
                                }

                                if (asuntoToSave.Actuacion != null)
                                {
                                    Actuacion.Agregar(asuntoToSave, c, t);
                                }

                                cmdInsertAsuntoOnDatabase.ExecuteNonQuery();
                            }
                        }

                        // When process is completed correctly, commit changes on database
                        t.Commit();
                    }
                }
            } catch (Exception ex) {
                throw ex;
            }
        }
Example #2
0
        /// <summary>
        /// Agrega un asunto a la base de datos
        /// Fecha de creación : 06/06/2018
        /// Autor : Maximiliano Leiva
        /// </summary>
        /// <param name="pEntAsunto">Entidad con los datos cargados que necesitan persistencia</param>
        public void Add(Entidades.Asunto pEntAsunto)
        {
            // Generamos el objeto de conexión
            using (SQLiteConnection c = new SQLiteConnection(Conexion.Cadena))
            {
                // Abrimos la conexión
                c.Open();
                using (SQLiteTransaction t = c.BeginTransaction())
                {
                    // Disponemos de la cadena que se utilizará en el ingreso a la base de datos
                    String strIngresarAsunto = "INSERT INTO asuntos (numero, operador, descripcion_breve, grupo_derivado, reportable) values (@Numero, @Operador, @Descripcion_breve, @Grupo_Derivado, @Reportable)";
                    using (SQLiteCommand cmdIngresarAsunto = new SQLiteCommand(strIngresarAsunto, c, t))
                    {
                        // Parametrizamos los valores agregados
                        cmdIngresarAsunto.Parameters.Agregar("@Numero", pEntAsunto.Numero);
                        cmdIngresarAsunto.Parameters.Agregar("@Operador", pEntAsunto.Oper.UserName);
                        cmdIngresarAsunto.Parameters.Agregar("@Descripcion_breve", pEntAsunto.DescripcionBreve);
                        cmdIngresarAsunto.Parameters.Agregar("@Grupo_Derivado", pEntAsunto.GrupoDerivado);
                        cmdIngresarAsunto.Parameters.Agregar("@Reportable", pEntAsunto.Reportable ? 1 : 0);
                        // Ejecutamos el Query
                        cmdIngresarAsunto.ExecuteNonQuery();
                    }
                    if (pEntAsunto.Estados != null)
                    {
                        // Agregamos los estados que traiga el asunto en cuestión
                        EstadoAsunto.AddAllFromAsunto(pEntAsunto, c, t);
                    }


                    // Agregamos la o las actuaciones
                    if (pEntAsunto.Actuacion != null)
                    {
                        Actuacion.Agregar(pEntAsunto, c, t);
                    }
                    t.Commit();
                }
            }
        }