public int Insert(BuybackResultAbsSale poco)
 {
     using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ABS-SQL"].ConnectionString))
     {
         return (int)connection.Insert(poco);
     }
 }
 public void AddCustomer(Customer customer)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Insert(CustomerTableName, ToKeyValuePairs(customer));
     }
 }
 public void AddCase(Case @case)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Insert(CaseTableName, ToKeyValuePairs(@case));
     }
 }
        private static void SetupDB()
        {
            var dbrecreated = false;
            using (var connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;Initial Catalog=Master;Integrated Security=True"))
            {
                connection.Open();
                try
                {
                    connection.Execute(@" DROP DATABASE SimplecrudDemoWebsite; ");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("database drop  failed - close and reopen VS and try again:" + ex.Message);
                }

                try
                {
                    connection.Execute(@" CREATE DATABASE SimplecrudDemoWebsite; ");
                    dbrecreated = true;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("database create failed - close and reopen VS and try again:" + ex.Message);
                }

            }
            if (!dbrecreated) return;
            using (var connection = Utilities.GetOpenConnection())
            {
                connection.Execute(@" create TABLE Car (Id int IDENTITY(1,1) not null  Primary Key, Make nvarchar(100) not null, ModelName nvarchar(100) not null) ");
                connection.Insert(new CarViewModel() { Make = "Honda", ModelName = "Civic" });
                connection.Execute(@" create TABLE Users (UserId int IDENTITY(1,1) not null Primary Key, FirstName nvarchar(100) not null, LastName nvarchar(100) not null, intAge int not null) ");
                connection.Insert(new UserViewModel() {Age = 42, FirstName = "Jim", LastName = "Smith"});
                connection.Execute(@" CREATE TABLE GUIDTest (guid uniqueidentifier NOT NULL,name varchar(50) NOT NULL, CONSTRAINT PK_GUIDTest PRIMARY KEY CLUSTERED (guid ASC))");
                connection.Insert<Guid>(new GUIDTestViewModel {name = "Example"});

                int x = 1;
                do
                {
                    connection.Insert(new User { FirstName = "Jim ", LastName = "Smith " + x, Age = x });
                    x++;
                } while (x < 101);

            }
        }
        public void SaveRule(Rule rule)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                connection.Insert(rule);

                connection.Close();
            }
        }
        public bool AddActivityToActivity(int parentActivityId, int activityId)
        {
            var activityActivity = new ActivityActivity() {ActivityId = activityId, ParentActivityId = parentActivityId};

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Insert(activityActivity);
            }

            return true;
        }
        public bool AddActivityToRole(int roleId, int activityId)
        {
            var roleActivity = new RoleActivity() {ActivityId = activityId, RoleId = roleId};

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Insert(roleActivity);
            }

            return true;
        }
        public bool AddRoleToRole(int parentRoleId, int roleId)
        {
            var roleRole = new RoleRole() {RoleId = roleId, ParentRoleId = parentRoleId};

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Insert(roleRole);
            }

            return true;
        }
        public bool AddRoleToUser(int userId, int roleId)
        {
            var userRole = new UserRole() {Id = userId, RoleId = roleId};

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Insert(userRole);
            }

            return true;
        }
Example #10
0
		public void LogError(Error errorToLog)
		{
            Error result = null;

			//save info to DB
            using(SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["CrestDB"].ConnectionString))
            {
               result = connection.Insert<Error>(errorToLog);
            }

            Clients.All.broadcastMessage(result);
		}
 public void AddBookmarkRecord(string bookmarkName, object workflowInstanceId)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Insert(CaseWorkflowManager.BookmarkTableName,
                           new Dictionary<string, object>
                               {
                                   {CaseWorkflowManager.CaseIdColumnName, _caseId},
                                   {CaseWorkflowManager.WorkflowinstanceidColumnName, workflowInstanceId},
                                   {CaseWorkflowManager.BookmarkNameColumnName, bookmarkName}
                               });
     }
 }
 public void AddMessage(CaseMessage doc)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         var dictionary = new Dictionary<string, object>
                              {
                                  {"案件编号", doc.案件编号},
                                  {"Content", doc.Content},
                                  {"SenderName", doc.SenderUsername}
                              };
         connection.Insert(TableName, dictionary);
     }
 }
Example #13
0
        private static void Dapper(int eachCount)
        {
            GC.Collect();//回收资源
            System.Threading.Thread.Sleep(2000);//休息2秒

            //正试比拼
            PerHelper.Execute(eachCount, "Dapper", () =>
            {
                using (SqlConnection conn = new SqlConnection(PubConst.connectionString))
                {
                    var list = conn.Insert(GetList);
                }
            });
        }
 public void AddDoc(CaseDoc doc)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         var dictionary = new Dictionary<string, object>
                              {
                                  {"文件名", doc.FileName},
                                  {"创建人", doc.UploadUserName},
                                  {"创建日期", doc.UploadDateTime},
                                  {"文件路径", doc.FilePath},
                                  {"案件编号", doc.案件编号}
                              };
         connection.Insert(CaseDocTableName, dictionary);
     }
 }
Example #15
0
		public static void Insert()
		{
			var contact = new Contact
			{
				FirstName = "New",
				LastName = "Contact",
				Email = "[email protected]"
			};

			using (var cn = new SqlConnection(CONNECTION_STRING))
			{
				var id = cn.Insert(contact);
				Console.WriteLine("Inserted record ID: {0}", id);
			}

			Console.ReadKey();
		}
Example #16
0
        public Athlete SaveAthlete(Athlete athlete)
        {
            using (var conn = new SqlConnection(_ConnectionString))
            {
                conn.Open();

                if (athlete.Id == 0)
                {
                    athlete.Id = conn.Insert(athlete);
                }
                else
                {
                    conn.Update(athlete);
                }

                return athlete;
            }
        }
