Exemplo n.º 1
0
        public static void UpdateDataById(int id, ForumModel updateModel)
        {
            string query = @"update Forum set ThemeName = @ThemeName, ChangeDate = @ChangeDate where id = @id";

            using (IDbConnection db = new SqlConnection(conn))
            {
                if (db.State == ConnectionState.Closed)
                {
                    db.Open();
                }

                db.Execute(query, new { updateModel.ThemeName, updateModel.ChangeDate, id });
            }
        }
Exemplo n.º 2
0
        public static void InsertData(ForumModel insertModel)
        {
            string query = @"insert into Forum (ThemeName, ChangeDate) values (@ThemeName, @ChangeDate)";

            using (IDbConnection db = new SqlConnection(conn))
            {
                if (db.State == ConnectionState.Closed)
                {
                    db.Open();
                }

                db.Execute(query, new { insertModel.ThemeName, insertModel.ChangeDate });
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            int    currentPage        = 2;
            int    countElemetsOnPage = 2;
            string sortTypeAsc        = "asc";
            string sortTypeDesc       = "desc";

            int updateId = 10;

            var updateModel = new ForumModel
            {
                ThemeName  = "UpdateName",
                ChangeDate = ForumLogic.GetDataById(updateId).ChangeDate
            };

            var insertModel = new ForumModel
            {
                ThemeName  = "InsertModel",
                ChangeDate = new DateTime(2018, 12, 12)
            };

            int deleteId = 11;

            var allCount = ForumLogic.GetCountAllRecords();

            var testDataAsc  = ForumLogic.GetDataForCurrentPage(currentPage, countElemetsOnPage, allCount, sortTypeAsc);
            var testDataDesc = ForumLogic.GetDataForCurrentPage(currentPage, countElemetsOnPage, allCount, sortTypeDesc);

            //ForumLogic.UpdateDataById(updateId, updateModel);
            //ForumLogic.InsertData(insertModel);
            //ForumLogic.InsertData(insertModel);
            //ForumLogic.DeleteDataById(deleteId);

            var newAllCount = ForumLogic.GetCountAllRecords();

            int currentPage2        = 3;
            int countElemetsOnPage2 = 4;

            var testDataAsc2  = ForumLogic.GetDataByIds(currentPage2, countElemetsOnPage2, newAllCount, sortTypeAsc);
            var testDataDesc2 = ForumLogic.GetDataByIds(currentPage2, countElemetsOnPage2, newAllCount, sortTypeDesc);

            var slqTestAsc1  = ForumLogic.GetDataForCurrentPageSql(currentPage2, countElemetsOnPage2, newAllCount, sortTypeAsc, sortTypeDesc);
            var slqTestDesc1 = ForumLogic.GetDataForCurrentPageSql(currentPage2, countElemetsOnPage2, newAllCount, sortTypeDesc, sortTypeAsc);

            var testDataAsc3  = ForumLogic.GetDataForCurrentPageLinq(currentPage2, countElemetsOnPage2, newAllCount, sortTypeAsc);
            var testDataDesc3 = ForumLogic.GetDataForCurrentPageLinq(currentPage2, countElemetsOnPage2, newAllCount, sortTypeDesc);
        }