Example #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);
            }
        }
Example #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);
            }
        }
        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);
            }
        }
        public static Traveler Spawn()
        {
            Traveler t = new Traveler()
            {
                FirstName = "TestNom", LastName = "TestPrenom", Email = "*****@*****.**"
            };

            _db.Add(t);
            return(t);
        }
        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);
            }
        }
        public void Test_4_Add_PublisherEntity()
        {
            TransactionContext tContext = database.BeginTransaction <PublisherEntity>(isolationLevel);

            try
            {
                for (int i = 0; i < 10; ++i)
                {
                    PublisherEntity entity = Mocker.MockOne();

                    DatabaseResult result = database.Add(entity, tContext);

                    if (!result.IsSucceeded())
                    {
                        output.WriteLine(result.Exception?.Message);
                        throw new Exception();
                    }

                    Assert.True(result.IsSucceeded());
                }

                database.Commit(tContext);
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.Message);
                database.Rollback(tContext);
                throw ex;
            }
        }
Example #7
0
        public async Task <RegistrationResponse> Register(RegistrationAttempt user)
        {
            var response = new RegistrationResponse();

            if (await UniqueEmail(user.Email))
            {
                var salt    = GetSalt();
                var newUser = new Persons
                {
                    Name         = user.FirstName + " " + user.LastName,
                    Email        = user.Email,
                    PasswordHash = GeneratePass(user.Password, salt),
                    PasswordSalt = Encoding.UTF8.GetString(salt, 0, salt.Length),
                    Role         = GetRoleFromCode(user.RegistrationCode)
                };
                await _database.Add(newUser);

                response.Success = true;
                return(response);
            }

            response.Success      = false;
            response.ErrorMessage = "Email is already being used.";
            return(response);
        }
Example #8
0
        public static void Main(string[] args)
        {
            string setting = "mysql";

            DBFactory           dBFactory = new DBFactory(setting);
            IDatabase <Product> dbHandler = dBFactory.GetDatabase <Product>();

            Product p = new Product();

            /*
             * switch (setting)
             * {
             * case "mssql":
             *    MsSQL<Product> mssql = new MsSQL<Product>();
             *    mssql.Add(p);
             *    break;
             * case "mongodb":
             *    MongoDB<Product> mongo = new MongoDB<Product>();
             *    mongo.Add(p);
             *    break;
             *
             * }
             */


            dbHandler.Add(p);

            Console.ReadLine();
        }
Example #9
0
        private void GameSelectionPanel_Display(On.GameSelectionPanel.orig_Display orig, GameSelectionPanel self, bool isMultiplayer, string mpSaveKey, int slotCount, GameSelectionPanel.GameSelectionFinishedHandler onGameSelectionFinished)
        {
            Log("Attempting to Display!");
            IDatabase <ShipConfig> db = Databases.GetDatabase <ShipConfig>(false);

            Log("Database loaded!");
            if (db.GetValue(this.GetConfig().Name) != null)
            {
                // It already exists within the database, so we can continue
                Log("The shipconfig with name: " + this.GetConfig().Name + " already exists inside the database!");
            }
            else
            {
                db.Add(this.GetConfig());
            }
            DynData <GameSelectionPanel> paneldyn = new DynData <GameSelectionPanel>(self);

            paneldyn.Set <IDatabase <ShipConfig> >("shipConfigDB", db);
            Log("Database set!");

            orig(self, isMultiplayer, mpSaveKey, slotCount, onGameSelectionFinished);

            Log("Available Ships:");
            foreach (string s in paneldyn.Get <List <Amplitude.StaticString> >("availableShips"))
            {
                Log(s);
            }
            Log("DB:");
            foreach (ShipConfig s in paneldyn.Get <IDatabase <ShipConfig> >("shipConfigDB"))
            {
                Log("Name: " + s.Name + " localized: " + s.GetLocalizedName() + " desc: " + s.GetLocalizedDescription() + " abscissa val: " + s.AbscissaValue);
            }
        }
