public LivreCategoryDTO GetLivreCategory(int codeCategory)
        {
            var category = context.LivreCategories
                           .FirstOrDefault(c => c.IdCategory == codeCategory);
            var categoryDto = new LivreCategoryDTO
            {
                CodeCategoryDto = category.IdCategory,
                NomCategoryDto  = category.NomCategory
            };

            return(categoryDto);
        }
示例#2
0
        public LivreCategoryDTO GetLivreCategory(int codeCategory)
        {
            var categoryDto = new LivreCategoryDTO();

            using (SqlConnection connection = new SqlConnection())
            {
                connection.ConnectionString = CONNECTIONSTRING;
                connection.Open();
                SqlCommand command = new SqlCommand("GetCategory", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@idCategory", codeCategory);
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    categoryDto.CodeCategoryDto = int.Parse(reader[0].ToString());
                    categoryDto.NomCategoryDto  = reader[1].ToString();
                }
            }
            return(categoryDto);
        }