Пример #1
0
 /// <summary>
 /// Metodo para Crear un registro de SalidaSacrificio
 /// </summary>
 /// <param name="info">Valores de la entidad que será creada</param>
 public void Crear(SalidaSacrificioInfo info)
 {
     try
     {
         Logger.Info();
         Dictionary <string, object> parameters = AuxSalidaSacrificioDAL.ObtenerParametrosCrear(info);
         //int result = Create("SalidaSacrificio_Crear", parameters);
         using (var connection = new SqlConnection(this.ConnectionString))
         {
             var command = new SqlCommand("SalidaSacrificio_Crear", connection);
             foreach (var param in parameters)
             {
                 IDbDataParameter parameter = new SqlParameter(string.Format("{0}", param.Key), param.Value ?? DBNull.Value);
                 command.Parameters.Add(parameter);
             }
             command.Connection.Open();
             command.ExecuteNonQuery();
         }
     }
     catch (SqlException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (DataException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Пример #2
0
        public bool CrearLista(IList <SalidaSacrificioInfo> salidaSacrificio, string conexion)
        {
            var result = false;

            try
            {
                Logger.Info();
                using (var connection = new SqlConnection(conexion))
                {
                    connection.Open();
                    var command = new SqlCommand("SalidaSacrificio_Crear", connection);
                    command.CommandType = CommandType.StoredProcedure;

                    foreach (var salida in salidaSacrificio.GroupBy(e => e.NUM_CORR))
                    {
                        var corralSacrificar = salida.FirstOrDefault();
                        command.Parameters.Clear();
                        Dictionary <string, object> parameters = AuxSalidaSacrificioDAL.ObtenerParametrosCrear(corralSacrificar);
                        foreach (var param in parameters)
                        {
                            IDbDataParameter parameter = new SqlParameter(string.Format("{0}", param.Key), param.Value ?? DBNull.Value);
                            command.Parameters.Add(parameter);
                        }
                        command.ExecuteNonQuery();
                    }
                }
                result = true;
            }
            catch (SqlException ex)
            {
                if (ex.Message.Contains("Violation of PRIMARY KEY constraint 'PK_ConfiguracionVisceraCorral'"))
                {
                }
                Logger.Error(ex);
            }
            catch (DataException ex)
            {
                Logger.Error(ex);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            return(result);
        }