예제 #1
0
        public async Task <ListViewModel <CoursesViewModel> > GetCoursesAsync(CoursesListInputModel input)
        {
            logger.LogInformation("Course richiesti");

            string orderBy   = input.OrderBy == "CurrentPrice" ? "CurrentPrice_Amount" : input.OrderBy;
            string direction = input.Ascending ? "ASC" : "DESC";

            FormattableString query   = $@"SELECT Id, Title, ImagePath, Author, Rating, FullPrice_Amount, FullPrice_Currency, CurrentPrice_Amount, CurrentPrice_Currency FROM Courses WHERE Title LIKE {"%"+input.Search+"%"} ORDER BY {(Sql) orderBy} {(Sql) direction} LIMIT {input.Limit} OFFSET {input.Offset};
            SELECT COUNT(*) FROM Courses WHERE Title LIKE {"%"+input.Search+"%"}";
            DataSet           dataSet = await db.QueryAsync(query);

            var dataTable   = dataSet.Tables[0];
            var CoursesList = new List <CoursesViewModel>();

            foreach (DataRow item in dataTable.Rows)
            {
                CoursesViewModel corsi = CoursesViewModel.FromDataRow(item);
                CoursesList.Add(corsi);
            }
            int totalCount = Convert.ToInt32(dataSet.Tables[1].Rows[0][0]);
            ListViewModel <CoursesViewModel> result = new ListViewModel <CoursesViewModel>
            {
                Result     = CoursesList,
                TotalCount = totalCount
            };

            return(result);
        }
예제 #2
0
        public async Task <List <CoursesViewModel> > GetBestCourseAsync()
        {
            FormattableString query   = $"SELECT Id, Title, ImagePath, Author, Rating, FullPrice_Amount, FullPrice_Currency, CurrentPrice_Amount, CurrentPrice_Currency FROM Courses ORDER BY Rating DESC LIMIT 3";
            DataSet           dataSet = await db.QueryAsync(query);

            var dataTable   = dataSet.Tables[0];
            var CoursesList = new List <CoursesViewModel>();

            foreach (DataRow item in dataTable.Rows)
            {
                CoursesViewModel corsi = CoursesViewModel.FromDataRow(item);
                CoursesList.Add(corsi);
            }
            return(CoursesList);
        }