Example #10
0
File: Form1.cs Project: rNdm74/C-
        private void addAnimalsToDatabase(string fileName)
        {
            try
            {
                StreamReader sr = new StreamReader(fileName);

                // While there is something to read
                while (!sr.EndOfStream)
                {
                    // Get the line
                    string animalData = sr.ReadLine();

                    // Create the animal
                    Animal animal = new Animal(animalData.Split(DELIMITER));

                    // Add to database
                    db.Add(animal);
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                MessageBox.Show(e.Message, "The file could not be read");
                Application.Exit();
            }
        }
Example #11
0
 public void AddNewCustomer()
 {
     if (Validate())
     {
         db.Add();
     }
 }
Example #12
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);
            }
        }
Example #13
0
        public IActionResult Add([FromQuery] string key, [FromBody] JsonElement jsonString)
        {
            if (_database.Add(key, jsonString))
            {
                return(Ok());
            }

            return(BadRequest());
        }
Example #14
0
        private void HandleAddItem()
        {
            ItemDialog dialog = new ItemDialog();

            dialog.Item = CreateItem();
            dialog.ShowDialog();

            database.Add(dialog.Item);
        }
Example #15
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);
            }
        }
Example #16
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);
            }
        }
        internal void Add(Stack <string> args)
        {
            var name    = args.Pop();
            var price   = double.Parse(args.Pop());
            var brand   = args.Pop();
            var seller  = args.Pop();
            var product = new Product(name, price, brand, seller);

            db.Add(product);
        }
Example #18
0
        public ActionResult Create([Bind("Nome, Telefone")] Contato formData)
        {
            if (ModelState.IsValid)
            {
                _db.Add(formData);

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
        public async Task AddAsync(Car car)
        {
            await Task.Run(() =>
            {
                _database.Add(car);
            });

            // Определись нужно ли ждать пока по факту добавится в БД или сгенерировать событие раньше.
            // Правда, если сгенерируешь раньше, а при добавлении произойдёт ошибка, то нужно уведомить об этом подписчиков.
            OnCarAdded(car, DatabaseServiceUpdate.Added);
        }
        public async Task <TodoItem> Post([FromBody] NewTodoItem viewModel)
        {
            var newItem = new TodoItem()
            {
                Text = viewModel.Text
            };

            _database.Add(newItem);
            await _database.SaveChangesAsync();

            return(newItem);
        }
Example #21
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);
            }
        }
Example #22
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);
            }
        }
Example #23
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);
            }
        }
Example #24
0
        public async Task AddAsync(string name,
                                   string source,
                                   string id,
                                   CancellationToken cancellationToken = default)
        {
            name = FixCollectionName(name);

            Doujin     doujin;
            Collection collection;

            do
            {
                collection = await _database.GetCollectionAsync(_context.User.Id, name, cancellationToken);

                if (collection == null)
                {
                    collection = new Collection
                    {
                        Name    = name,
                        OwnerId = _context.User.Id,
                        Doujins = new List <CollectionRef>()
                    };

                    _database.Add(collection);
                }

                doujin = await _database.GetDoujinAsync(GalleryUtility.ExpandContraction(source),
                                                        id,
                                                        cancellationToken);

                if (doujin == null)
                {
                    await _context.ReplyAsync("doujinNotFound");

                    return;
                }

                if (collection.Doujins.Any(x => x.DoujinId == doujin.Id))
                {
                    await _context.ReplyAsync("alreadyInCollection", new { doujin, collection });

                    return;
                }

                collection.Doujins.Add(new CollectionRef
                {
                    DoujinId = doujin.Id
                });
            }while (!await _database.SaveAsync(cancellationToken));

            await _context.ReplyAsync("addedToCollection", new { doujin, collection });
        }
        private async ValueTask HandleAddIp(string target, WebApiUser user, string reason)
        {
            var players = _gameManager.Games
                          .SelectMany(game => game.Players)
                          .Where(player => player.Client.Connection !.EndPoint.Address.ToString().Equals(target));

            var count       = 0;
            var uniqueNames = 0;
            var name        = string.Empty;
            var names       = new List <string>();

            foreach (var clientPlayer in players)
            {
                if (!name.Equals(clientPlayer.Character !.PlayerInfo.PlayerName))
                {
                    uniqueNames++;
                    names.Add(clientPlayer.Character !.PlayerInfo.PlayerName);
                }
                name = clientPlayer.Character !.PlayerInfo.PlayerName;
                _    = clientPlayer.BanAsync();
                count++;
            }

            if (count == 0)
            {
                await user.WriteConsole($"Unable to comply: player not found.", "ban system");

                return;
            }

            await _database.Add(target, new PlayerBan(target, new string[]
            {
                $"Dashboard: {user.Password.User}"
            }, DateTime.Now, names.ToArray(), reason));

            await user.WriteConsole($"IP Banned {count} instances, with {uniqueNames} unique names.", "ban system");

            await _logManager.LogInformation($"Ban Manager: IP banned {count} instances of {target} with {uniqueNames} unique instance names for {user.Password.User}");
        }
