Пример #1
0
        public async Task <CourseEditInputModel> GetCourseForEditingAsync(int id)
        {
            FormattableString query = $@"SELECT Id, Title, Description, ImagePath, Email, FullPrice_Amount, FullPrice_Currency, CurrentPrice_Amount, CurrentPrice_Currency, RowVersion FROM Courses WHERE Id={id} AND Status<>{nameof(CourseStatus.Deleted)}";

            DataSet dataSet = await db.QueryAsync(query);

            DataTable courseTable = dataSet.Tables[0];

            if (courseTable.Rows.Count != 1)
            {
                logger.LogWarning("Course {id} not found", id);
                throw new CourseNotFoundException(id);
            }
            DataRow courseRow = courseTable.Rows[0];
            CourseEditInputModel courseEditInputModel = CourseEditInputModel.FromDataRow(courseRow);

            return(courseEditInputModel);
        }
Пример #2
0
        //--------------------------------Modifica corso-----------------------------------------

        public async Task <CourseEditInputModel> GetCourseForEditingAsync(int id)
        {
            //seleziona tutti i campi modificabili
            FormattableString query = $@"SELECT Id, Title, Description, ImagePath, Email, FullPrice_Amount, FullPrice_Currency, CurrentPrice_Amount, CurrentPrice_Currency, RowVersion FROM Courses WHERE Id={id}";

            DataSet dataSet = await db.ExecuteQueryAsync(query);

            var courseTable = dataSet.Tables[0];

            if (courseTable.Rows.Count != 1)                //se vengono trovate 0 righe: corso ... non trovato
            {
                logger.LogWarning("Course {id} not found", id);
                throw new CourseNotFoundException(id);      //richiama la classe dove é stata dichiarata l'eccezione
            }
            var courseRow = courseTable.Rows[0];
            //mapping sul CourseEditInputModel
            var courseEditInputModel = CourseEditInputModel.FromDataRow(courseRow);

            return(courseEditInputModel);
        }