Beispiel #1
0
    public ErrorAppRemax Add(Client client)
    {
        ErrorAppRemax err = new ErrorAppRemax();

        if (_list.ContainsKey(client.ClientId))
        {
            err.ErrorCode    = -1;
            err.ErrorMessage = "There is another Client with this same Client Id.";
            return(err);
        }

        // result is the number of affected rows.
        int result = DataSource.AddClient(client.FirstName, client.LastName, client.BirthDate,
                                          client.Email, client.Phone, (int)client.ClientType, client.Agent.EmployeeId);

        // Any error occurred?
        if (DataSource.ErrorCode() != 0)
        {
            err.ErrorCode    = DataSource.ErrorCode();
            err.ErrorMessage = DataSource.ErrorMessage();
            return(err);
        }

        if (result == 1)
        {
            // If the adding works fine only one row should be affected.

            // Reloading _list.
            LoadClients();

            return(err);
        }
        else
        {
            err.ErrorCode    = -1;
            err.ErrorMessage = "The add operation was not successful (" + result.ToString() + " rows affected). Please check the database.";
            return(err);
        }
    }