Exemple #1
0
        public void TestReadStudents()
        {
            DBConnection.Type             = DBType.MySQL;
            DBConnection.ConnectionString = "Server=localhost;Port=3306;Uid=root;Pwd=system32;Database=Students;CheckParameters=false;";

            long total = 0;
            long pages = 0;
            var  list  = StudentMapper.GetAllPaginatedWhere(1, 10, out total, out pages, "");

            Assert.AreNotEqual(0, total);
            Assert.AreNotEqual(0, pages);
            Assert.AreNotEqual(null, list);
            Assert.AreNotEqual(0, list.Count);
        }
Exemple #2
0
        public StudentsResponse GetPaginatedList(DateTime startDate, DateTime endDate, string name, bool isEnabled, string gender, string type, int pageNumber, int pageSize, string sortBy, string sortDirection)
        {
            var  listResult = new List <Student>();
            long totalItems = 0;
            long totalPages = 0;

            try
            {
                string filter       = string.Empty;
                string joinOperator = string.Empty;

                //filter = " convert(date, updated_on) between '" + startDate.ToString("yyyyMMdd") + "' and '" + endDate.ToString("yyyyMMdd") + "' ";
                filter = " updated_on >= '" + startDate.ToString("yyyy-MM-dd") + "' and updated_on <= '" + endDate.ToString("yyyy-MM-dd") + "' + INTERVAL 1 DAY ";

                if (!string.IsNullOrEmpty(name))
                {
                    filter += " and name like '%" + name + "%'";
                }

                if (!string.IsNullOrEmpty(gender))
                {
                    filter += " and gender = '" + gender + "'";
                }

                joinOperator = (string.IsNullOrEmpty(filter) ? string.Empty : " and ");

                if (!string.IsNullOrEmpty(type))
                {
                    filter += " and type = '" + type + "'";
                }

                listResult = StudentMapper.GetAllPaginatedWhere(pageNumber, pageSize, out totalItems, out totalPages, filter, sortBy, sortDirection, isEnabled);
            }
            catch (Exception ex)
            {
                Logger.Create().Exception(ex);
            }

            return(new StudentsResponse {
                Students = listResult, TotalStudents = totalItems, TotalPages = totalPages
            });
        }