Example #17
0
        static void Main()
        {
            try
            {
                var connection = new SqlConnection(@"Server=localhost\sqlexpress;Database=ExperimentalStuff;Trusted_Connection=true;");

                var id = new Guid("DB44BD6A-532C-4F9A-A9A0-CE32C193F467");
                var grandParent = new GrandParent
                {
                    Id = id,
                    Name = "grandparent",
                };

                Builder<Parent>.CreateListOfSize(3).Build()
                    .ToList().ForEach(grandParent.AddParent);

                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    connection.Delete<GrandParent>(new { grandParent.Id }, transaction);
                    var insert = connection.Insert(grandParent, transaction);
                    Console.WriteLine(insert);
                    transaction.Commit();
                }
                connection.Close();

                Print(connection, grandParent.Id);
                //connection.Delete<GrandParent>(new { grandParent.Id });

                connection.Dispose();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
            finally
            {
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }
        public static void Main()
        {
            using (var sqlConnection
                        = new SqlConnection(Constant.DatabaseConnection))
            {
                sqlConnection.Open();

                var supplier = new Supplier()
                                   {
                                       Address = "10 Main Street",
                                       CompanyName = "ABC Corporation"
                                   };

                var supplierId = sqlConnection.Insert<Supplier>(supplier);

                sqlConnection.Close();

                Console.WriteLine(string.Format("New Supplier Id is {0}", supplierId));

                Console.WriteLine("Done. ");
            }
        }
        public Activity SaveActivity(Activity activity)
        {
            var isInsert = activity.Id.Equals(0);

            using (var conn = new SqlConnection(ConnectionString))
            {
                if (isInsert)
                {
                    activity = conn.Insert(activity, "Id");
                }
                else
                {
                    conn.Update(activity, new Dictionary<string, object>() {{"Id", activity.Id}}, new[] {"Id"});
                }
            }

            return activity;
        }
        /// <summary>
        /// Customers the CRUD.
        /// </summary>
        /// <param name="sqlconn">The sqlconn.</param>
        /// <remarks>http://wintersun.cnblogs.com/</remarks>
        private static void CustomerCRUD(SqlConnection sqlconn)
        {
            var customer = new Customers
            {
                CustomerID = "8273",
                CompanyName = "Newcompanyname",
                ContactName = "ccc",
                Address = "asdcasdws",
                ContactTitle = "asdf",
                City = "kuna",
                Country = "china",
                Fax = "23",
                Phone = "231",
                PostalCode = "234",
                Region = "asia"
            };

            string insertflag = sqlconn.Insert<Customers>(customer);

            //update it
            var myCustomer = sqlconn.Get<Customers>(customer.CustomerID);
            myCustomer.ContactName = "updated name";

            sqlconn.Update<Customers>(myCustomer);

            //delete
            sqlconn.Delete<Customers>(customer);
        }
 public void AddInventor(Inventor inventor)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Insert(InventorTableName, ToKeyValuePairs(inventor));
     }
 }
Example #22
0
        public void PostPost(string title, string filename, int owner, DateTime date, int width, int height)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();

                Posts p = new Posts() { title = title, filename = filename, owner = owner, dateuploaded = date, width = width, height = height };

                var i = conn.Insert(p);
            }
        }
Example #23
0
        public Comments PostComment(int id, string comment, string username)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();

                Comments c = new Comments() { dateposted = DateTime.UtcNow, item_id = id, text = comment, name = username };

                Posts p = this.GetPost(id, conn);
                p.comments_count++;

                var i = conn.Insert(c);
                conn.Update(p);
                c.id = i;
                return c;
            }
        }
 private void PersistMessage(QueueMessage message)
 {
     using (var connection = new SqlConnection(_setting.ConnectionString))
     {
         connection.Insert(new
         {
             MessageId = message.MessageId,
             MessageOffset = message.MessageOffset,
             MessageKey = message.Key,
             Topic = message.Topic,
             QueueId = message.QueueId,
             QueueOffset = message.QueueOffset,
             Code = message.Code,
             Body = message.Body,
             RoutingKey = message.RoutingKey,
             CreatedTime = message.CreatedTime,
             ArrivedTime = message.ArrivedTime,
             StoredTime = DateTime.Now
         }, _setting.MessageTable);
     }
 }
        public UserAuthorisation SaveUserAuthorisation(UserAuthorisation userAuthorisation)
        {
            var isInsert = userAuthorisation.Id.Equals(0);

            using (var conn = new SqlConnection(ConnectionString))
            {
                if (isInsert)
                {
                    userAuthorisation = conn.Insert(userAuthorisation, "Id");
                }
                else
                {
                    conn.Update(userAuthorisation, new Dictionary<string, object>() {{"Id", userAuthorisation.Id}}, new[] {"Id"});
                }
            }

            return userAuthorisation;
        }
 public void AddApplicant(Applicant applicant)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Insert(ApplicantTableName, ToKeyValuePairs(applicant));
     }
 }
        public Role SaveRole(Role role)
        {
            var isInsert = role.Id.Equals(0);

            using (var conn = new SqlConnection(ConnectionString))
            {
                if (isInsert)
                {
                    role = conn.Insert(role, "Id");
                }
                else
                {
                    conn.Update(role, new Dictionary<string, object>() {{"Id", role.Id}}, new[] {"Id"});
                }
            }

            return role;
        }
 public int Insert(BuybackVehicle poco, IDbTransaction transaction)
 {
     using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ABS-SQL"].ConnectionString))
     {
         return (int)connection.Insert(poco, transaction);
     }
 }