Ejemplo n.º 1
0
        protected override Product LoadInternal(ISqlConnectionInfo connection, int id)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT " +
                             ProductTable.GetColumnNames("[p]") +
                             (this.Depth > 0 ? "," + InstanceTable.GetColumnNames("[p_i]") : string.Empty) +
                             " FROM [core].[Product] AS [p] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [p_i] ON [p].[InstanceID] = [p_i].[InstanceID] ";
                }
                sqlCmdText += "WHERE [p].[ProductID] = @ProductID;";

                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                sqlCmd.Parameters.AddWithValue("@ProductID", id);
                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("p", "loadinternal", "notfound"), "Product could not be loaded by id as it was not found.", sqlCmdText, this, connection, id);
                    if (this.Logger.IsWarnEnabled)
                    {
                        this.Logger.Warn(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ProductTable  pTable   = new ProductTable(query);
                InstanceTable p_iTable = (this.Depth > 0) ? new InstanceTable(query) : null;


                Instance p_iObject = (this.Depth > 0) ? p_iTable.CreateInstance() : null;
                Product  pObject   = pTable.CreateInstance(p_iObject);
                sqlReader.Close();

                return(pObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("p", "loadinternal", "exception"), "Product could not be loaded by id. See exception for details.", sqlCmdText, ex, this, connection, id);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "Product", "Exception while loading Product object from database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 2
0
        protected override Country LoadInternal(ISqlConnectionInfo connection, int id)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT " +
                             CountryTable.GetColumnNames("[c]") +
                             (this.Depth > 0 ? "," + LanguageTable.GetColumnNames("[c_l]") : string.Empty) +
                             " FROM [core].[Country] AS [c] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [c_l] ON [c].[LanguageID] = [c_l].[LanguageID] ";
                }
                sqlCmdText += "WHERE [c].[CountryID] = @CountryID;";

                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                sqlCmd.Parameters.AddWithValue("@CountryID", id);
                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("c", "loadinternal", "notfound"), "Country could not be loaded by id as it was not found.", sqlCmdText, this, connection, id);
                    if (this.Logger.IsWarnEnabled)
                    {
                        this.Logger.Warn(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                CountryTable  cTable   = new CountryTable(query);
                LanguageTable c_lTable = (this.Depth > 0) ? new LanguageTable(query) : null;


                Language c_lObject = (this.Depth > 0) ? c_lTable.CreateInstance() : null;
                Country  cObject   = cTable.CreateInstance(c_lObject);
                sqlReader.Close();

                return(cObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("c", "loadinternal", "exception"), "Country could not be loaded by id. See exception for details.", sqlCmdText, ex, this, connection, id);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "Country", "Exception while loading Country object from database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 3
0
        protected override ReportLink LoadInternal(ISqlConnectionInfo connection, int id)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT " +
                             ReportLinkTable.GetColumnNames("[rl]") +
                             (this.Depth > 0 ? "," + ReportLinkGroupTable.GetColumnNames("[rl_rlg]") : string.Empty) +
                             " FROM [core].[ReportLink] AS [rl] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ReportLinkGroup] AS [rl_rlg] ON [rl].[ReportLinkGroupID] = [rl_rlg].[ReportLinkGroupID] ";
                }
                sqlCmdText += "WHERE [rl].[ReportLinkID] = @ReportLinkID;";

                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                sqlCmd.Parameters.AddWithValue("@ReportLinkID", id);
                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rl", "loadinternal", "notfound"), "ReportLink could not be loaded by id as it was not found.", sqlCmdText, this, connection, id);
                    if (this.Logger.IsWarnEnabled)
                    {
                        this.Logger.Warn(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ReportLinkTable      rlTable     = new ReportLinkTable(query);
                ReportLinkGroupTable rl_rlgTable = (this.Depth > 0) ? new ReportLinkGroupTable(query) : null;


                ReportLinkGroup rl_rlgObject = (this.Depth > 0) ? rl_rlgTable.CreateInstance() : null;
                ReportLink      rlObject     = rlTable.CreateInstance(rl_rlgObject);
                sqlReader.Close();

                return(rlObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rl", "loadinternal", "exception"), "ReportLink could not be loaded by id. See exception for details.", sqlCmdText, ex, this, connection, id);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "ReportLink", "Exception while loading ReportLink object from database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 4
0
        public override bool Update(ISqlConnectionInfo connection, ActionContextGroup data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                data.Updated = DateTime.Now;
                sqlCmdText   = "UPDATE [core].[ActionContextGroup] SET " +
                               "[Name] = @Name, " +
                               "[Updated] = GETDATE() " +
                               "WHERE [ActionContextGroupID] = @ActionContextGroupID;";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@Name", !string.IsNullOrEmpty(data.Name) ? (object)data.Name : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Updated", data.Updated).SqlDbType = SqlDbType.DateTime2;
                sqlCmd.Parameters.AddWithValue("@ActionContextGroupID", data.ID);

                int rowCount = sqlCmd.ExecuteNonQuery();
                if (rowCount < 1)
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("acg", "update", "norecord"), "ActionContextGroup could not be updated as no matching record was found.", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Update, "ActionContextGroup", "Exception while updating ActionContextGroup object in database. No record found for this id.");
                }
                else if (rowCount > 1)
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("acg", "update", "morerecords"), "ActionContextGroup was updated but there was more than one record affected.", sqlCmdText, this, connection, data);
                    if (this.Logger.IsFatalEnabled)
                    {
                        this.Logger.Fatal(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Update, "ActionContextGroup", "Exception while updating ActionContextGroup object in database. More than one record found for this statement (update statement where clause broken?!).");
                }
                return(true);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("acg", "update", "exception"), "ActionContextGroup could not be updated. See exception for details", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Update, "ActionContextGroup", "Exception while updating ActionContextGroup object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 5
0
        public override int?Insert(ISqlConnectionInfo connection, Message data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [stats].[Message] ([MessageGuid],[ExternalID],[ServiceID],[CustomerID],[MobileOperatorName],[MobileOperatorID],[MessageDirectionID],[MessageTypeID],[MessageStatusID],[Text],[Shorcode],[Keyword],[TrackingID]) VALUES(@MessageGuid,@ExternalID,@ServiceID,@CustomerID,@MobileOperatorName,@MobileOperatorID,@MessageDirectionID,@MessageTypeID,@MessageStatusID,@Text,@Shorcode,@Keyword,@TrackingID); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@MessageGuid", data.Guid);
                sqlCmd.Parameters.AddWithValue("@ExternalID", data.ExternalID.HasValue ? (object)data.ExternalID.Value : DBNull.Value).SqlDbType = SqlDbType.Int;
                sqlCmd.Parameters.AddWithValue("@ServiceID", data.Service.ID);
                sqlCmd.Parameters.AddWithValue("@CustomerID", data.Customer == null ? DBNull.Value : (object)data.Customer.ID);
                sqlCmd.Parameters.AddWithValue("@MobileOperatorName", !string.IsNullOrEmpty(data.MobileOperatorName) ? (object)data.MobileOperatorName : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@MobileOperatorID", data.MobileOperator == null ? DBNull.Value : (object)data.MobileOperator.ID);
                sqlCmd.Parameters.AddWithValue("@MessageDirectionID", (int)data.MessageDirection);
                sqlCmd.Parameters.AddWithValue("@MessageTypeID", (int)data.MessageType);
                sqlCmd.Parameters.AddWithValue("@MessageStatusID", (int)data.MessageStatus);
                sqlCmd.Parameters.AddWithValue("@Text", !string.IsNullOrEmpty(data.Text) ? (object)data.Text : DBNull.Value).SqlDbType           = SqlDbType.NText;
                sqlCmd.Parameters.AddWithValue("@Shorcode", data.Shorcode.HasValue ? (object)data.Shorcode.Value : DBNull.Value).SqlDbType       = SqlDbType.Int;
                sqlCmd.Parameters.AddWithValue("@Keyword", !string.IsNullOrEmpty(data.Keyword) ? (object)data.Keyword : DBNull.Value).SqlDbType  = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@TrackingID", data.TrackingID.HasValue ? (object)data.TrackingID.Value : DBNull.Value).SqlDbType = SqlDbType.Int;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("m", "insert", "noprimarykey"), "Message could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "Message", "Exception while inserting Message object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("m", "insert", "exception"), "Message could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "Message", "Exception while inserting Message object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 6
0
        public override int?Insert(ISqlConnectionInfo connection, Service data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[Service] ([ServiceGuid],[ApplicationID],[ProductID],[MerchantID],[ServiceStatusID],[ServiceTypeID],[UserSessionTypeID],[FallbackCountryID],[FallbackLanguageID],[ServiceConfigurationID],[TemplateID],[Name],[Description]) VALUES(@ServiceGuid,@ApplicationID,@ProductID,@MerchantID,@ServiceStatusID,@ServiceTypeID,@UserSessionTypeID,@FallbackCountryID,@FallbackLanguageID,@ServiceConfigurationID,@TemplateID,@Name,@Description); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@ServiceGuid", data.Guid);
                sqlCmd.Parameters.AddWithValue("@ApplicationID", data.Application.ID);
                sqlCmd.Parameters.AddWithValue("@ProductID", data.Product.ID);
                sqlCmd.Parameters.AddWithValue("@MerchantID", data.Merchant.ID);
                sqlCmd.Parameters.AddWithValue("@ServiceStatusID", (int)data.ServiceStatus);
                sqlCmd.Parameters.AddWithValue("@ServiceTypeID", data.ServiceType.ID);
                sqlCmd.Parameters.AddWithValue("@UserSessionTypeID", data.UserSessionType.ID);
                sqlCmd.Parameters.AddWithValue("@FallbackCountryID", data.FallbackCountry.ID);
                sqlCmd.Parameters.AddWithValue("@FallbackLanguageID", data.FallbackLanguage.ID);
                sqlCmd.Parameters.AddWithValue("@ServiceConfigurationID", data.ServiceConfiguration.ID);
                sqlCmd.Parameters.AddWithValue("@TemplateID", data.Template.ID);
                sqlCmd.Parameters.AddWithValue("@Name", data.Name).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Description", data.Description).SqlDbType = SqlDbType.NText;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("s", "insert", "noprimarykey"), "Service could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "Service", "Exception while inserting Service object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("s", "insert", "exception"), "Service could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "Service", "Exception while inserting Service object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 7
0
        protected override CallbackReport LoadInternal(ISqlConnectionInfo connection, int id)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT " +
                             CallbackReportTable.GetColumnNames("[cr]") +
                             " FROM [core].[CallbackReport] AS [cr] ";
                sqlCmdText += "WHERE [cr].[CallbackReportID] = @CallbackReportID;";

                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                sqlCmd.Parameters.AddWithValue("@CallbackReportID", id);
                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("cr", "loadinternal", "notfound"), "CallbackReport could not be loaded by id as it was not found.", sqlCmdText, this, connection, id);
                    if (this.Logger.IsWarnEnabled)
                    {
                        this.Logger.Warn(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                CallbackReportTable crTable = new CallbackReportTable(query);


                CallbackReport crObject = crTable.CreateInstance();
                sqlReader.Close();

                return(crObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("cr", "loadinternal", "exception"), "CallbackReport could not be loaded by id. See exception for details.", sqlCmdText, ex, this, connection, id);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "CallbackReport", "Exception while loading CallbackReport object from database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 8
0
        public override int?Insert(ISqlConnectionInfo connection, MTMessage data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [stats].[MTMessage] ([MessageID],[AppID],[To],[MsgID],[Time],[State],[Error],[ReasonCode],[Retry],[AppMsgID]) VALUES(@MessageID,@AppID,@To,@MsgID,@Time,@State,@Error,@ReasonCode,@Retry,@AppMsgID); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@MessageID", data.Message.ID);
                sqlCmd.Parameters.AddWithValue("@AppID", !string.IsNullOrEmpty(data.AppID) ? (object)data.AppID : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@To", !string.IsNullOrEmpty(data.To) ? (object)data.To : DBNull.Value).SqlDbType          = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@MsgID", !string.IsNullOrEmpty(data.MsgID) ? (object)data.MsgID : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Time", !string.IsNullOrEmpty(data.Time) ? (object)data.Time : DBNull.Value).SqlDbType    = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@State", !string.IsNullOrEmpty(data.State) ? (object)data.State : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Error", !string.IsNullOrEmpty(data.Error) ? (object)data.Error : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@ReasonCode", !string.IsNullOrEmpty(data.ReasonCode) ? (object)data.ReasonCode : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Retry", !string.IsNullOrEmpty(data.Retry) ? (object)data.Retry : DBNull.Value).SqlDbType          = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@AppMsgID", !string.IsNullOrEmpty(data.AppMsgID) ? (object)data.AppMsgID : DBNull.Value).SqlDbType = SqlDbType.NVarChar;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mtm", "insert", "noprimarykey"), "MTMessage could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "MTMessage", "Exception while inserting MTMessage object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mtm", "insert", "exception"), "MTMessage could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "MTMessage", "Exception while inserting MTMessage object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 9
0
        public override int?Insert(ISqlConnectionInfo connection, Route data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[Route] ([RouteSetID],[Name],[Action],[Controller],[Pattern],[IsIgnore],[IsEnabled],[Index],[IsSessionRoute]) VALUES(@RouteSetID,@Name,@Action,@Controller,@Pattern,@IsIgnore,@IsEnabled,@Index,@IsSessionRoute); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@RouteSetID", data.RouteSet.ID);
                sqlCmd.Parameters.AddWithValue("@Name", data.Name).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Action", !string.IsNullOrEmpty(data.Action) ? (object)data.Action : DBNull.Value).SqlDbType             = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Controller", !string.IsNullOrEmpty(data.Controller) ? (object)data.Controller : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Pattern", data.Pattern).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@IsIgnore", data.IsIgnore.HasValue ? (object)data.IsIgnore.Value : DBNull.Value).SqlDbType    = SqlDbType.Bit;
                sqlCmd.Parameters.AddWithValue("@IsEnabled", data.IsEnabled.HasValue ? (object)data.IsEnabled.Value : DBNull.Value).SqlDbType = SqlDbType.Bit;
                sqlCmd.Parameters.AddWithValue("@Index", data.Index).SqlDbType = SqlDbType.Int;
                sqlCmd.Parameters.AddWithValue("@IsSessionRoute", data.IsSessionRoute).SqlDbType = SqlDbType.Bit;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("r", "insert", "noprimarykey"), "Route could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "Route", "Exception while inserting Route object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("r", "insert", "exception"), "Route could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "Route", "Exception while inserting Route object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 10
0
        public override int?Insert(ISqlConnectionInfo connection, UserDetail data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[UserDetail] ([UserID],[CountryID],[GenderID],[FirstName],[LastName],[Address],[Mail],[Contact],[BirthDate]) VALUES(@UserID,@CountryID,@GenderID,@FirstName,@LastName,@Address,@Mail,@Contact,@BirthDate); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@UserID", data.User.ID);
                sqlCmd.Parameters.AddWithValue("@CountryID", data.CountryID).SqlDbType = SqlDbType.Int;
                sqlCmd.Parameters.AddWithValue("@GenderID", data.Gender.ID);
                sqlCmd.Parameters.AddWithValue("@FirstName", data.FirstName).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@LastName", data.LastName).SqlDbType   = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Address", !string.IsNullOrEmpty(data.Address) ? (object)data.Address : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Mail", data.Mail).SqlDbType       = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Contact", data.Contact).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@BirthDate", data.BirthDate.HasValue ? (object)data.BirthDate.Value : DBNull.Value).SqlDbType = SqlDbType.DateTime2;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ud", "insert", "noprimarykey"), "UserDetail could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "UserDetail", "Exception while inserting UserDetail object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ud", "insert", "exception"), "UserDetail could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "UserDetail", "Exception while inserting UserDetail object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 11
0
        public override int?Insert(ISqlConnectionInfo connection, Country data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[Country] ([LanguageID],[GlobalName],[LocalName],[CountryCode],[CultureCode],[TwoLetterIsoCode],[LCID],[CallingCode]) VALUES(@LanguageID,@GlobalName,@LocalName,@CountryCode,@CultureCode,@TwoLetterIsoCode,@LCID,@CallingCode); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@LanguageID", data.Language == null ? DBNull.Value : (object)data.Language.ID);
                sqlCmd.Parameters.AddWithValue("@GlobalName", data.GlobalName).SqlDbType             = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@LocalName", data.LocalName).SqlDbType               = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@CountryCode", data.CountryCode).SqlDbType           = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@CultureCode", data.CultureCode).SqlDbType           = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@TwoLetterIsoCode", data.TwoLetterIsoCode).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@LCID", data.LCID.HasValue ? (object)data.LCID.Value : DBNull.Value).SqlDbType = SqlDbType.Int;
                sqlCmd.Parameters.AddWithValue("@CallingCode", data.CallingCode.HasValue ? (object)data.CallingCode.Value : DBNull.Value).SqlDbType = SqlDbType.Int;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("c", "insert", "noprimarykey"), "Country could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "Country", "Exception while inserting Country object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("c", "insert", "exception"), "Country could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "Country", "Exception while inserting Country object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 12
0
        public override int?Insert(ISqlConnectionInfo connection, Merchant data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[Merchant] ([InstanceID],[TemplateID],[Name],[Address],[Phone],[Email],[RegistrationNo],[VatNo]) VALUES(@InstanceID,@TemplateID,@Name,@Address,@Phone,@Email,@RegistrationNo,@VatNo); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@InstanceID", data.Instance.ID);
                sqlCmd.Parameters.AddWithValue("@TemplateID", data.Template == null ? DBNull.Value : (object)data.Template.ID);
                sqlCmd.Parameters.AddWithValue("@Name", data.Name).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Address", !string.IsNullOrEmpty(data.Address) ? (object)data.Address : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Phone", !string.IsNullOrEmpty(data.Phone) ? (object)data.Phone : DBNull.Value).SqlDbType       = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Email", !string.IsNullOrEmpty(data.Email) ? (object)data.Email : DBNull.Value).SqlDbType       = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@RegistrationNo", !string.IsNullOrEmpty(data.RegistrationNo) ? (object)data.RegistrationNo : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@VatNo", !string.IsNullOrEmpty(data.VatNo) ? (object)data.VatNo : DBNull.Value).SqlDbType = SqlDbType.NVarChar;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("m", "insert", "noprimarykey"), "Merchant could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "Merchant", "Exception while inserting Merchant object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("m", "insert", "exception"), "Merchant could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "Merchant", "Exception while inserting Merchant object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 13
0
        public override int?Insert(ISqlConnectionInfo connection, Customer data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[Customer] ([CustomerGuid],[UserID],[ServiceID],[CountryID],[LanguageID],[MobileOperatorID],[Msisdn],[EncryptedMsisdn]) VALUES(@CustomerGuid,@UserID,@ServiceID,@CountryID,@LanguageID,@MobileOperatorID,@Msisdn,@EncryptedMsisdn); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@CustomerGuid", data.Guid);
                sqlCmd.Parameters.AddWithValue("@UserID", data.User == null ? DBNull.Value : (object)data.User.ID);
                sqlCmd.Parameters.AddWithValue("@ServiceID", data.Service.ID);
                sqlCmd.Parameters.AddWithValue("@CountryID", data.Country.ID);
                sqlCmd.Parameters.AddWithValue("@LanguageID", data.Language == null ? DBNull.Value : (object)data.Language.ID);
                sqlCmd.Parameters.AddWithValue("@MobileOperatorID", data.MobileOperator == null ? DBNull.Value : (object)data.MobileOperator.ID);
                sqlCmd.Parameters.AddWithValue("@Msisdn", !string.IsNullOrEmpty(data.Msisdn) ? (object)data.Msisdn : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@EncryptedMsisdn", !string.IsNullOrEmpty(data.EncryptedMsisdn) ? (object)data.EncryptedMsisdn : DBNull.Value).SqlDbType = SqlDbType.NVarChar;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("c", "insert", "noprimarykey"), "Customer could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "Customer", "Exception while inserting Customer object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("c", "insert", "exception"), "Customer could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "Customer", "Exception while inserting Customer object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 14
0
        public override int?Insert(ISqlConnectionInfo connection, ServiceConfigurationEntry data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[ServiceConfigurationEntry] ([ServiceConfigurationID],[CountryID],[MobileOperatorID],[Shortcode],[Keyword],[IsAgeVerificationRequired],[IsActive]) VALUES(@ServiceConfigurationID,@CountryID,@MobileOperatorID,@Shortcode,@Keyword,@IsAgeVerificationRequired,@IsActive); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@ServiceConfigurationID", data.ServiceConfiguration.ID);
                sqlCmd.Parameters.AddWithValue("@CountryID", data.CountryID).SqlDbType = SqlDbType.Int;
                sqlCmd.Parameters.AddWithValue("@MobileOperatorID", data.MobileOperatorID.HasValue ? (object)data.MobileOperatorID.Value : DBNull.Value).SqlDbType = SqlDbType.Int;
                sqlCmd.Parameters.AddWithValue("@Shortcode", data.Shortcode).SqlDbType = SqlDbType.Int;
                sqlCmd.Parameters.AddWithValue("@Keyword", data.Keyword).SqlDbType     = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@IsAgeVerificationRequired", data.IsAgeVerificationRequired).SqlDbType = SqlDbType.Bit;
                sqlCmd.Parameters.AddWithValue("@IsActive", data.IsActive).SqlDbType = SqlDbType.Bit;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("sce", "insert", "noprimarykey"), "ServiceConfigurationEntry could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "ServiceConfigurationEntry", "Exception while inserting ServiceConfigurationEntry object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("sce", "insert", "exception"), "ServiceConfigurationEntry could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "ServiceConfigurationEntry", "Exception while inserting ServiceConfigurationEntry object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 15
0
        public override int?Insert(ISqlConnectionInfo connection, Transaction data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[Transaction] ([TransactionGuid],[ExternalTransactionGuid],[ExternalPurchaseGuid],[ExternalTransactionGroupGuid],[TransactionStatusID],[TransactionTypeID]) VALUES(@TransactionGuid,@ExternalTransactionGuid,@ExternalPurchaseGuid,@ExternalTransactionGroupGuid,@TransactionStatusID,@TransactionTypeID); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@TransactionGuid", data.Guid);
                sqlCmd.Parameters.AddWithValue("@ExternalTransactionGuid", data.ExternalTransactionGuid);
                sqlCmd.Parameters.AddWithValue("@ExternalPurchaseGuid", data.ExternalPurchaseGuid);
                sqlCmd.Parameters.AddWithValue("@ExternalTransactionGroupGuid", data.ExternalTransactionGroupGuid);
                sqlCmd.Parameters.AddWithValue("@TransactionStatusID", (int)data.TransactionStatus);
                sqlCmd.Parameters.AddWithValue("@TransactionTypeID", (int)data.TransactionType);

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("t", "insert", "noprimarykey"), "Transaction could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "Transaction", "Exception while inserting Transaction object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("t", "insert", "exception"), "Transaction could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "Transaction", "Exception while inserting Transaction object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 16
0
        public override int?Insert(ISqlConnectionInfo connection, PaymentConfiguration data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[PaymentConfiguration] ([PaymentCredentialsID],[PaymentInterfaceID],[PaymentProviderID],[BehaviorModelID],[Name]) VALUES(@PaymentCredentialsID,@PaymentInterfaceID,@PaymentProviderID,@BehaviorModelID,@Name); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@PaymentCredentialsID", data.PaymentCredentials.ID);
                sqlCmd.Parameters.AddWithValue("@PaymentInterfaceID", data.PaymentInterface.ID);
                sqlCmd.Parameters.AddWithValue("@PaymentProviderID", data.PaymentProvider.ID);
                sqlCmd.Parameters.AddWithValue("@BehaviorModelID", data.BehaviorModel.ID);
                sqlCmd.Parameters.AddWithValue("@Name", data.Name).SqlDbType = SqlDbType.NVarChar;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pc", "insert", "noprimarykey"), "PaymentConfiguration could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "PaymentConfiguration", "Exception while inserting PaymentConfiguration object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pc", "insert", "exception"), "PaymentConfiguration could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "PaymentConfiguration", "Exception while inserting PaymentConfiguration object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 17
0
        public override int?Insert(ISqlConnectionInfo connection, TranslationKey data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[TranslationKey] ([FallbackTranslationKeyID],[TranslationID],[LanguageID],[ServiceID],[Name]) VALUES(@FallbackTranslationKeyID,@TranslationID,@LanguageID,@ServiceID,@Name); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@FallbackTranslationKeyID", data.FallbackTranslationKey == null ? DBNull.Value : (object)data.FallbackTranslationKey.ID);
                sqlCmd.Parameters.AddWithValue("@TranslationID", data.Translation.ID);
                sqlCmd.Parameters.AddWithValue("@LanguageID", data.Language == null ? DBNull.Value : (object)data.Language.ID);
                sqlCmd.Parameters.AddWithValue("@ServiceID", data.Service == null ? DBNull.Value : (object)data.Service.ID);
                sqlCmd.Parameters.AddWithValue("@Name", data.Name).SqlDbType = SqlDbType.NVarChar;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tk", "insert", "noprimarykey"), "TranslationKey could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "TranslationKey", "Exception while inserting TranslationKey object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tk", "insert", "exception"), "TranslationKey could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "TranslationKey", "Exception while inserting TranslationKey object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 18
0
        public override int?Insert(ISqlConnectionInfo connection, RouteParameter data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[RouteParameter] ([RouteID],[Key],[Value],[Constraint],[IsOptional]) VALUES(@RouteID,@Key,@Value,@Constraint,@IsOptional); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@RouteID", data.Route.ID);
                sqlCmd.Parameters.AddWithValue("@Key", data.Key).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Value", !string.IsNullOrEmpty(data.Value) ? (object)data.Value : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Constraint", !string.IsNullOrEmpty(data.Constraint) ? (object)data.Constraint : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@IsOptional", data.IsOptional).SqlDbType = SqlDbType.Bit;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rp", "insert", "noprimarykey"), "RouteParameter could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "RouteParameter", "Exception while inserting RouteParameter object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rp", "insert", "exception"), "RouteParameter could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "RouteParameter", "Exception while inserting RouteParameter object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 19
0
        public override int?Insert(ISqlConnectionInfo connection, Product data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[Product] ([InstanceID],[ProductGuid],[ExternalProductGuid],[Name],[Description]) VALUES(@InstanceID,@ProductGuid,@ExternalProductGuid,@Name,@Description); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@InstanceID", data.Instance.ID);
                sqlCmd.Parameters.AddWithValue("@ProductGuid", data.Guid);
                sqlCmd.Parameters.AddWithValue("@ExternalProductGuid", data.ExternalProductGuid);
                sqlCmd.Parameters.AddWithValue("@Name", data.Name).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Description", !string.IsNullOrEmpty(data.Description) ? (object)data.Description : DBNull.Value).SqlDbType = SqlDbType.NText;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("p", "insert", "noprimarykey"), "Product could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "Product", "Exception while inserting Product object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("p", "insert", "exception"), "Product could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "Product", "Exception while inserting Product object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 20
0
        public override int?Insert(ISqlConnectionInfo connection, IPCountryMap data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[IPCountryMap] ([FromAddress],[ToAddress],[TwoLetterIsoCode],[CountryID]) VALUES(@FromAddress,@ToAddress,@TwoLetterIsoCode,@CountryID); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@FromAddress", data.FromAddress).SqlDbType           = SqlDbType.BigInt;
                sqlCmd.Parameters.AddWithValue("@ToAddress", data.ToAddress).SqlDbType               = SqlDbType.BigInt;
                sqlCmd.Parameters.AddWithValue("@TwoLetterIsoCode", data.TwoLetterIsoCode).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@CountryID", data.Country == null ? DBNull.Value : (object)data.Country.ID);

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ipcm", "insert", "noprimarykey"), "IPCountryMap could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "IPCountryMap", "Exception while inserting IPCountryMap object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ipcm", "insert", "exception"), "IPCountryMap could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "IPCountryMap", "Exception while inserting IPCountryMap object in database. See inner exception for details.", ex);
            }
        }
        public override int?Insert(ISqlConnectionInfo connection, MobileOperatorCode data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[MobileOperatorCode] ([MobileOperatorID],[MCC],[MNC],[IsDefault]) VALUES(@MobileOperatorID,@MCC,@MNC,@IsDefault); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@MobileOperatorID", data.MobileOperator.ID);
                sqlCmd.Parameters.AddWithValue("@MCC", data.MCC).SqlDbType             = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@MNC", data.MNC).SqlDbType             = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@IsDefault", data.IsDefault).SqlDbType = SqlDbType.Bit;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("moc", "insert", "noprimarykey"), "MobileOperatorCode could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "MobileOperatorCode", "Exception while inserting MobileOperatorCode object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("moc", "insert", "exception"), "MobileOperatorCode could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "MobileOperatorCode", "Exception while inserting MobileOperatorCode object in database. See inner exception for details.", ex);
            }
        }
        public override int?Insert(ISqlConnectionInfo connection, ServiceSendNumberMap data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[ServiceSendNumberMap] ([ServiceID],[SendNumberTypeID],[Messages],[IsActive]) VALUES(@ServiceID,@SendNumberTypeID,@Messages,@IsActive); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@ServiceID", data.Service.ID);
                sqlCmd.Parameters.AddWithValue("@SendNumberTypeID", data.SendNumberType.ID);
                sqlCmd.Parameters.AddWithValue("@Messages", !string.IsNullOrEmpty(data.Messages) ? (object)data.Messages : DBNull.Value).SqlDbType = SqlDbType.NText;
                sqlCmd.Parameters.AddWithValue("@IsActive", data.IsActive).SqlDbType = SqlDbType.Bit;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ssnm", "insert", "noprimarykey"), "ServiceSendNumberMap could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "ServiceSendNumberMap", "Exception while inserting ServiceSendNumberMap object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ssnm", "insert", "exception"), "ServiceSendNumberMap could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "ServiceSendNumberMap", "Exception while inserting ServiceSendNumberMap object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 23
0
        public override int?Insert(ISqlConnectionInfo connection, Report data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[Report] ([ReportLinkID],[Pxid],[AdditionalData]) VALUES(@ReportLinkID,@Pxid,@AdditionalData); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@ReportLinkID", data.ReportLink.ID);
                sqlCmd.Parameters.AddWithValue("@Pxid", data.Pxid.HasValue ? (object)data.Pxid.Value : DBNull.Value).SqlDbType = SqlDbType.Int;
                sqlCmd.Parameters.AddWithValue("@AdditionalData", !string.IsNullOrEmpty(data.AdditionalData) ? (object)data.AdditionalData : DBNull.Value).SqlDbType = SqlDbType.NText;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("r", "insert", "noprimarykey"), "Report could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "Report", "Exception while inserting Report object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("r", "insert", "exception"), "Report could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "Report", "Exception while inserting Report object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 24
0
        public override bool Delete(ISqlConnectionInfo connection, CallbackReport data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "DELETE FROM [core].[CallbackReport] WHERE CallbackReportID = @CallbackReportID;";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                sqlCmd.Parameters.AddWithValue("@CallbackReportID", data.ID);

                int success = sqlCmd.ExecuteNonQuery();

                if (success == -1)
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("cr", "delete", "norecord"), "CallbackReport could not be deleted as no matching record was found.", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Delete, "CallbackReport", "Exception while deleting CallbackReport object from database. No such record found.");
                }

                return(true);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("cr", "delete", "exception"), "CallbackReport could not be deleted. See exception for details", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Delete, "CallbackReport", "Exception while deleting CallbackReport object from database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 25
0
        public override int?Insert(ISqlConnectionInfo connection, CallbackReport data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "INSERT INTO [core].[CallbackReport] ([CallbackNotificationTypeID],[Url]) VALUES(@CallbackNotificationTypeID,@Url); SELECT SCOPE_IDENTITY();";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@CallbackNotificationTypeID", (int)data.CallbackNotificationType);
                sqlCmd.Parameters.AddWithValue("@Url", data.Url).SqlDbType = SqlDbType.NVarChar;

                object idObj = sqlCmd.ExecuteScalar();
                if (idObj == null || DBNull.Value.Equals(idObj))
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("cr", "insert", "noprimarykey"), "CallbackReport could not be inserted or inserted primary key was not returned. Are you missing SELECT SCOPE_IDENTITY();?", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Insert, "CallbackReport", "Exception while inserting CallbackReport object in database.");
                }
                return((int)((decimal)idObj));
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("cr", "insert", "exception"), "CallbackReport could not be inserted. See exception for details.", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Insert, "CallbackReport", "Exception while inserting CallbackReport object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 26
0
        public CallbackReport Load(ISqlConnectionInfo connection, SqlQueryParameters parameters)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT {0} " +
                             CallbackReportTable.GetColumnNames("[cr]") +
                             " FROM [core].[CallbackReport] AS [cr] ";


                parameters.Top = 1;
                sqlCmdText     = parameters.BuildQuery(sqlCmdText);
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                foreach (KeyValuePair <string, object> argument in parameters.Arguments)
                {
                    sqlCmd.Parameters.AddWithValue("@" + argument.Key, argument.Value);
                }

                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("cr", "customload", "notfound"), "CallbackReport could not be loaded using custom logic as it was not found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                CallbackReportTable crTable = new CallbackReportTable(query);


                CallbackReport crObject = crTable.CreateInstance();
                sqlReader.Close();

                return(crObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("cr", "customload", "exception"), "CallbackReport could not be loaded using custom logic. See exception for details.", sqlCmdText, ex, this, connection, parameters);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "CallbackReport", "Exception while loading (custom/single) CallbackReport object from database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 27
0
        public List <TranslationType> LoadMany(ISqlConnectionInfo connection, SqlQueryParameters parameters)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT {0} " +
                             TranslationTypeTable.GetColumnNames("[tt]") +
                             " FROM [core].[TranslationType] AS [tt] ";


                sqlCmdText = parameters.BuildQuery(sqlCmdText);
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                foreach (KeyValuePair <string, object> argument in parameters.Arguments)
                {
                    sqlCmd.Parameters.AddWithValue("@" + argument.Key, argument.Value);
                }

                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tt", "customloadmany", "notfound"), "TranslationType list could not be loaded using custom logic as no items were found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(new List <TranslationType>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                TranslationTypeTable ttTable = new TranslationTypeTable(query);

                List <TranslationType> result = new List <TranslationType>();
                do
                {
                    TranslationType ttObject = (this.Depth > -1) ? ttTable.CreateInstance() : null;
                    result.Add(ttObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tt", "customloadmany", "exception"), "TranslationType list could not be loaded using custom logic. See exception for details.", sqlCmdText, ex, this, connection, parameters);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "TranslationType", "Exception while loading (custom/many) TranslationType object from database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 28
0
        public override bool Update(ISqlConnectionInfo connection, MOMessage data)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string sqlCmdText = string.Empty;

            try
            {
                data.Updated = DateTime.Now;
                sqlCmdText   = "UPDATE [stats].[MOMessage] SET " +
                               "[MessageID] = @MessageID, " +
                               "[AppID] = @AppID, " +
                               "[From] = @From, " +
                               "[Operator] = @Operator, " +
                               "[To] = @To, " +
                               "[Keyword] = @Keyword, " +
                               "[Tariff] = @Tariff, " +
                               "[MessageText] = @MessageText, " +
                               "[SmsID] = @SmsID, " +
                               "[Updated] = GETDATE() " +
                               "WHERE [MOMessageID] = @MOMessageID;";
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;

                sqlCmd.Parameters.AddWithValue("@MessageID", data.Message.ID);
                sqlCmd.Parameters.AddWithValue("@AppID", !string.IsNullOrEmpty(data.AppID) ? (object)data.AppID : DBNull.Value).SqlDbType          = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@From", !string.IsNullOrEmpty(data.From) ? (object)data.From : DBNull.Value).SqlDbType             = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Operator", !string.IsNullOrEmpty(data.Operator) ? (object)data.Operator : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@To", !string.IsNullOrEmpty(data.To) ? (object)data.To : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Keyword", !string.IsNullOrEmpty(data.Keyword) ? (object)data.Keyword : DBNull.Value).SqlDbType             = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Tariff", !string.IsNullOrEmpty(data.Tariff) ? (object)data.Tariff : DBNull.Value).SqlDbType                = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@MessageText", !string.IsNullOrEmpty(data.MessageText) ? (object)data.MessageText : DBNull.Value).SqlDbType = SqlDbType.NText;
                sqlCmd.Parameters.AddWithValue("@SmsID", !string.IsNullOrEmpty(data.SmsID) ? (object)data.SmsID : DBNull.Value).SqlDbType = SqlDbType.NVarChar;
                sqlCmd.Parameters.AddWithValue("@Updated", data.Updated).SqlDbType = SqlDbType.DateTime2;
                sqlCmd.Parameters.AddWithValue("@MOMessageID", data.ID);

                int rowCount = sqlCmd.ExecuteNonQuery();
                if (rowCount < 1)
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mom", "update", "norecord"), "MOMessage could not be updated as no matching record was found.", sqlCmdText, this, connection, data);
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.Error(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Update, "MOMessage", "Exception while updating MOMessage object in database. No record found for this id.");
                }
                else if (rowCount > 1)
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mom", "update", "morerecords"), "MOMessage was updated but there was more than one record affected.", sqlCmdText, this, connection, data);
                    if (this.Logger.IsFatalEnabled)
                    {
                        this.Logger.Fatal(builder.ToString());
                    }
                    throw new DataOperationException(DataOperation.Update, "MOMessage", "Exception while updating MOMessage object in database. More than one record found for this statement (update statement where clause broken?!).");
                }
                return(true);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mom", "update", "exception"), "MOMessage could not be updated. See exception for details", sqlCmdText, ex, this, connection, data);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Update, "MOMessage", "Exception while updating MOMessage object in database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 29
0
        protected override MOMessage LoadInternal(ISqlConnectionInfo connection, int id)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT " +
                             MOMessageTable.GetColumnNames("[mom]") +
                             (this.Depth > 0 ? "," + MessageTable.GetColumnNames("[mom_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[mom_m_s]") : string.Empty) +
                             (this.Depth > 1 ? "," + CustomerTable.GetColumnNames("[mom_m_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + MobileOperatorTable.GetColumnNames("[mom_m_mo]") : string.Empty) +
                             " FROM [stats].[MOMessage] AS [mom] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [stats].[Message] AS [mom_m] ON [mom].[MessageID] = [mom_m].[MessageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Service] AS [mom_m_s] ON [mom_m].[ServiceID] = [mom_m_s].[ServiceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Customer] AS [mom_m_c] ON [mom_m].[CustomerID] = [mom_m_c].[CustomerID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[MobileOperator] AS [mom_m_mo] ON [mom_m].[MobileOperatorID] = [mom_m_mo].[MobileOperatorID] ";
                }
                sqlCmdText += "WHERE [mom].[MOMessageID] = @MOMessageID;";

                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                sqlCmd.Parameters.AddWithValue("@MOMessageID", id);
                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mom", "loadinternal", "notfound"), "MOMessage could not be loaded by id as it was not found.", sqlCmdText, this, connection, id);
                    if (this.Logger.IsWarnEnabled)
                    {
                        this.Logger.Warn(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                MOMessageTable      momTable      = new MOMessageTable(query);
                MessageTable        mom_mTable    = (this.Depth > 0) ? new MessageTable(query) : null;
                ServiceTable        mom_m_sTable  = (this.Depth > 1) ? new ServiceTable(query) : null;
                CustomerTable       mom_m_cTable  = (this.Depth > 1) ? new CustomerTable(query) : null;
                MobileOperatorTable mom_m_moTable = (this.Depth > 1) ? new MobileOperatorTable(query) : null;


                Service        mom_m_sObject  = (this.Depth > 1) ? mom_m_sTable.CreateInstance() : null;
                Customer       mom_m_cObject  = (this.Depth > 1) ? mom_m_cTable.CreateInstance() : null;
                MobileOperator mom_m_moObject = (this.Depth > 1) ? mom_m_moTable.CreateInstance() : null;
                Message        mom_mObject    = (this.Depth > 0) ? mom_mTable.CreateInstance(mom_m_sObject, mom_m_cObject, mom_m_moObject) : null;
                MOMessage      momObject      = momTable.CreateInstance(mom_mObject);
                sqlReader.Close();

                return(momObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mom", "loadinternal", "exception"), "MOMessage could not be loaded by id. See exception for details.", sqlCmdText, ex, this, connection, id);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "MOMessage", "Exception while loading MOMessage object from database. See inner exception for details.", ex);
            }
        }
Ejemplo n.º 30
0
        public List <MOMessage> LoadMany(ISqlConnectionInfo connection, SqlQueryParameters parameters)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT {0} " +
                             MOMessageTable.GetColumnNames("[mom]") +
                             (this.Depth > 0 ? "," + MessageTable.GetColumnNames("[mom_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[mom_m_s]") : string.Empty) +
                             (this.Depth > 1 ? "," + CustomerTable.GetColumnNames("[mom_m_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + MobileOperatorTable.GetColumnNames("[mom_m_mo]") : string.Empty) +
                             " FROM [stats].[MOMessage] AS [mom] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [stats].[Message] AS [mom_m] ON [mom].[MessageID] = [mom_m].[MessageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Service] AS [mom_m_s] ON [mom_m].[ServiceID] = [mom_m_s].[ServiceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Customer] AS [mom_m_c] ON [mom_m].[CustomerID] = [mom_m_c].[CustomerID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[MobileOperator] AS [mom_m_mo] ON [mom_m].[MobileOperatorID] = [mom_m_mo].[MobileOperatorID] ";
                }


                sqlCmdText = parameters.BuildQuery(sqlCmdText);
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                foreach (KeyValuePair <string, object> argument in parameters.Arguments)
                {
                    sqlCmd.Parameters.AddWithValue("@" + argument.Key, argument.Value);
                }

                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mom", "customloadmany", "notfound"), "MOMessage list could not be loaded using custom logic as no items were found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(new List <MOMessage>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                MOMessageTable      momTable      = new MOMessageTable(query);
                MessageTable        mom_mTable    = (this.Depth > 0) ? new MessageTable(query) : null;
                ServiceTable        mom_m_sTable  = (this.Depth > 1) ? new ServiceTable(query) : null;
                CustomerTable       mom_m_cTable  = (this.Depth > 1) ? new CustomerTable(query) : null;
                MobileOperatorTable mom_m_moTable = (this.Depth > 1) ? new MobileOperatorTable(query) : null;

                List <MOMessage> result = new List <MOMessage>();
                do
                {
                    Service        mom_m_sObject  = (this.Depth > 1) ? mom_m_sTable.CreateInstance() : null;
                    Customer       mom_m_cObject  = (this.Depth > 1) ? mom_m_cTable.CreateInstance() : null;
                    MobileOperator mom_m_moObject = (this.Depth > 1) ? mom_m_moTable.CreateInstance() : null;
                    Message        mom_mObject    = (this.Depth > 0) ? mom_mTable.CreateInstance(mom_m_sObject, mom_m_cObject, mom_m_moObject) : null;
                    MOMessage      momObject      = (this.Depth > -1) ? momTable.CreateInstance(mom_mObject) : null;
                    result.Add(momObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("mom", "customloadmany", "exception"), "MOMessage list could not be loaded using custom logic. See exception for details.", sqlCmdText, ex, this, connection, parameters);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "MOMessage", "Exception while loading (custom/many) MOMessage object from database. See inner exception for details.", ex);
            }
        }