Exemplo n.º 1
0
        public Producer AddProducer(Producer producer, string spName, string providerName, string connectionString)
        {
            try
            {
                var parameters  = RepositoryHelper.CreateProducerSqlParameters(producer);
                var paramsArray = parameters.ToArray();

                string storedProcedure = MasterDataManager.ConfigData["AddProducer"];
                using (SqlConnection connection = (SqlConnection)RepositoryHelper.OpenConnection(providerName, connectionString))
                {
                    try
                    {
                        var sqlCommand = new SqlCommand()
                        {
                            Connection  = connection,
                            CommandText = storedProcedure,
                            CommandType = CommandType.StoredProcedure
                        };
                        sqlCommand.Parameters.AddRange(paramsArray);
                        sqlCommand.ExecuteNonQuery();
                        producer.ProducerID = Convert.ToInt32((paramsArray.FirstOrDefault(a => a.ParameterName == "@ProducerID").Value.ToString()));
                    }
                    catch (System.Exception ex)
                    {
                        throw;
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw;
            }

            return(producer);
        }