Beispiel #1
0
        public Actor AddActor(Actor actor, string spName, string providerName, string connectionString)
        {
            try
            {
                var parameters  = RepositoryHelper.CreateActorSqlParameters(actor);
                var paramsArray = parameters.ToArray();

                string storedProcedure = MasterDataManager.ConfigData["AddActor"];
                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();
                        actor.ActorID = Convert.ToInt32((paramsArray.FirstOrDefault(a => a.ParameterName == "@ActorID").Value.ToString()));
                    }
                    catch (System.Exception ex)
                    {
                        throw;
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw;
            }

            return(actor);
        }