Example #26
0
        public IActionResult Create(Todo item)
        {
            ModelState.AddModelError("Categoria", "Deu ruim aqui hein");


            if (ModelState.IsValid == false)
            {
                BuildView();
                return(View(item));
            }
            database.Add(item);
            return(RedirectToAction("Index"));
        }
Example #27
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);
            }
        }
Example #28
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);
            }
        }
Example #29
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);
            }
        }
Example #30
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);
            }
        }
Example #31
0
    /// <summary>
    /// Creates the picture database.
    /// </summary>
    void CreatePictureDatabase()
    {
      try
      {
        IDatabaseBuilderFactory builderFactory = ServiceScope.Get<IDatabaseBuilderFactory>();
        IDatabaseFactory factory = builderFactory.CreateFromId("Pictures");

        _pictureDatabase = factory.Open("Pictures");

        _pictureDatabase.Add("CameraModel", typeof(string), 40);
        _pictureDatabase.Add("EquipmentMake", typeof(string), 40);
        _pictureDatabase.Add("ExposureCompensation", typeof(string), 1024);
        _pictureDatabase.Add("ExposureTime", typeof(string), 1024);
        _pictureDatabase.Add("Flash", typeof(string), 40);
        _pictureDatabase.Add("Fstop", typeof(string), 40);
        _pictureDatabase.Add("ImgDimensions", typeof(string), 40);
        _pictureDatabase.Add("title", typeof(string), 60);
        _pictureDatabase.Add("MeteringMod", typeof(string), 1024);
        _pictureDatabase.Add("Resolutions", typeof(string), 1024);
        _pictureDatabase.Add("ShutterSpeed", typeof(string), 1024);
        _pictureDatabase.Add("ViewComment", typeof(string), 1024);
        _pictureDatabase.Add("ISOSpeed", typeof(string), 1024);
        _pictureDatabase.Add("Orientation", typeof(int));
        _pictureDatabase.Add("PictureTags", typeof(List<string>), 1000);
        _pictureDatabase.Add("Date", typeof(DateTime), 1024);
        _pictureDatabase.Add("contentURI", typeof(string), 1024);
        _pictureDatabase.Add("CoverArt", typeof(string), 1024);
        _pictureDatabase.Add("Updated", typeof(string), 1);
        _pictureDatabase.Add("path", typeof(string), 1024);
        _pictureDatabase.Add("dateAdded", typeof(DateTime));
      }
      catch (Exception ex)
      {
        ServiceScope.Get<ILogger>().Info("pictureimporter:error CreatePictureDatabase");
        ServiceScope.Get<ILogger>().Error(ex);
      }
    }