Ejemplo n.º 1
0
    public static RegistrationResult WriteData(List <RegistrationEntry> data, List <Email> emails,
                                               string payerEmail, float amountToPay, float donation, int idCurrency, bool needHelp)
    {
        var success   = false;
        var badEmails = new List <string>();

        try
        {
            using (var transaction = new TransactionScope())
            {
                using (var sqlConnection = new SqlConnection(ConnectionString))
                {
                    using (var command = sqlConnection.CreateCommand())
                    {
                        command.PrepareStoredProcedure(sqlConnection, "AddUsers4");
                        command.AddParameterUserDefined("@users", "dbo.ListOfUsers", RegistrationEntry.GetDataTable(data));
                        command.AddParameterUserDefined("@emails", "dbo.ListOfEmails", Email.GetDataTable(emails));
                        command.AddParameterString("@payerEmail", payerEmail);
                        command.AddParameterFloat("@amount", amountToPay);
                        command.AddParameterFloat("@donation", donation);
                        command.AddParameterInt("@idCurrency", idCurrency);
                        command.AddParameterBool("@needHelp", needHelp);

                        sqlConnection.Open();

                        using (var reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                success = reader.GetInt32(0) > 0;
                            }
                            reader.NextResult();

                            if (!success)
                            {
                                while (reader.Read())
                                {
                                    badEmails.Add(reader.GetString(0));
                                }
                            }
                        }
                    }
                }
                transaction.Complete();
            }
        }
        catch (Exception ex)
        {
        }
        return(new RegistrationResult
        {
            Success = success,
            AlreadyRegisteredEmails = badEmails
        });
    }
Ejemplo n.º 2
0
    public static RegistrationResult WriteData(List <RegistrationEntry> data, List <Email> emails,
                                               string payerEmail, float donation, CurrencyInfo currency)
    {
        var success   = false;
        var badEmails = new List <string>();

        using (var transaction = new TransactionScope())
        {
            using (var connection = CreateConnection())
            {
                using (var command = CreateCommand(connection, "AddUsers4"))
                {
                    command.AddParameterUserDefined("@users", "dbo.ListOfUsers4", RegistrationEntry.GetDataTable(data));
                    command.AddParameterUserDefined("@emails", "dbo.ListOfEmails", Email.GetDataTable(emails));
                    command.AddParameterString("@payerEmail", payerEmail);
                    command.AddParameterFloat("@donation", donation);
                    command.AddParameterInt("@idCurrency", currency.Id);

                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            success = reader.GetInt32(0) > 0;
                        }
                        reader.NextResult();

                        if (!success)
                        {
                            while (reader.Read())
                            {
                                badEmails.Add(reader.GetString(0));
                            }
                        }
                    }
                }
            }
            transaction.Complete();
        }

        return(new RegistrationResult
        {
            Success = success,
            AlreadyRegisteredEmails = badEmails
        });
    }